This guide shows developers how to call Kimi K3, Moonshot AI's most capable model, from their own software. It covers the model name, a first request you can copy, how to control how hard it thinks, tool calls, caching, prices and fixes for common errors. Everything here follows Moonshot's own documentation.
One extra setting matters most with Kimi K3: how much effort it puts into thinking.
kimi-k3https://api.moonshot.ai/v1max_completion_tokens)reasoning_effort: low, high or maxFrom Moonshot's Kimi K3 quickstart and price page. Prices exclude tax.
MOONSHOT_API_KEY. Do not paste it into your code.pip install --upgrade "openai>=1.0". For Node, run npm install openai.Need more detail on keys and accounts? See Kimi API setup.
All three examples ask Kimi K3 a simple question and print the answer. They use low effort and a small output limit to keep the test cheap.
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": 4096,
"messages": [
{"role": "user", "content": "Explain what an API is in two sentences."}
]
}'import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MOONSHOT_API_KEY"],
base_url="https://api.moonshot.ai/v1",
)
response = client.chat.completions.create(
model="kimi-k3",
reasoning_effort="low",
max_completion_tokens=4096,
messages=[
{"role": "user", "content": "Explain what an API is in two sentences."}
],
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.MOONSHOT_API_KEY,
baseURL: "https://api.moonshot.ai/v1",
});
const response = await client.chat.completions.create({
model: "kimi-k3",
reasoning_effort: "low",
max_completion_tokens: 4096,
messages: [
{ role: "user", content: "Explain what an API is in two sentences." },
],
});
console.log(response.choices[0].message.content);Written for this guide in the standard OpenAI format, using the address, model name and settings from Moonshot's quickstart. Notice what is missing: no temperature setting. An older OpenAI SDK may not accept reasoning_effort or max_completion_tokens, so update it first.
Kimi K3 always thinks before it answers, and you cannot switch that off. What you can set is how much effort it spends. More effort usually means better answers on hard problems, with a longer wait and a bigger bill, because thinking is charged as output.
The quickest and cheapest. A sensible choice for simple questions, short edits and tests.
A middle setting for everyday coding and analysis.
The deepest thinking, and the default if you set nothing. Best kept for the hardest jobs.
The three values and the default are from Moonshot's reasoning effort guide. The advice on when to use each is ours. Moonshot's guide does not give figures for the difference, so measure it on your own tasks.
thinking setting from your requests. Kimi K3 uses the top-level reasoning_effort field instead.Moonshot fixes several settings for Kimi K3 and says to leave them out of requests.
| Setting | Fixed at | What to do |
|---|---|---|
temperature | 1.0 | Leave it out |
top_p | 0.95 | Leave it out |
n | 1 | Leave it out. One answer per request |
presence_penalty | 0 | Leave it out |
frequency_penalty | 0 | Leave it out |
| Thinking | Always on | Use reasoning_effort to turn it down |
On a small screen, swipe the table sideways to see every column.
Many libraries send a temperature by default. If yours does, look for a way to remove it. Need thinking switched off completely? Use kimi-k2.6 for those calls.
Each reply has two parts: reasoning_content, the model's thinking, and content, the final answer. Show content to your users.
With streaming on, the reply arrives piece by piece. The thinking comes first, then the answer. Streaming is worth using with Kimi K3, because deep thinking can take a while and a request with no response for 900 seconds times out.
content only.stream = client.chat.completions.create(
model="kimi-k3",
reasoning_effort="high",
stream=True,
messages=[{"role": "user", "content": "Plan a 3-step database migration."}],
)
for chunk in stream:
if not chunk.choices:
continue
delta = chunk.choices[0].delta
thinking = getattr(delta, "reasoning_content", None)
if thinking:
print(thinking, end="", flush=True) # the model's reasoning
if delta.content:
print(delta.content, end="", flush=True) # the answerContinues from the Python example above. A teaching example written for this guide.
Tools let Kimi K3 do real work: search, read files, run code. Moonshot's guides set out a few rules that matter more for this model than for older ones.
After each reply, add the complete assistant message to your history, unchanged, including reasoning_content and tool_calls. Kimi K3 was trained to see its earlier thinking.
Add one tool message for each call, with the matching tool_call_id.
For large tool sets, Moonshot suggests starting with a few core tools plus one "search tools" function, then adding others only when needed.
Set tool_choice to "required" on the first turn to make the model call a tool, then go back to "auto".
For a full tool loop in Python, see the example on the Kimi K2.7 Code API page. The pattern is the same.
content must be a list of parts, not plain text.ms://. Public image links are not supported.video_url part.{
"role": "user",
"content": [
{"type": "image_url",
"image_url": {"url": "data:image/png;base64,PASTE_BASE64_HERE"}},
{"type": "text", "text": "What does this chart show?"}
]
}If many requests start with the same long text, such as instructions or a codebase, Kimi K3 can remember it. Later requests then pay $0.30 per million tokens for that part instead of $3.00. It happens automatically.
usage.prompt_tokens_details.cached_tokens in the reply to see what was reused.{
"model": "kimi-k3",
"prompt_cache_options": {"mode": "implicit", "ttl": "1h"},
"messages": [
{"role": "system", "content": "LONG FIXED INSTRUCTIONS AND REFERENCE TEXT"},
{"role": "user", "content": "The question that changes each time"}
]
}From Moonshot's context caching guide. Text is cached in blocks, and a part smaller than one block is charged at the normal price. The guide does not give the block size.
| Per million tokens | Price |
|---|---|
| Input | $3.00 |
| Cached input | $0.30 |
| Saving to the cache, 5 minutes | $3.00 |
| Saving to the cache, 1 hour | $6.00 |
| Output, including thinking | $15.00 |
Enter a month's usage to see the bill, next to the same work on Kimi K2.6.
List prices before tax. It leaves out the one-off charge for saving to the cache and any web search calls. The Kimi K2.6 figure uses $0.95 in, $0.16 cached and $4.00 out. Kimi K3 always thinks before answering, so its output may be higher than Kimi K2.6 with thinking off.
Moonshot's batch price page lists only Kimi K2.7 Code and Kimi K2.6, so Kimi K3 does not appear to be offered at the cheaper batch rate. More: API pricing · rate limits and enterprise pricing · API vs subscription
| Code | What it means | What to do |
|---|---|---|
| 400 | A setting is not allowed | Remove temperature, top_p, n and the penalty settings. Remove any older thinking setting and use reasoning_effort |
| 400 | The request is too long | Shorten the input or lower the output limit. Everything must fit in 1,048,576 tokens |
| 400 | Image link rejected | Public image links are not supported. Send base64 or an uploaded file reference |
| 401 | The key is wrong or missing | Check the Authorization: Bearer header. A Kimi Code membership key will not work on this address |
| 404 | Model not found | Check the spelling: kimi-k3. Also check that your account has access |
| 429 | Rate limit reached | Slow down or wait. New accounts are limited to 3 requests a minute until total top-ups reach $10 |
| 429 | Servers are busy | Wait and retry with growing pauses. Topping up does not help with this one |
| 504 | Timed out | Long thinking can pass the time limit. Turn on streaming with "stream": true |
On a small screen, swipe the table sideways to see every column.
From Moonshot's error code page and Kimi K3 guides. More help: Kimi not working?