Chat · Tool Calls · Vision · Long Context · Updated for K3

Moonshot AI Kimi API (K3 / moonshot-v1 ecosystem)

The Kimi API (Moonshot AI Open Platform) gives developers programmatic access to Moonshot's models - from the long-standing moonshot-v1 chat family (32k/128k, OpenAI-compatible) through the agentic K2 / K2.5 / K2.6 / K2.7-Code line to the new flagship Kimi K3: a 2.8T-parameter, 1M-context, always-thinking model that's now the largest open-weight model released to date.

Base URL: api.moonshot.ai/v1 OpenAI SDK-compatible K3: $3 / $15 per 1M tokens K3 weights: open, released Jul 26, 2026
🌙 New · July 16, 2026

Kimi K3 launches - the first open 3T-class model

Moonshot's flagship jumps from K2's ~1T parameters to 2.8T total parameters (a Mixture-of-Experts model activating roughly 16 of 896 experts per token), with a 1-million-token context window, native vision, and reasoning that's always on. It's built on two new architectural components - Kimi Delta Attention (KDA) and Attention Residuals - that Moonshot says deliver roughly 2.5x the scaling efficiency of K2.

🧠
2.8T params, MoE
Largest open flagship by raw scale - ~75% larger than the next-biggest open model.
📚
1M-token context
Full window exposed at a flat rate via the API; app tiers meter it differently.
💭
Always-on reasoning
Use reasoning_effort, not the older K2.x thinking toggle.
🔓
Open weights
Published July 26, 2026, a day ahead of schedule, under a Modified-MIT-style license.
1) What Kimi API is 2) Auth & base URLs 3) OpenAI compatibility 4) Models & context 5) Chat API 6) Tool calling 7) Vision inputs 8) Token estimation 9) Files & attachments 10) Pricing & budgeting 11) Rate limits & reliability 12) Production architecture FAQ References
Section 1 · Where it fits, who should use it

1) What the Kimi API is

Moonshot AI's Open Platform (often called the "Kimi API") provides an HTTP API to interact with Moonshot/Kimi models: an ecosystem spanning long-context chat models, tool calling, multimodal vision, and - as of July 2026 - the frontier-scale Kimi K3.

Good fit

Long-context chat and document Q&A, tool-using agents, migration from OpenAI-style chat, cost-sensitive scale, and vision/multimodal workflows.

Long contextAgentsVision

Not the best fit

Purely local/offline requirements, ultra-low-latency (<50ms) micro-responses, or workloads needing fully deterministic output without validation layers.

Best mental model

Treat the Kimi API like a "reasoning coprocessor" that reads large context, generates structured outputs, and decides when to call tools - while your code handles secure execution.

The K3 shift

K3 pushes Moonshot from "capable open alternative" to genuine frontier contender - Moonshot positions it against Claude and GPT-5.6-class models on coding and agent benchmarks.

Section 2 · Bearer keys, global vs China endpoints

2) Authentication & base URLs

Kimi API uses standard Bearer authentication: send your key in the Authorization header. Base URLs differ by region.

Global base URL

https://api.moonshot.ai/v1

InternationalOpenAI-style paths

China base URL

https://api.moonshot.cn/v1

China regionOpenAI-style paths
  • Never place API keys in frontend JavaScript - always call Kimi API from your backend.
  • Store keys in a secrets manager (or at least environment variables) and rotate periodically.
  • Use request logging and per-user quotas to reduce abuse risk and prevent surprise billing.
  • If you allow user-supplied prompts, add content filtering and "dangerous prompt" detection for your domain.
  • Most accounts need a small minimum top-up (commonly cited around $1) before a newly created key becomes active.
bash · curlQuick health check: list models
curl "https://api.moonshot.ai/v1/models" \
  -H "Authorization: Bearer $MOONSHOT_API_KEY"
Section 3 · Chat completions, migration approach

3) OpenAI compatibility

