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.
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.
Long-context chat and document Q&A, tool-using agents, migration from OpenAI-style chat, cost-sensitive scale, and vision/multimodal workflows.
Purely local/offline requirements, ultra-low-latency (<50ms) micro-responses, or workloads needing fully deterministic output without validation layers.
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.
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.
Kimi API uses standard Bearer authentication: send your key in the Authorization header.
Base URLs differ by region.
https://api.moonshot.ai/v1
https://api.moonshot.cn/v1
curl "https://api.moonshot.ai/v1/models" \ -H "Authorization: Bearer $MOONSHOT_API_KEY"
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.
https://api.moonshot.ai/v1 (or .cn).functions vs. modern tools).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
}
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.
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.
| Model | Params (total / active) | Context | Price (in/out per 1M) | Best for |
|---|---|---|---|---|
| moonshot-v1-32k / 128k | - | 32k / 128k | See official pricing page | General chat, summaries, everyday assistants |
| moonshot-v1-*-vision-preview | - | 8k / 32k / 128k | See official pricing page | Image + text prompts, screenshots, charts |
| kimi-k2.5 | ~1T / ~32B active | Long context | $0.60 / $3.00 | Multimodal + agentic, budget-friendly agent tasks |
| kimi-k2.6 | ~1T-class | Long context | $0.95 / $4.00 | General-purpose value tier (stable release, Apr 2026) |
| kimi-k2.7-code | ~1T-class | Long context | $0.95 / $4.00 | Cost-sensitive coding workloads |
| kimi-k3 | 2.8T / ~16 of 896 experts | 1,000,000 tokens | $3.00 / $15.00 $0.30 cache-hit input | Frontier reasoning, long-horizon coding & agent swarms |
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.
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.
Expose "Standard / Long Context / Pro Agent / Vision" modes in product UI rather than showing raw model IDs to users.
reasoning_effort parameter to control reasoning depth - not the older K2.x "thinking mode"
toggle, which doesn't apply the same way to K3.
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.
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 ?? ""; }
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"]
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.
tool_calls.{
"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"]
}
}
}
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.
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.
"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}."
Vision analysis benefits from structure: bullet lists, step-by-step troubleshooting, or JSON. Keep temperature low and validate outputs, especially for extraction tasks.
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.
Remove older conversation turns that are no longer relevant. Keep only the last few turns and any "pinned" system instructions.
Summarize older context into a short "memory" block: decisions, user preferences, known facts. Replace many turns with one summary message.
Instead of pasting full documents, retrieve only the relevant chunks (RAG) and cite them. Use token estimation to keep retrieval bounded.
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.
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.
| Model | Input (cache miss) | Input (cache hit) | Output |
|---|---|---|---|
| kimi-k2.5 | $0.60 / 1M | Lower, varies | $3.00 / 1M |
| kimi-k2.6 / k2.7-code | $0.95 / 1M | Lower, varies | $4.00 / 1M |
| kimi-k3 | $3.00 / 1M | $0.30 / 1M | $15.00 / 1M |
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).
Token estimation before large requests, context trimming + summarization, deduplicate repeated prompts (idempotency hash), cache retrieval results (RAG).
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.
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"
Even for non-streaming responses, show "Thinking…" plus a spinner and disable the send button briefly. This alone reduces duplicate requests dramatically.
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.
Clear plan messaging ("Free: 3 RPM, 1 concurrency") prevents confusion. Silent throttling feels broken; visible throttling feels fair.
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.
| Component | Responsibility | Why it matters |
|---|---|---|
| Frontend | Collect prompts, show streaming output, show status and history. | Good UX reduces duplicate requests and improves retention. |
| Backend API | Auth, quotas, request validation, prompt templates. | Protects your keys and enforces budgets. |
| Queue + workers | Batch 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. |
| Observability | Logs, traces, metrics, evals, cost tracking. | Debug faster, prevent regressions, improve prompts. |
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).
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.
| Topic | Official link | Use it for |
|---|---|---|
| Docs overview | platform.moonshot.ai/docs/overview | Platform capabilities, navigation, guides |
| Quickstart | platform.moonshot.ai/docs/guide/start-using-kimi-api | First request, basic setup |
| Main concepts | platform.moonshot.ai/docs/introduction | Model families, context windows, concepts |
| Chat API | platform.moonshot.ai/docs/api/chat | Chat request/response details |
| Tool use | platform.moonshot.ai/docs/api/tool-use | Tool calling schema and examples |
| Vision guide | platform.moonshot.ai/docs/guide/use-kimi-vision-model | Vision preview models and usage |
| Token estimation | platform.moonshot.ai/docs/api/estimate | Estimate token counts for text + images |
| Pricing | platform.moonshot.ai/docs/pricing/chat | Price per 1M tokens by model tier |
| FAQ | platform.moonshot.ai/docs/guide/faq | Limits, edge cases, common questions |
| API key console | platform.kimi.ai/console/api-keys | Create and manage API keys |