The Kimi API lets your own code talk to Kimi. This guide takes you from no account to a working first request: sign up, add credit, create an API key, and run a few lines of code. Copy and paste as you go.
Your app sends a request, a Kimi model works on it, and the answer comes straight back.
Sign in at platform.kimi.ai, add at least $1 and create an API key.
Use the OpenAI SDK with Kimi's base URL and your key.
Call chat completions with the model kimi-k3.
Base URL: https://api.moonshot.ai/v1
The API has its own site, platform.kimi.ai. It is separate from the Kimi chat app and billed separately.
There is no free tier and no monthly fee. You top up a balance and pay for what you use.
A terminal is enough for curl. For the SDK you need Python 3.8 or later, or Node.js 18 or later.
Not a developer? You probably want the Kimi app, not the API. See plan or API: how to choose and how to use Kimi AI.
api.moonshot.ai. Accounts on the mainland China platform use api.moonshot.cn. A key only works on the platform that made it.Open the billing page in the console and top up. The minimum is $1, which is plenty for testing.
| Total topped up | Requests at once | Requests per minute |
|---|---|---|
| $1 (starting tier) | 1 | 3 |
| $10 | 15 | 100 |
| $3,000 | 100 | 300 |
On a small screen, swipe the table sideways to see every column.
Do not paste the key into your code. Save it as an environment variable named MOONSHOT_API_KEY, which is the name Moonshot's own examples use. Your code then reads it from there.
export MOONSHOT_API_KEY="YOUR_KIMI_API_KEY"
setx MOONSHOT_API_KEY "YOUR_KIMI_API_KEY"
Replace YOUR_KIMI_API_KEY with your real key. On Windows, close PowerShell and open it again so the new value is picked up. On Mac and Linux, the export line lasts until you close the terminal.
Pick the way you prefer. All three do the same thing: ask Kimi K3 "What is 1+1?" and print the answer.
Nothing to install. Paste this into a Mac or Linux terminal.
curl https://api.moonshot.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MOONSHOT_API_KEY" \
-d '{
"model": "kimi-k3",
"reasoning_effort": "low",
"max_completion_tokens": 2048,
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is 1+1?"}
]
}'Install the OpenAI SDK, save the code as first.py, then run python first.py.
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",
reasoning_effort="low",
max_completion_tokens=2048,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is 1+1?"},
],
)
print(completion.choices[0].message.content)Install the OpenAI SDK, save the code as first.mjs, then run node first.mjs.
npm install openai@latest
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.MOONSHOT_API_KEY,
baseURL: "https://api.moonshot.ai/v1",
});
const completion = await client.chat.completions.create({
model: "kimi-k3",
reasoning_effort: "low",
max_completion_tokens: 2048,
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is 1+1?" },
],
});
console.log(completion.choices[0].message.content);base_url: sends the request to Kimi, not to OpenAI.model: which Kimi model answers.reasoning_effort: how hard Kimi K3 thinks. Use low, high or max. The default is max.max_completion_tokens: a cap on the answer, so a test cannot run up a big bill.messages: the conversation. "system" sets the behaviour and "user" is your question.temperature, top_p, n and the penalty settings. They are fixed for this model, and sending them can cause an error.Kimi sends back JSON. A shortened example of its shape:
{
"id": "chatcmpl-...",
"model": "kimi-k3",
"choices": [
{
"message": {
"role": "assistant",
"content": "1 + 1 = 2",
"reasoning_content": "..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": ...,
"completion_tokens": ...,
"total_tokens": ...
}
}choices[0].message.content: the answer. This is what the examples print.reasoning_content: Kimi K3's thinking. Useful for debugging.finish_reason: stop means it finished. length means it hit your token cap.usage: how many tokens you were charged for.For multi-step conversations with Kimi K3, send back the complete assistant message each turn, including its reasoning_content, not just the text.
To switch model, change the model value. Prices are per million tokens, in US dollars.
| Model name | Best for | Input | Output |
|---|---|---|---|
kimi-k3 | Hardest jobs. About 1 million tokens of context | $3.00 | $15.00 |
kimi-k2.7-code | Coding | $0.95 | $4.00 |
kimi-k2.7-code-highspeed | Fast coding | $1.90 | $8.00 |
kimi-k2.6 | General use at lower cost | $0.95 | $4.00 |
On a small screen, swipe the table sideways to see every column.
Older names such as kimi-k2.5 and moonshot-v1 were retired on 31 August 2026 and now return a 404 error. Settings differ between models, so check the docs when you switch. Guides: Kimi K3 API · all Kimi models · API docs guide
Almost nothing. The test above sends a few dozen tokens and caps the answer at 2,048 tokens. Even if Kimi K3 used the whole cap, that is about 3 cents. A normal "1+1" answer costs a tiny part of that.
A token is a small piece of a word. Text going in and text coming out are both counted.
Kimi K3 always thinks before it answers. Use a lower reasoning_effort for simple jobs.
Kimi K3's default cap is very high, at 131,072 tokens. Set max_completion_tokens yourself.
Kimi API pricing · Web Search API pricing · Enterprise pricing
Read it from an environment variable or a secrets manager.
Keep keys out of Git. Add .env files to .gitignore.
Call Kimi from your server, not from web page or app code that users can read.
If one leaks, you can delete it without breaking the others.
Check the console now and then for spending you do not recognise.
Delete the key in the console and create a new one straight away.
| Error | What it means | What to do |
|---|---|---|
| 401 | The key is wrong, missing or for the other platform | Check the key and the base URL. Global keys use api.moonshot.ai. Open a new terminal so the variable is loaded. |
| 404 | The model name does not exist | Use kimi-k3, kimi-k2.7-code or kimi-k2.6. Older names were retired. |
| 429 | Too many requests | New accounts allow 3 requests a minute. Wait and retry, or top up to raise the limit. |
| 400 | Something in the request is not allowed | With Kimi K3, remove temperature and top_p. Send images as files, not web links. |
| Empty answer | The token cap ran out while Kimi was still thinking | Raise max_completion_tokens or lower reasoning_effort. |
| KeyError or undefined key | Your code cannot find the environment variable | Set MOONSHOT_API_KEY again, then open a new terminal window. |
On a small screen, swipe the table sideways to see every column.
More fixes: Kimi AI not working.
Your ticks are not saved if you close or reload this page.
Many apps that accept an "OpenAI-compatible" endpoint work with Kimi. Enter the base URL, your key and a Kimi model name.
Kimi Code gives you a coding assistant without writing API code.