Try Kimi at kimi.com →

Kimi AI API
Setup, Pricing & Examples

The Kimi API lets you build Moonshot AI's models into your own apps. It is OpenAI-compatible and Anthropic-compatible, and it runs Kimi K3.1 Pro with a 1-million-token context. This guide covers getting a key, every price, caching and batch savings, rate limits, and working code to copy.

From $2 / $10 per 1M tokens OpenAI and Anthropic compatible $1 to start
POST /v1/chat/completions { "model": "kimi-k3.1-pro", "reasoning_effort": "high", "stream": true, "messages": [{ "role": "user", "content": "Summarise this contract" }] } Bearer $MOONSHOT_API_KEY OpenAI-compatible Anthropic-compatible Responses API K3.1PRO api.moonshot.ai thinking… 200 OK · streaming reasoning_content content The contract runs 3 years and renews automatically unless cancelled 90 days before the end. Key risks: uncapped liability, and a one-sided price clause. in 1,240 · out 860 tokenscost ≈ $0.011
OVERVIEW

Kimi API at a glance

Moonshot AI runs the Kimi API on its developer platform, platform.kimi.ai. You pay only for the tokens you use, with no subscription, and you can call it with the OpenAI or Anthropic SDKs you already know.

$2 / $10per 1M tokens

K3.1 Pro input and output. Cached input $0.20.

1Mtoken context

1,048,576 tokens on K3.1 Pro and K3, with flat pricing at any length.

60%batch price

The Batch API charges 60% of list price and skips real-time limits.

$1to start

Top up $1 to unlock models. Reach $5 and get a $5 voucher.

Endpoints

  • OpenAI-compatiblehttps://api.moonshot.ai/v1
  • Anthropic-compatiblehttps://api.moonshot.ai/anthropic
  • ChatPOST /v1/chat/completions
  • ResponsesPOST /v1/responses
  • Models listGET /v1/models
  • Consoleplatform.kimi.ai
SETUP

How to get a Kimi API key

  1. 1

    Create a platform account

    Go to platform.kimi.ai and sign up with email or Google. This is separate from your Kimi chat plan.

    Open the platform ↗
  2. 2

    Top up at least $1

    Models unlock after your first successful top-up. Your total top-ups also set your rate-limit tier.

  3. 3

    Create an API key

    Open API keys in the console and create one. Copy it straight away and keep it secret. Never put it in front-end code.

  4. 4

    Save it as an environment variable

    Store it as MOONSHOT_API_KEY, then check it by listing your models.

Terminal
# macOS / Linux export MOONSHOT_API_KEY="sk-..." # Windows PowerShell $env:MOONSHOT_API_KEY="sk-..." # Check your key and see which models you can use curl https://api.moonshot.ai/v1/models \ --header "Authorization: Bearer $MOONSHOT_API_KEY"
Already have a Kimi chat or Kimi Code plan? That doesn't add API balance. The API is billed separately, by token.
QUICKSTART

Your first Kimi API call

Use the official OpenAI SDK and point it at Kimi. Pick your language:

# pip install --upgrade "openai>=1.0" import os from openai import OpenAI client = OpenAI( api_key=os.environ["MOONSHOT_API_KEY"], base_url="https://api.moonshot.ai/v1", ) completion = client.chat.completions.create( model="kimi-k3.1-pro", reasoning_effort="high", # low | high | max (default max) messages=[{"role": "user", "content": "Explain context caching in two sentences."}], ) print(completion.choices[0].message.content)

Python needs version 3.9 or later and openai>=1.0. Swap the model ID to use another model.

app.py r = client.chat.completions.create( model="kimi-k3.1-pro", reasoning_effort="high", messages=[{"role": "user", "content": "Summarize report.pdf"}]) POST /v1/chat/completions K3.1 api.moonshot.ai thinking… streaming Response 200 OK · 2.1s The report shows revenue up 18%, driven by EU sales. Margins held at 24%, but costs rose in Q3. Input tokens Output tokens Cost 12,480 0$0.025 640$0.031 1,280$0.038 1,920$0.044 at $2 in / $10 out per 1M

A request goes to kimi-k3.1-pro, the answer streams back, and you pay for the tokens used.

PRICING

Kimi API pricing by model

Prices are in US dollars per million tokens, before tax. There are no extra charges for long inputs, and thinking tokens are billed as output.

