Skip to content

API · Beginner

Kimi API quickstart: your first call in five minutes

The Kimi API is OpenAI-compatible, so you can use the official OpenAI SDK by pointing it at Moonshot’s base URL. Create an API key on the Kimi platform, set `base_url` to the Moonshot endpoint, choose a model identifier such as `kimi-k3`, and your existing code works unchanged.

Last updated

What do you need before you start?

Three things: an account on the Kimi API platform, an API key, and an OpenAI-compatible SDK. That is genuinely the whole list — there is no separate Kimi SDK to learn.

One thing worth getting straight before you sign up, because it causes real confusion: the Kimi API platform is a different product from the Kimi app and from Kimi Code. Moonshot documents these as distinct products with separate billing. A Kimi Membership subscription does not give you API access, and API credit does not pay for the app. If you want to call models from code, you want the platform at platform.kimi.ai.

How do you get a Kimi API key?

Create an account on the Kimi API platform, then generate a key in the user centre. Store it in an environment variable rather than in your code:

export MOONSHOT_API_KEY="sk-..."

Two habits worth forming immediately:

  • Never commit the key. Add .env to .gitignore before you create it, not after. Leaked API keys are found by automated scanners within minutes.
  • Use a separate key per environment. Development, staging and production should have different keys, so revoking one does not take down the others.

How do you make your first request?

Install the OpenAI SDK and point it at Moonshot’s base URL. Here is a complete, working Python example:

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-k2.6",
    messages=[
        {"role": "system", "content": "You are a concise technical assistant."},
        {"role": "user", "content": "Explain a context window in two sentences."},
    ],
)

print(response.choices[0].message.content)

The JavaScript equivalent:

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-k2.6',
  messages: [
    { role: 'system', content: 'You are a concise technical assistant.' },
    { role: 'user', content: 'Explain a context window in two sentences.' },
  ],
});

console.log(response.choices[0].message.content);

If you already have code calling OpenAI, the migration is those two constructor arguments plus the model name.

Which model should you use?

Start cheap. The model identifier is a per-request string, so this is not a decision you are locked into.

Model identifier Use it for Output per 1M
kimi-k2.6 General-purpose default $4.00
kimi-k2.7-code Coding tasks $4.00
kimi-k2.7-code-highspeed Coding, latency-critical $8.00
kimi-k3 Long context, hardest reasoning $15.00

Two identifiers you may find in older tutorials and should not use: kimi-k2.5 sunsets on 31 August 2026 and is closed to new accounts, and the entire kimi-k2-* series was discontinued on 25 May 2026 — those endpoints no longer respond.

See every Kimi model compared for the full picture, or work out what your workload will cost with the API cost calculator.

How does reasoning effort work on Kimi K3?

If you use kimi-k3, this is the parameter that will surprise you on your first invoice. K3 always reasons — you cannot disable it. You control depth with a top-level reasoning_effort field accepting low, high or max.

The default is max.

response = client.chat.completions.create(
    model="kimi-k3",
    messages=messages,
    reasoning_effort="low",  # default is "max"
)

Reasoning tokens are billed as output tokens at $15.00 per million, so leaving the default in place on high-volume simple requests is an easy and expensive mistake. Set it explicitly.

What does streaming look like?

Same as OpenAI — pass stream=True and iterate:

stream = client.chat.completions.create(
    model="kimi-k2.6",
    messages=messages,
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)

Stream anything a person is reading as it arrives. Perceived latency is dominated by time-to-first-token, not total generation time, and streaming is free.

What should you know about rate limits and cost before going to production?

Two things that catch people out.

Rate limits are measured four ways. Moonshot documents concurrency, requests per minute (RPM), tokens per minute (TPM) and tokens per day (TPD) — and you hit whichever binds first. Their own example is instructive: 20 requests of 100 tokens each can exhaust a 20 RPM limit while using a fraction of your token quota. Handle 429 responses with exponential backoff from day one.

Context caching is automatic and changes your economics. Moonshot caches repeated prompt prefixes automatically, and cache-hit input can cost as little as one tenth of cache-miss input. Structure your prompts so the stable part — system prompt, tool definitions, few-shot examples — comes first and stays byte-identical between calls. That ordering alone can move an agent’s bill more than choosing a different model does.

Frequently asked questions

Is the Kimi API compatible with OpenAI?

Yes. Moonshot exposes a Chat Completions interface that matches OpenAI’s, so the official OpenAI SDKs work by changing the base URL and API key. Most existing integrations need no other modification.

What is the Kimi API base URL?

The global endpoint is https://api.moonshot.ai/v1. Pass it as base_url when constructing an OpenAI-compatible client, along with your Kimi platform API key.

Is the Kimi API free?

No. The Kimi API platform uses pay-as-you-go billing with no subscription tier, charged per token consumed. It is billed separately from Kimi Membership and Kimi Code, which are different products with different pricing.

Which Kimi model should I start with?

Start with kimi-k2.6 for general work or kimi-k2.7-code for programming tasks — both cost $4.00 per million output tokens. Move to kimi-k3 when you need its 1,048,576-token context window or its stronger reasoning, at $15.00 per million output tokens.

Do I need a different API key for each Kimi model?

No. One API key works across every model on the platform. You select the model per request with the model parameter, so switching models is a one-line change.

What are the Kimi API rate limits?

Moonshot measures limits four ways — concurrency, requests per minute, tokens per minute and tokens per day — and you hit whichever binds first. The specific numbers depend on your account tier, so check the rate limits page on the platform for your own quota.

Models mentioned

  • Kimi K3 is Moonshot AI’s flagship model, with 2.8 trillion parameters, native visual understanding and a 1,048,576-token context window.

  • Kimi K2.7 Code is Moonshot AI’s coding-focused model, with a 262,144-token context window and higher instruction-following reliability in long contexts.

  • Kimi K2.6 is a general-purpose model with a 262,144-token context window, supporting text, image and video input across thinking and non-thinking modes.

Read next