A major advantage of the Kimi API ecosystem is compatibility with familiar "chat completions" request bodies - including for K3, which ships compatible with the OpenAI SDK. Migration usually comes down to four steps.

  • Swap the base URL to https://api.moonshot.ai/v1 (or .cn).
  • Replace the API key environment variable and header.
  • Update the model string to a Moonshot/Kimi model ID (see Section 4).
  • Review tool-calling parameter differences (legacy functions vs. modern tools).
httpBasic "drop-in" chat request
POST https://api.moonshot.ai/v1/chat/completions
Authorization: Bearer $MOONSHOT_API_KEY
Content-Type: application/json

{
  "model": "moonshot-v1-32k",
  "messages": [
    {"role":"system","content":"You are a helpful assistant."},
    {"role":"user","content":"Summarize this article in 6 bullets..."}
  ],
  "temperature": 0.3
}
Compatibility warning: the legacy functions field is deprecated in the OpenAI ecosystem in favor of tools. Use the modern tools and tool_choice patterns for best results with Kimi models, including K3.
Do I need OpenAI's SDK? No - plain HTTPS requests work fine. But many OpenAI-compatible SDKs let you specify a custom base URL, so existing OpenAI-client code often needs only configuration changes, not a rewrite.
Section 4 · moonshot-v1 32k/128k, 1M + K2/K2.5/K2.6/K2.7/K3

4) Models & context windows

Moonshot's lineup now spans two generations: the moonshot-v1 family (context-size-named, general chat and vision) and the K-series agentic/reasoning models, which evolved rapidly through 2025–2026 from K2 to the frontier-scale K3.

ModelParams (total / active)ContextPrice (in/out per 1M)Best for
moonshot-v1-32k / 128k-32k / 128kSee official pricing pageGeneral chat, summaries, everyday assistants
moonshot-v1-*-vision-preview-8k / 32k / 128kSee official pricing pageImage + text prompts, screenshots, charts
kimi-k2.5~1T / ~32B activeLong context$0.60 / $3.00Multimodal + agentic, budget-friendly agent tasks
kimi-k2.6~1T-classLong context$0.95 / $4.00General-purpose value tier (stable release, Apr 2026)
kimi-k2.7-code~1T-classLong context$0.95 / $4.00Cost-sensitive coding workloads
kimi-k32.8T / ~16 of 896 experts1,000,000 tokens$3.00 / $15.00
$0.30 cache-hit input
Frontier reasoning, long-horizon coding & agent swarms

Pick context first

If your conversation or retrieved documents are large, choose a larger-context model. If most prompts are small, don't pay for context you don't use.

Pick capability second

For tool-using agents and complex coding, prefer K2.7-Code or K3. For simple Q&A, moonshot-v1 or K2.5 is more cost-effective.

Keep a tiered UX

Expose "Standard / Long Context / Pro Agent / Vision" modes in product UI rather than showing raw model IDs to users.

List models dynamically: model IDs evolve fast - K3 shipped roughly 12 months after K2. Store a "supported models" configuration in your backend and refresh it periodically by calling the models endpoint, then map raw IDs to user-friendly product tiers.
K3-specific note: K3 runs in thinking mode by default. Use the reasoning_effort parameter to control reasoning depth - not the older K2.x "thinking mode" toggle, which doesn't apply the same way to K3.
Section 5 · Messages, params, streaming, output control

5) Chat API

You send a list of messages (system, user, assistant) and receive a model-generated response. A production-grade chat layer usually includes safe prompt construction, streaming support, response validation, retries, and logging.

  • system: set behavior ("You are a concise support agent."), output constraints, tone, policy.
  • user: the user's input - ideally sanitized and length-checked.
  • assistant: previous replies (conversation memory). Keep only what you need to control token usage.
  • temperature: lower (0–0.3) for extraction/structured output; higher (0.7–1.0) for ideation. Use temperature or top_p, not both at once.
  • Length control: request a specific shape ("Return exactly 6 bullets," "Return JSON with keys …") to reduce run-on outputs and keep costs predictable.