Model IDInputCached inputCache write (5 min / 1 h)OutputContextNotes
kimi-k3.1-pro$2.00$0.20$2.00 / $4.00$10.001MNewest flagship
kimi-k3.1-pro-highspeed$4.00$0.20$4.00 / $8.00$20.001M2–3× faster
kimi-k3$3.00$0.30Billed separately$15.001MPrevious flagship
kimi-k2.7-code$0.95$0.19No charge$4.00256KRetiring by end of Dec 2026
kimi-k2.6$0.95$0.16No charge$4.00256KRetiring by end of Dec 2026

Sources: Moonshot's pricing and K3.1 Pro quickstart pages, plus published reports of the cache-write rates. On K3 models, a 5-minute cache write costs the same as normal input and a 1-hour write costs double. K2 models don't charge for cache writes.

K2 models are retiring. Moonshot says K2-series models stopped being available to newly registered users on 31 October 2026, and all are planned to retire by the end of December 2026. New projects should use kimi-k3.1-pro.

Tools and batch pricing

ToolEndpointPriceWhat you get
Web Search Basic/v1/tools/search$0.002Titles, links and snippets
Web Search Pro/v1/tools/search_pro$0.003Richer search results
URL Fetch/v1/tools/fetch$0.002A web page as Markdown
Batch API/v1/batches60% of list priceK3.1 Pro, K3, K2.7 Code, K2.6

Tool calls are billed only when they succeed with non-empty results. Search results you pass to a model count as input tokens. The older built-in $web_search tool is being replaced by these endpoints.

CALCULATOR

Estimate your Kimi API cost

Kimi API cost calculator

Per request–
Per day–
Per month (30 days)–

An estimate from list prices. It doesn't include cache-write charges on K3 models, and thinking tokens count as output.

Comparing chat plans instead? See Kimi AI pricing.

CACHING

Context caching: pay less for repeated input

  • 1
    It's automatic. When requests share the same starting text, such as a long system prompt or document, the repeated part is read from cache.
  • 2
    Hits are about 90% cheaper. Cached input costs $0.20 per million on K3.1 Pro instead of $2.
  • 3
    Pick a lifetime. A 5-minute cache (default) costs the input price to write. A 1-hour cache costs double but survives longer gaps. Each hit renews the timer.
  • 4
    Keep the prefix identical. Put fixed content first and changing content last. Changing the model or reasoning effort breaks the cache.
Python
# Caching is automatic. Choose how long a new cache entry lives: r = client.chat.completions.create( model="kimi-k3.1-pro", messages=[ {"role": "system", "content": LONG_SHARED_INSTRUCTIONS}, # same prefix every call {"role": "user", "content": question}, ], extra_body={"prompt_cache_options": {"ttl": "1h"}}, # "5m" (default) or "1h" ) d = r.usage.prompt_tokens_details print("cached:", d.cached_tokens)
CACHE COST: 5-MIN VS 1-HOUR 5 calls reuse a 100K-token prefix time 0 min 5 min 10 min 15 min 20 min 25 min 5-minute cache $0.20 $0.02 $0.02 $0.20 $0.20 $0.64 1-hour cache $0.40 $0.02 $0.02 $0.02 $0.02 $0.48 cache writecache hit ($0.20/M)

When calls are more than 5 minutes apart, the 1-hour cache costs less overall.

EXAMPLES

Kimi API code examples

All examples use the Python client from the quickstart. Copy, add your own prompt, and run.

Streaming with thinking

Show the model's reasoning and answer as they arrive.

