Try Kimi at kimi.com →

Kimi API: Setup, API Keys & First Request

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.

About 15 minutescurl, Python and Node.js
Your app Hello Kimi Hi! How canI help? KKimi API kimi-k3 kimi-k2.7-code kimi-k2.6 request →← answer your_code.py base_url = "api.moonshot.ai/v1" model = "kimi-k3" message = "Hello Kimi" → "Hi! How can I help?" 200 OK

Your app sends a request, a Kimi model works on it, and the answer comes straight back.

Keep your API key private. We are an independent guide, not Moonshot AI. This page never asks for your key, and no real website should. Create and manage keys only on the official platform, platform.kimi.ai.
QUICK ANSWER

The short version

  1. 1

    Get a key

    Sign in at platform.kimi.ai, add at least $1 and create an API key.

  2. 2

    Point your code at Kimi

    Use the OpenAI SDK with Kimi's base URL and your key.

  3. 3

    Send a message

    Call chat completions with the model kimi-k3.

Base URL: https://api.moonshot.ai/v1

BEFORE YOU START

What you need

A platform account

The API has its own site, platform.kimi.ai. It is separate from the Kimi chat app and billed separately.

At least $1

There is no free tier and no monthly fee. You top up a balance and pay for what you use.

A way to run code

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.

Step 1

Create a platform account

  1. Go to platform.kimi.ai. Check the address before you sign in.
  2. Sign up or sign in.
  3. You land in the console. This is where you manage keys, billing and usage.
Two platforms exist. platform.kimi.ai is the global one and uses api.moonshot.ai. Accounts on the mainland China platform use api.moonshot.cn. A key only works on the platform that made it.
Step 2

Add credit

Open the billing page in the console and top up. The minimum is $1, which is plenty for testing.

Total topped upRequests at onceRequests per minute
$1 (starting tier)13
$1015100
$3,000100300

On a small screen, swipe the table sideways to see every column.

Step 3

Create an API key

  1. In the console, open API Keys.
  2. Create a new key. Give it a name you will recognise, such as "laptop-test".
  3. Copy the key straight away and keep it somewhere safe, such as a password manager.
Treat the key like a password. Anyone who has it can spend your balance. If you think a key has leaked, delete it in the console and make a new one.
Step 4

Store the key safely

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.

Mac and Linux

Terminal
export MOONSHOT_API_KEY="YOUR_KIMI_API_KEY"

Windows PowerShell

PowerShell
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.

Step 5

Send your first request

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
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?"}
    ]
  }'

What each line means

  • 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.
first-request $ export MOONSHOT_API_KEY="sk-••••••••" $ pip install --upgrade openai $ python first.py → POST api.moonshot.ai/v1/chat/completions ← 200 OK model: kimi-k3 1 + 1 = 2 ✓ First request done
With Kimi K3, leave out temperature, top_p, n and the penalty settings. They are fixed for this model, and sending them can cause an error.
Step 6

Read the response

Kimi sends back JSON. A shortened example of its shape:

JSON · shortened example
{
  "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": ...
  }
}

Where to look

  • 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.
Answers vary. You will not get exactly the same wording each time. That is normal.

For multi-step conversations with Kimi K3, send back the complete assistant message each turn, including its reasoning_content, not just the text.

MODELS

Choose a model

To switch model, change the model value. Prices are per million tokens, in US dollars.

Model nameBest forInputOutput
kimi-k3Hardest jobs. About 1 million tokens of context$3.00$15.00
kimi-k2.7-codeCoding$0.95$4.00
kimi-k2.7-code-highspeedFast coding$1.90$8.00
kimi-k2.6General 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

COST

What your first request costs

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.

You pay for tokens

A token is a small piece of a word. Text going in and text coming out are both counted.

Thinking counts as output

Kimi K3 always thinks before it answers. Use a lower reasoning_effort for simple jobs.

Always set a cap

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

SAFETY

API key safety

  1. 1

    Never put it in code

    Read it from an environment variable or a secrets manager.

  2. 2

    Never commit it

    Keep keys out of Git. Add .env files to .gitignore.

  3. 3

    Never ship it to browsers

    Call Kimi from your server, not from web page or app code that users can read.

  4. 4

    One key per project

    If one leaks, you can delete it without breaking the others.

  5. 5

    Watch your usage

    Check the console now and then for spending you do not recognise.

  6. 6

    Leaked? Replace it

    Delete the key in the console and create a new one straight away.

HELP

Fix first-request errors

ErrorWhat it meansWhat to do
401The key is wrong, missing or for the other platformCheck the key and the base URL. Global keys use api.moonshot.ai. Open a new terminal so the variable is loaded.
404The model name does not existUse kimi-k3, kimi-k2.7-code or kimi-k2.6. Older names were retired.
429Too many requestsNew accounts allow 3 requests a minute. Wait and retry, or top up to raise the limit.
400Something in the request is not allowedWith Kimi K3, remove temperature and top_p. Send images as files, not web links.
Empty answerThe token cap ran out while Kimi was still thinkingRaise max_completion_tokens or lower reasoning_effort.
KeyError or undefined keyYour code cannot find the environment variableSet 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.

CHECKLIST

Setup checklist

0 of 7 done

Your ticks are not saved if you close or reload this page.

NEXT STEPS

After your first request

Use it in tools you know

Many apps that accept an "OpenAI-compatible" endpoint work with Kimi. Enter the base URL, your key and a Kimi model name.

Add web search

Kimi has a separate Web Search API, charged per call.

Web Search API pricing

Prefer a ready-made tool?

Kimi Code gives you a coding assistant without writing API code.

Kimi Code setup

FAQ

Kimi API questions

Sign in at platform.kimi.ai, add at least $1 of credit, open the API Keys page in the console and create a key. Copy it and store it somewhere safe.

No. There is no free tier. You top up from $1 and pay only for the tokens you use. Once your top-ups reach $5, Moonshot adds a $5 voucher.

For global accounts it is https://api.moonshot.ai/v1. Accounts made on the mainland China platform use https://api.moonshot.cn/v1. A key from one does not work on the other.

Yes. You can use the official OpenAI SDK for Python or Node.js. You only change the base URL, the API key and the model name. Kimi also works with tools built for the Anthropic format.

Moonshot's quickstart uses kimi-k3. For cheaper everyday calls use kimi-k2.6, and for coding use kimi-k2.7-code.

No. App plans and the API are billed separately. Paying for one does not give you credit on the other.
NEXT

Related guides

Get your API key

Accounts, keys and billing are on Moonshot's own platform, never on this page. We are an independent guide.