javascriptfetch example
async function kimiChat({ prompt }) {
  const res = await fetch("https://api.moonshot.ai/v1/chat/completions", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.MOONSHOT_API_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "moonshot-v1-32k",
      messages: [
        { role: "system", content: "You are a concise developer assistant." },
        { role: "user", content: prompt }
      ],
      temperature: 0.2
    })
  });

  if (!res.ok) {
    const err = await res.text();
    throw new Error(`Kimi API error ${res.status}: ${err}`);
  }

  const data = await res.json();
  return data.choices?.[0]?.message?.content ?? "";
}
pythonrequests example
import os, requests

def kimi_chat(prompt: str) -> str:
    url = "https://api.moonshot.ai/v1/chat/completions"
    headers = {
        "Authorization": f"Bearer {os.environ['MOONSHOT_API_KEY']}",
        "Content-Type": "application/json",
    }
    payload = {
        "model": "moonshot-v1-32k",
        "messages": [
            {"role": "system", "content": "You are a helpful assistant. Keep answers under 150 words."},
            {"role": "user", "content": prompt},
        ],
        "temperature": 0.2,
    }
    r = requests.post(url, headers=headers, json=payload, timeout=60)
    r.raise_for_status()
    return r.json()["choices"][0]["message"]["content"]
Streaming: improves perceived latency and reduces duplicate-click spam. Treat it as the default UX for interactive chat; non-streaming is fine for background jobs like batch summaries.
Structured outputs: ask for a strict JSON schema, validate server-side. If parsing fails, retry once with a repair prompt that includes the model's previous output and asks it to fix only the JSON. Keep temperature low, and never trust JSON without validation.
Section 6 · Tool schema, tool_choice, multi-tool workflows

6) Tool calling

Tool calling lets the model decide when to call external functions you define. The model outputs a structured tool-call object; your application executes the tool and returns the result back as a follow-up message.

  1. Define tools with names, descriptions, and a JSON schema for parameters.
  2. Send a chat request with tools included.
  3. The model replies with normal text, or one or more tool_calls.
  4. Your code executes the tool(s) securely and returns results as messages.
  5. The model uses those results to produce the final user-facing response.
Golden rule: the model can suggest tool calls - but your code must be the authority. Validate parameters, enforce permissions, and never let a tool call perform an action the user isn't allowed to do.
jsonTool definition example
{
  "type": "function",
  "function": {
    "name": "search_kb",
    "description": "Search the internal knowledge base for relevant documents.",
    "parameters": {
      "type": "object",
      "properties": {
        "query": { "type": "string", "description": "Search query." },
        "top_k": { "type": "integer", "description": "Number of results.", "default": 5 }
      },
      "required": ["query"]
    }
  }
}
Pseudo-codeTypical tool-calling loop
messages = [system, user]
tools = [search_kb, get_order_status, ...]
resp = chat(messages, tools, tool_choice="auto")

if resp contains tool_calls:
  for each call:
    args = validate(call.arguments)
    result = execute_tool(call.name, args)
    messages.append({role:"tool", tool_call_id: call.id, content: json(result)})
  resp2 = chat(messages, tools, tool_choice="auto")
  return resp2.final_answer
else:
  return resp.text
tool_choice on K2.5+ models: Moonshot's quickstart guidance notes that tool_choice may be restricted to "auto" or "none" by default to avoid conflicts between reasoning and forced tool selection. "auto" is the best default; only use "none" for pure text generation.
  • Keep tools small and single-purpose (search, fetch, update).
  • Use consistent output formats from tools (JSON).
  • Add timeouts and retries around tool execution.
  • Log every tool call for debugging and safety auditing.
  • Add a "planner" instruction to encourage calling tools only when needed, not by habit.