Python · streaming
stream = client.chat.completions.create( model="kimi-k3.1-pro", reasoning_effort="low", # lowest latency stream=True, messages=[{"role": "user", "content": "Write a haiku about the sea."}], ) for chunk in stream: delta = chunk.choices[0].delta # Thinking arrives in reasoning_content, the answer in content if getattr(delta, "reasoning_content", None): print(delta.reasoning_content, end="", flush=True) if delta.content: print(delta.content, end="", flush=True)

Tool calling

Let Kimi call your functions, then send back the results.

Python · tools
import json tools = [{ "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a city", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"], }, }, }] messages = [{"role": "user", "content": "Do I need an umbrella in Colombo today?"}] r = client.chat.completions.create(model="kimi-k3.1-pro", messages=messages, tools=tools) msg = r.choices[0].message messages.append(msg) # keep the WHOLE assistant message, not just content for call in msg.tool_calls or []: args = json.loads(call.function.arguments) result = {"city": args["city"], "rain_chance": 0.7} # your own function here messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)}) final = client.chat.completions.create(model="kimi-k3.1-pro", messages=messages, tools=tools) print(final.choices[0].message.content)

Structured JSON output

Force output that matches your JSON schema.

Python · json_schema
r = client.chat.completions.create( model="kimi-k3.1-pro", messages=[{"role": "user", "content": "Invoice 1042 from Acme, total 1,250.00 USD, due 30 Nov."}], response_format={ "type": "json_schema", "json_schema": { "name": "invoice", "strict": True, "schema": { "type": "object", "properties": { "number": {"type": "string"}, "vendor": {"type": "string"}, "total": {"type": "number"}, "currency": {"type": "string"}, }, "required": ["number", "vendor", "total", "currency"], "additionalProperties": False, }, }, }, ) data = json.loads(r.choices[0].message.content) # parse content, not reasoning_content

Image understanding

Send an image with your question.

Python · vision
import base64 with open("chart.png", "rb") as f: b64 = base64.b64encode(f.read()).decode() r = client.chat.completions.create( model="kimi-k3.1-pro", messages=[{ "role": "user", "content": [ # must be a list for images {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64}"}}, {"type": "text", "text": "What trend does this chart show?"}, ], }], ) print(r.choices[0].message.content) # Public image URLs are not supported: use base64 or an uploaded file (ms://<file-id>)

Anthropic-compatible Messages API

Works with K3.1 Pro, K3.1 Pro Highspeed and K3. max_tokens is required.

cURL · Messages API
curl https://api.moonshot.ai/anthropic/v1/messages \ --header "Authorization: Bearer $MOONSHOT_API_KEY" \ --header "Content-Type: application/json" \ --data '{ "model": "kimi-k3.1-pro", "max_tokens": 1024, "cache_control": {"type": "ephemeral", "ttl": "1h"}, "messages": [{"role": "user", "content": "Hello"}] }'

More things you can do

  1. Partial mode: add an assistant message with "partial": true to make Kimi continue your text.
  2. Video: upload with purpose="video" and send it as video_url with ms://<file-id>.
  3. Files: upload PDFs and documents, then ask questions about them.
  4. Batch: upload a JSONL file of requests and pay 60% of list price.
  5. Token estimate: count tokens before you send a long request.
K3.1 Pro guide →
FEATURES

Kimi API features

01

Chat Completions

OpenAI-compatible /v1/chat/completions. Switch existing apps by changing the base URL and model.

02

Anthropic Messages

An Anthropic-compatible endpoint at /anthropic/v1/messages for K3.1 Pro, K3.1 Pro Highspeed and K3.

03

Responses API

/v1/responses, with a built-in web_search tool you can switch on.

04

Tool calling

Function calling with tool_choice, plus tools you can add mid-conversation.

05

Structured output

JSON mode and strict json_schema output for data you can parse straight away.

06

Vision and video

Send images and video with text. K3-series models understand both.

07

Files

Upload files to ask questions about them or reference them as ms://<file-id>.

08

Context caching

Automatic. Repeated prefixes bill at about a tenth of the input price.

09

Batch and tokens

Batch jobs at 60% of list price, and a token-estimation endpoint to plan costs.

PARAMETERS

K3.1 Pro parameter rules

K3.1 Pro handles some settings differently from other APIs. Most 400 errors come from these.

SettingHow it works
reasoning_effortlow, high or max. Default is max. Use low for the fastest replies.
ThinkingAlways on for K3.1 Pro. You can't turn it off.
temperature, top_p, n, penaltiesFixed (1.0, 0.95, 1, 0, 0). Leave them out of your request.
max_completion_tokensDefault 131,072, up to 1,048,576. Thinking counts as output.
Multi-turn historySend back the full assistant message, including tool calls, not just its content.
Images and videoUse base64 or ms://<file-id>. Video is uploaded with purpose="video".
LIMITS

Kimi API rate limits

Your limits depend on how much you have topped up in total. They apply to your whole account across all models, and you move up a tier automatically when you top up more.

TierTotal top-upsConcurrent requestsRequests per minuteTokens per day
Tier 0$1 (minimum)LowLow1.5M tokens
Tier 1$1050200No daily cap
Tiers 2–4Between $10 and $3,000Rises with each tierRises with each tierNo daily cap
Tier 5$3,0001,00010,000No daily cap

Your exact limits, including tokens per minute, are shown in the console. Response headers X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset show where you stand. Vouchers don't count towards your tier.

Avoid surprise 429s: limits count your input plus max_completion_tokens, not just what the model actually writes. Set it close to what you need, retry with exponential backoff, and queue requests instead of sending them all at once. Need more? Contact Moonshot's sales team for a custom quota.
COMPARE

Kimi API vs Kimi Code vs Kimi app

Kimi APIKimi CodeKimi app
Best forBuilding your own appsCoding with an AI agentChat, research, documents
How you payPer token, prepaid balanceIncluded in paid Kimi plansFree or monthly plan
Where you sign upplatform.kimi.aikimi.comkimi.com
Base URLapi.moonshot.ai/v1api.kimi.ai/codingNone
Model IDskimi-k3.1-pro and othersk3.1-pro, kimi-for-coding and othersChosen for you

More on Kimi Code and all Kimi models.

FIXES

Common Kimi API errors and fixes

401 Unauthorized
  • Check the key is copied in full and sent as Authorization: Bearer.
  • Make sure you topped up at least $1. Models unlock only after a successful top-up.
  • Kimi Code console keys only work with Kimi Code endpoints, not api.moonshot.ai.
429 Too Many Requests
  • You hit a concurrency, RPM, TPM or daily limit, or your balance ran out.
  • Rate limits count your input plus max_completion_tokens, so set that value close to what you need.
  • Retry with exponential backoff (1s, 2s, 4s…), and turn off unlimited SDK retries.
  • Top up more to move to a higher tier automatically.
400 Bad Request with K3.1 Pro
  • Remove temperature, top_p, n and penalty settings. They are fixed.
  • Don't try to switch thinking off. K3.1 Pro always thinks.
  • For images, content must be a list, not a string.
Image URL errors
  • Public image URLs are not supported. Send the image as base64 or upload it and use ms://<file-id>.
Model not found for K2.6 or K2.7 Code
  • K2 models closed to newly registered users on 31 October 2026 and retire by the end of December 2026.
  • Move to kimi-k3.1-pro. It costs more per token, but caching and batch discounts close much of the gap.
Answers cut off
  • Raise max_completion_tokens. Long thinking can use up the output budget before the answer finishes.
  • Or lower reasoning_effort to high or low.

More help: Kimi troubleshooting.

FAQ

Kimi API FAQ

Sign up at platform.kimi.ai, top up at least $1, then create a key in the API keys section of the console. Store it as an environment variable such as MOONSHOT_API_KEY and never put it in client-side code.

No. The Kimi API is pay-as-you-go, and you must top up at least $1 before models unlock. When your total top-ups reach $5, Moonshot adds a $5 voucher. Chatting in the Kimi app is a separate product with its own free plan.

Kimi K3.1 Pro costs $2 per million input tokens, $0.20 per million cached input tokens and $10 per million output tokens. K3.1 Pro Highspeed costs $4 and $20, and Kimi K3 costs $3 and $15. Thinking tokens are billed as output.

The OpenAI-compatible base URL is https://api.moonshot.ai/v1. The Anthropic-compatible base URL is https://api.moonshot.ai/anthropic.

Yes. You can use the official OpenAI SDKs for Python and Node.js by setting base_url to https://api.moonshot.ai/v1 and using a Kimi model ID such as kimi-k3.1-pro. Some parameters, such as temperature on K3.1 Pro, are fixed.

Caching is automatic. When a request repeats a prefix, those tokens bill at the cached price, $0.20 per million on K3.1 Pro. On K3 models, writing to the cache costs the input price for a 5-minute cache or twice that for a 1-hour cache, set with prompt_cache_options.

Rate limits depend on your total top-ups, from Tier 0 at $1 to Tier 5 at $3,000. Tier 0 has a 1.5 million token daily cap. Tier 1, at $10, allows 50 concurrent requests and 200 requests per minute, and Tier 5 allows 1,000 and 10,000.

Only for existing users. Moonshot says K2-series models stopped being available to newly registered users on 31 October 2026, and all are planned to retire by the end of December 2026.

Yes. Web Search Basic costs $0.002 per call, Web Search Pro $0.003 and URL Fetch $0.002. You can also enable a web_search tool in the Responses API. Search results passed to a model are billed as input tokens.

The Kimi API is pay-as-you-go by token for building your own apps, at api.moonshot.ai. Kimi Code is a coding agent included in paid Kimi plans, with its own keys and base URL, api.kimi.ai/coding.

Start building with the Kimi API

Top up $1, create a key and make your first call in minutes.