K3 and agent swarms: Moonshot's newer agentic tooling (surfaced in products like Kimi Work) can fan a task out to a fleet of sub-agents working in parallel - useful for batch, search, and large-repository work that a single agent would grind through serially. At the API level this still reduces to the same tool-calling loop above, orchestrated across multiple concurrent requests.
Section 7 · Vision preview models + multimodal prompts

7) Vision inputs

Moonshot's guides describe vision preview models - moonshot-v1-8k-vision-preview, moonshot-v1-32k-vision-preview, moonshot-v1-128k-vision-preview - alongside native vision now built into K2.5 and K3. These accept image input plus text for screenshot interpretation, chart explanation, UI analysis, and multimodal reasoning.

  • Users upload screenshots wanting explanations ("Why is this build failing?" "What does this chart imply?").
  • Document processing includes scanned pages where text extraction alone loses context.
  • You want the assistant to interpret UI/UX mocks or design comps and generate code or copy.
Vision cost planning: vision inputs consume tokens too (or have separate accounting). Use the token estimation API (Section 8) to forecast cost before sending large images in production.

Be explicit about the task

"Describe what's in this image" is vague. Better: "Read the error message, identify the root cause, and propose 3 fixes in priority order," or "Extract table rows into JSON with keys {name, value, unit}."

Ask for structured outputs

Vision analysis benefits from structure: bullet lists, step-by-step troubleshooting, or JSON. Keep temperature low and validate outputs, especially for extraction tasks.

Common pitfall - sensitive screenshots: screenshots can include emails, tokens, or personal info. Implement redaction guidance, access control, and retention policies for user uploads, and consider an "auto-blur" step for obvious secrets like API keys in logs.
Section 8 · Estimate endpoint, long-context planning

8) Token estimation

Moonshot exposes an "Estimate Tokens" API to calculate token count for a request, including both plain text and visual input. This lets you warn users before an expensive request, auto-compress/trim context, and enforce budgets - increasingly important with K3's 1M-token window.

  • Long user messages or pasted documents.
  • Large RAG results that might overrun context.
  • Multimodal messages with images.
  • Agent loops that might chain many tool calls and assistant turns.

Stage 1: Trim

Remove older conversation turns that are no longer relevant. Keep only the last few turns and any "pinned" system instructions.

Stage 2: Summarize

Summarize older context into a short "memory" block: decisions, user preferences, known facts. Replace many turns with one summary message.

Stage 3: Retrieve

Instead of pasting full documents, retrieve only the relevant chunks (RAG) and cite them. Use token estimation to keep retrieval bounded.

A bigger window isn't free: large prompts cost more, slow down responses, and increase the chance the model gets distracted - even at 1M tokens. Estimation helps you keep prompts tight and improves answer quality.
Section 9 · File API patterns and usage

9) Files & attachments

Moonshot's API documentation includes a Files endpoint category. Even when "files" isn't the headline feature you need, file-handling in your application is common for a few reasons.

  • Large documents you don't want to paste directly into messages.
  • Repeatability: upload a file once, reference it many times.
  • Auditing: keep track of which file influenced which answer.
  • Security: store files under your own access control and share only safe excerpts.
Recommended approach: keep the "source of truth" in your own object storage (S3/R2/GCS) and only send extracted text snippets to the model. This reduces vendor lock-in and gives you control over retention and deletion.
RAG vs. full document paste: RAG is usually better for reliability and cost - store embeddings and retrieve only relevant chunks. Full paste works for smaller documents but is expensive and can confuse the model when the doc is long. Good default: paste excerpts + cite where they came from.
Section 10 · Per-1M token pricing, cache hits, cost guardrails

10) Pricing & budgeting

Moonshot presents costs as price per 1M tokens, with input/output distinguished and a significant discount for cache-hit input - increasingly valuable with K3's long context window, where keeping stable prefixes (system prompts, tool definitions, document prefixes) unchanged across requests lets the cache do the work.

ModelInput (cache miss)Input (cache hit)Output
kimi-k2.5$0.60 / 1MLower, varies$3.00 / 1M
kimi-k2.6 / k2.7-code$0.95 / 1MLower, varies$4.00 / 1M
kimi-k3$3.00 / 1M$0.30 / 1M$15.00 / 1M

Product guardrails

Per-user daily/monthly credits, hard caps for free tier, preview-first flows (short answers first, "expand" on demand), model gating ("Pro model" only for paid users).

Engineering guardrails

Token estimation before large requests, context trimming + summarization, deduplicate repeated prompts (idempotency hash), cache retrieval results (RAG).

Back-of-the-envelope: monthly cost ≈ (requests × avg input tokens / 1,000,000 × input price) + (requests × avg output tokens / 1,000,000 × output price) + retry overhead. Track tokens per successful user outcome and retries per completion - these usually matter more than the headline price per 1M tokens.
Should I always use the cheapest model? Not always. If a stronger model (like K3) completes a task in fewer turns, fewer retries, and less prompt engineering, it can be cheaper overall. Choose based on total cost per successful outcome, not per-request price alone.
Section 11 · 429s, concurrency, retries

11) Rate limits & reliability

Like most AI APIs, Kimi API enforces rate limits and concurrency constraints, typically tiered by account recharge/spend level. Early or trial tiers can be strict - assume "Too Many Requests" (HTTP 429) will happen sometimes and handle it gracefully.

  • Retries with backoff: on 429/5xx, wait and retry rather than hammer the API.
  • Jitter: add randomness to backoff to avoid synchronized spikes.
  • Queue: enqueue bursty user requests rather than firing immediately.
  • Timeouts: set timeouts for API calls and tool executions; don't hang forever.
  • Idempotency: avoid duplicate charges when users click "Send" multiple times.
Pseudo-codeBackoff example
delay = 1.5s
for attempt in 1..6:
  try:
    return call_kimi()
  except RateLimitError:
    sleep(delay + random(0..500ms))
    delay = min(delay * 1.8, 15s)
throw "rate-limited"
Launch-week caution: new flagship models like K3 can see demand spikes intense enough that the provider temporarily pauses new subscriptions or tightens capacity. Build in graceful degradation (fallback to K2.6/K2.7 or a queued retry) for periods when your primary model is capacity-constrained.

Show progress

Even for non-streaming responses, show "Thinking…" plus a spinner and disable the send button briefly. This alone reduces duplicate requests dramatically.

Offer "Stop"

Users feel in control when they can stop generation. Wire up abort if your client supports it, or stop displaying output and ignore late tokens.

Explain limits

Clear plan messaging ("Free: 3 RPM, 1 concurrency") prevents confusion. Silent throttling feels broken; visible throttling feels fair.

Error handling checklist: log request ID, user ID, model, prompt token estimate, response latency, error code, retry count. Return user-friendly errors with next steps ("Try again in 10 seconds"). Alert on elevated 429/5xx rates or latency spikes.
Section 12 · Queues, observability, evals

12) Production architecture

A scalable LLM system combines prompt design, backend orchestration, and observability. The UI calls your backend, your backend calls Kimi, a queue manages concurrency for heavy tasks, and your storage layer holds persistent artifacts.

ComponentResponsibilityWhy it matters
FrontendCollect prompts, show streaming output, show status and history.Good UX reduces duplicate requests and improves retention.
Backend APIAuth, quotas, request validation, prompt templates.Protects your keys and enforces budgets.
Queue + workersBatch tasks: long summaries, tool pipelines, document processing.Prevents timeouts, controls concurrency and cost spikes.
Vector store (optional)RAG retrieval, embeddings, chunk storage.Improves accuracy and reduces tokens vs. full paste.
ObservabilityLogs, traces, metrics, evals, cost tracking.Debug faster, prevent regressions, improve prompts.
Prompt design system: build a "prompt library" of reusable templates - customer support, extraction, summarization, report writing, SQL generation, agent planning. Version these like code, measure quality, and roll out updates safely.
  • Collect real user queries (anonymized) and label good vs. bad outcomes.
  • Create a small test suite for each feature ("support replies," "invoice extraction").
  • Run offline evaluations: compare models, prompts, temperatures - including K2.x vs. K3 trade-offs.
  • Ship changes behind a flag, monitor cost + satisfaction.
  • Iterate and keep a changelog for transparency.
Agentic workflows - controlling tool-call explosions: tool-calling agents (and K3's sub-agent swarm patterns) can spiral into long loops. Control this with max tool calls per run, max tokens per run, timeouts per tool, and a budget instruction in the system prompt: "You have at most 3 tool calls; prefer the most informative call first." Combine with logging to see why an agent is over-calling tools.
FAQ

FAQ: Kimi API

What is the base URL for Kimi API?

Commonly referenced base URLs: https://api.moonshot.ai/v1 (global) and https://api.moonshot.cn/v1 (China region). Use the one recommended by your console/docs for your account.

Is the Kimi API OpenAI-compatible?

Yes - including K3. Migration usually involves swapping the base URL, using your Moonshot API key, and updating model IDs. Review tool-calling differences (use modern tools rather than legacy functions).

What's actually new with Kimi K3?

K3 is Moonshot's flagship, launched July 16, 2026: a 2.8T-parameter Mixture-of-Experts model with a 1M-token context window, native vision, and always-on reasoning (controlled via reasoning_effort). Open weights were published July 26, 2026. It's priced at $3/$15 per 1M input/output tokens, with $0.30 cache-hit input.

Can I self-host Kimi K3?

As of the open-weights release on July 26, 2026, yes - weights are published under a Modified-MIT-style license. Before that date, K3 was API-only. Moonshot recommends production self-hosting on supernode configurations with 64+ accelerators; no minimum viable single-GPU config has been published.

How do I choose between moonshot-v1, K2.x, and K3?

Use moonshot-v1 for straightforward chat/vision where OpenAI-style simplicity matters most. Use K2.5/K2.6/K2.7-Code for budget-conscious agentic and coding work. Reach for K3 when you need frontier-level reasoning, very long context (up to 1M tokens), or the best available coding/agent benchmark performance and can absorb the higher per-token cost.

Does Kimi API support tool calling?

Yes - a core feature across the model line. Define tools with JSON schemas, send them in a chat request, and execute tool calls securely in your application. On K2.5+ models, tool_choice may default to being restricted to "auto" or "none."

How do I handle rate limits?

Implement backoff retries for 429 responses, add a queue for bursty traffic, and cap concurrency per user or workspace. During launch-week demand spikes for new models, build in fallback to an older model tier.

What's the best way to reduce cost?

Control tokens: trim conversation history, summarize older context, use RAG instead of full paste, estimate tokens before big requests, keep temperature low for structured tasks to reduce retries, and structure prompts to maximize cache hits on stable prefixes (especially valuable with K3's long context).

References

Official documentation

Use these as the source of truth for schemas, model availability, pricing updates, and advanced guides - model names and rates move fast, especially in launch weeks.

TopicOfficial linkUse it for
Docs overviewplatform.moonshot.ai/docs/overviewPlatform capabilities, navigation, guides
Quickstartplatform.moonshot.ai/docs/guide/start-using-kimi-apiFirst request, basic setup
Main conceptsplatform.moonshot.ai/docs/introductionModel families, context windows, concepts
Chat APIplatform.moonshot.ai/docs/api/chatChat request/response details
Tool useplatform.moonshot.ai/docs/api/tool-useTool calling schema and examples
Vision guideplatform.moonshot.ai/docs/guide/use-kimi-vision-modelVision preview models and usage
Token estimationplatform.moonshot.ai/docs/api/estimateEstimate token counts for text + images
Pricingplatform.moonshot.ai/docs/pricing/chatPrice per 1M tokens by model tier
FAQplatform.moonshot.ai/docs/guide/faqLimits, edge cases, common questions
API key consoleplatform.kimi.ai/console/api-keysCreate and manage API keys