Kimi K2 API: Pricing, Setup, Model IDs, Context Window, and Limits

Zeyad Genena

Zeyad Genena

15 min read

Kimi K2 API: Pricing, Setup, Model IDs, Context Window, and Limits

Moonshot AI's original Kimi K2 API is no longer the endpoint to start with. The original kimi-k2 series was retired on May 25, 2026. Current K2-family API work uses kimi-k2.6 for general-purpose tasks or kimi-k2.7-code for coding, while Kimi K3 is Moonshot's flagship model.

Moonshot's current model list is the safest place to check names before copying code from an older K2 tutorial. Retired model IDs can make otherwise correct requests fail.

NeedCurrent option
General K2-family modelkimi-k2.6
Coding modelkimi-k2.7-code
Faster coding modelkimi-k2.7-code-highspeed
Current Kimi flagshipkimi-k3
K2.6 context window262,144 tokens
API base URLhttps://api.moonshot.ai/v1
Chat completions endpoint/v1/chat/completions
OpenAI SDK compatibilityYes
Permanent production API free tierNo

What is the Kimi K2 API?

The Kimi API gives applications direct access to Moonshot AI models through code. A request can send text, conversation history, images, video, tool definitions, or structured-output instructions, depending on the model and endpoint.

kimi-k2.6 is the current general-purpose K2-family model. Moonshot describes it as supporting text, image, and video input, thinking and non-thinking modes, dialogue, tool use, and agent tasks.

kimi-k2.7-code is the coding-focused branch. It keeps thinking enabled and is tuned for longer software-engineering tasks.

Kimi K3 is the newer flagship. Its 1M-token context window is four times the 256K context available on K2.6 and K2.7 Code.

Kimi K2 vs K2.6 vs K2.7 Code vs K3

The names look similar, but they are not interchangeable.

Original Kimi K2: kimi-k2-0905-preview, kimi-k2-0711-preview, kimi-k2-turbo-preview, kimi-k2-thinking, and related K2 IDs are retired.

Kimi K2.6: A general-purpose K2-family model with a 256K context window. It supports multimodal input, thinking controls, JSON output, and tool use.

Kimi K2.7 Code: A coding-focused model with a 256K context window. Thinking stays enabled.

Kimi K3: Moonshot's flagship model with a 1M-token context window.

A model-ID check should be the first debugging step for code copied from an older K2 example.

Kimi K2 API pricing

Moonshot bills direct Kimi API usage by tokens. Cached input, uncached input, and generated output have different rates.

Kimi's K2.6 pricing and K2.7 Code pricing pages list these current rates:

ModelCached input / 1MUncached input / 1MOutput / 1MContext
kimi-k2.6$0.16$0.95$4.00262,144
kimi-k2.7-code$0.19$0.95$4.00262,144
kimi-k2.7-code-highspeed$0.38$1.90$8.00262,144

Prices exclude applicable taxes.

How Kimi K2 API costs are calculated

A K2.6 request with 1 million uncached input tokens and 100,000 output tokens costs:

  • Input: $0.95
  • Output: $0.40
  • Total model cost: $1.35

The same request drops to $0.56 when all 1 million input tokens qualify for the $0.16 cache-hit rate.

Caching has the biggest effect on workloads that reuse the same system prompt, long document set, codebase context, or conversation prefix across many requests.

Is there a free Kimi K2 API?

Moonshot does not currently offer a permanent free tier for production API usage.

The Kimi recharge and rate-limit page states that an account must recharge at least $1 before API use starts. A $5 voucher is issued after cumulative recharge reaches $5.

Free access in Kimi's consumer products is separate from API billing. The same distinction applies to third-party providers that may offer promotional Kimi endpoints. Those routes can have different quotas, rate limits, model IDs, and availability.

How to get a Kimi K2 API key

Direct Moonshot requests require a Kimi API account, an API key, and available balance.

1. Create or sign in to a Kimi API account

Open the Kimi API platform and sign in.

2. Create an API key

Generate a key from the Kimi API Keys console.

Copy the key once it appears and store it in a password manager, secret manager, or protected environment configuration.

3. Store the key as an environment variable

Keep the key out of application source code.

For macOS or Linux:

export MOONSHOT_API_KEY="your_api_key"

For a .env file:

MOONSHOT_API_KEY=your_api_key

Add .env to .gitignore before committing the project.

Moonshot's API overview specifically warns against exposing API keys in client-side code, public repositories, or logs.

4. Add API balance

New accounts need at least a $1 recharge before direct API calls can start.

Production environments are easier to manage with separate keys for development, staging, and production. Any exposed key should be revoked rather than reused.

Kimi K2 model ID and API endpoint

The current general-purpose K2 model ID is:

kimi-k2.6

The coding model ID is:

kimi-k2.7-code

The faster coding variant is:

kimi-k2.7-code-highspeed

The Kimi API base URL is:

https://api.moonshot.ai/v1

Chat completions use:

POST /v1/chat/completions

The model-list endpoint is:

GET /v1/models

That model-list call is worth using during setup because account availability can change over time.

Older IDs such as these should not be used for a new integration:

kimi-k2-0905-preview

kimi-k2-thinking

kimi-k2-turbo-preview

How to use Kimi K2 API

Kimi follows the OpenAI Chat Completions request and response format, so the official OpenAI SDK can be used with Moonshot's base URL.

Kimi K2 API Python example

Install the OpenAI package:

pip install --upgrade openai

Then create the client:

1import os
2from openai import OpenAI
3
4client = OpenAI(
5 api_key=os.environ["MOONSHOT_API_KEY"],
6 base_url="https://api.moonshot.ai/v1"
7)
8
9response = client.chat.completions.create(
10 model="kimi-k2.6",
11 messages=[
12 {
13 "role": "user",
14 "content": "Explain context caching in three short bullets."
15 }
16 ]
17)
18
19print(response.choices[0].message.content)

The API key, base_url, and model ID are the three settings that usually explain a failed first request.

Kimi K2 API cURL example

The same request works without an SDK:

1curl https://api.moonshot.ai/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $MOONSHOT_API_KEY" \
4 -d '{
5 "model": "kimi-k2.6",
6 "messages": [
7 {
8 "role": "user",
9 "content": "Explain context caching in three short bullets."
10 }
11 ]
12 }'

A cURL request is useful for separating an API problem from an SDK or application problem. Authentication, account balance, the endpoint, and the model ID can all be checked before more code is added.

Kimi K2 API Node.js example

The OpenAI Node.js SDK uses the same base URL:

1import OpenAI from "openai";
2
3const client = new OpenAI({
4 apiKey: process.env.MOONSHOT_API_KEY,
5 baseURL: "https://api.moonshot.ai/v1"
6});
7
8const response = await client.chat.completions.create({
9 model: "kimi-k2.6",
10 messages: [
11 {
12 role: "user",
13 content: "Give me three ways to reduce API token usage."
14 }
15 ]
16});
17
18console.log(response.choices[0].message.content);

The request shape is close to the ChatGPT API, but Kimi has its own model IDs and parameter rules.

Is the Kimi K2 API OpenAI compatible?

Yes. Moonshot uses the OpenAI Chat Completions request and response format and supports the official OpenAI Python and Node.js SDKs.

The OpenAI-to-Kimi migration documentation shows the basic changes:

  • replace the API key
  • point base_url to https://api.moonshot.ai/v1
  • replace the OpenAI model ID with a Kimi model ID

Compatibility stops short of identical parameter behavior.

Migrating from OpenAI to Kimi

A basic client change looks like this:

1client = OpenAI(
2 api_key=os.environ["MOONSHOT_API_KEY"],
3 base_url="https://api.moonshot.ai/v1"
4)

Then set the model:

model="kimi-k2.6"

K2.6 uses fixed sampling values. Thinking mode uses temperature=1.0; non-thinking mode uses temperature=0.6. Other values return an error.

K2.7 Code always runs in thinking mode and uses temperature=1.0.

K2.6 and K2.7 Code also reject:

tool_choice="required"

Use auto or none with those models.

Older OpenAI integrations may still send functions and function_call. Kimi supports the newer tools and tool_calls pattern instead. A plain chat migration can therefore work, while an older tool workflow still needs changes.

Kimi K2 context window and token limits

Kimi K2.6 and K2.7 Code both support a 262,144-token context window, usually described as 256K.

The context window includes the working material for a request: system instructions, user input, conversation history, retrieved documents, tool messages, and generated output.

Context window vs max output tokens

A 256K context window does not mean every response can contain 256K output tokens.

Moonshot's K2.6 model documentation lists a default max_tokens value of 32,768 for K2.6. The current Chat Completions API uses max_completion_tokens as the preferred parameter name.

The total request must still fit inside the model's context window. Large inputs reduce the room available for output.

What happens when the response hits the token limit?

A completion that reaches its configured output ceiling ends with:

finish_reason = "length"

Repeated truncation usually points to one of four problems:

  • the completion budget is too small
  • the prompt carries more context than the task needs
  • old conversation turns are consuming the window
  • a large job should be split into several calls

Streaming does not increase the token limit, but it does let long responses start reaching the application before generation finishes.

Kimi K2 tool calling and structured output

Tool calling lets Kimi return a structured request for application code to execute.

Moonshot's tool-calling flow follows seven practical steps:

1. Define the tool and its JSON schema.

2. Send the tool definition with the request.

3. Let Kimi select a tool when the prompt requires one.

4. Read the returned tool name and arguments.

5. Execute the function in application code.

6. Send the tool result back to Kimi.

7. Generate the next model response from that result.

Kimi supplies the requested action and arguments. The application still owns authentication, validation, permissions, and the actual API or database call.

tool_calls vs function_call

Current Kimi integrations use:

tools

tool_calls

Older OpenAI code may still use:

functions

function_call

Moonshot does not support the deprecated functions parameter for Kimi function execution. That is a common source of migration failures in older agent code.

Kimi K2 structured output

The Kimi Chat Completions API supports both JSON mode and JSON Schema-constrained output through response_format.

Plain JSON uses:

{

"response_format": {

"type": "json_object"

}

}

Schema-constrained output uses json_schema, which is a better choice when downstream code expects fixed fields and types.

Typical uses include:

  • extracting fields from documents
  • classifying requests
  • returning product attributes
  • generating arguments for downstream workflows
  • turning unstructured text into application data

A valid JSON shape is not enough on its own. Check important values in application code before they trigger another system.

From Kimi API calls to a deployed AI agent

Model access covers inference, not the rest of an agent system. A customer-facing deployment also needs trusted data, tool permissions, guardrails, channels, monitoring, and a clear path to human review for cases that should not be automated.

Chatbase currently lists Kimi K2.7 among its model options and adds that surrounding agent layer. Teams moving past API experiments can build an AI agent with knowledge, actions, deployment channels, and human support workflows around supported models.

Kimi K2 API rate limits

Kimi does not publish one RPM number that applies to every account.

Direct API limits depend on cumulative recharge and are measured across four dimensions:

  • Concurrency: Requests processed at the same time
  • RPM: Requests per minute
  • TPM: Tokens per minute
  • TPD: Tokens per day

One of those limits can be reached before the others. Moonshot also says temporary rate-limit adjustments may happen when cluster load reaches capacity.

How to handle Kimi API 429 errors

A 429 response points to a rate-limit or quota problem.

A production retry policy should include:

Exponential backoff: Increase the delay after each failed retry.

Jitter: Add a small random delay so multiple workers do not retry together.

Concurrency control: Cap parallel calls instead of letting traffic spikes flood the same account.

Token monitoring: Track TPM as well as request count. A few large prompts can consume the token limit quickly.

Balance and quota checks: Confirm billing status before treating every 429 as a traffic problem.

Request logs: Store model ID, request size, retry count, and response code so recurring failures can be traced.

Kimi K2 coding and reasoning

K2.6 and K2.7 Code solve different jobs.

K2.6: General-purpose work across coding, reasoning, multimodal input, dialogue, and agent tasks. Thinking can be enabled or disabled.

K2.7 Code: Software-engineering work where long-context coding and instruction following matter more than general conversation. Thinking stays enabled.

K3: The better Moonshot choice for workloads that need the current flagship or more than 256K context.

Model selection here is mostly about workload shape. A coding-heavy agent has a stronger reason to test K2.7 Code, while mixed text, visual, and general reasoning work points back toward K2.6 or K3.

Kimi K2 benchmarks

Benchmark numbers are easy to misread because "Kimi K2" now covers several distinct releases.

Moonshot's K2.7 Code benchmark release reports a Kimi Code Bench v2 score of 62.0 for K2.7 Code versus 50.9 for K2.6. Moonshot also reports gains on Program Bench and MLS Bench Lite. Kimi Code Bench v2 is an internal Moonshot benchmark, so those numbers should be read with the test setup in mind.

For an independent view, Artificial Analysis' K2.6 evaluation currently gives K2.6 a score of 45 on its Intelligence Index and measures 50.3 output tokens per second on Kimi's API.

The version label matters more than the headline score. Original K2, K2.5, K2.6, and K2.7 Code should not be mixed into one benchmark table.

A small evaluation set built from the production workload is more useful than choosing a model from one public leaderboard. Track answer quality, latency, tool-call success, failure rate, and cost on the same tasks.

Kimi K2 vs DeepSeek

For current API work, the relevant DeepSeek comparison is K2.6 against DeepSeek V4 Flash or V4 Pro rather than older R1 or V3 releases.

DeepSeek's current model and pricing page lists both V4 models with 1M-token context windows, thinking and non-thinking modes, JSON output, and tool calls.

Published uncached token prices are currently lower than K2.6:

  • DeepSeek V4 Flash: $0.14 per 1M input tokens and $0.28 per 1M output tokens
  • DeepSeek V4 Pro: $0.435 per 1M input tokens and $0.87 per 1M output tokens
  • Kimi K2.6: $0.95 per 1M input tokens and $4 per 1M output tokens

DeepSeek also warns that its API pricing is expected to rise, so those rates should be checked again before a long-term cost forecast is approved.

K2.6 brings multimodal input and Moonshot's Kimi toolchain. DeepSeek V4 brings a 1M context window and, at current published rates, lower token pricing.

Coding quality, tool reliability, latency, and instruction following still need side-by-side testing on the same workload. Chatbase's DeepSeek API overview covers the setup and API details for that comparison.

Kimi K2 vs Claude

Claude Sonnet 5 trades higher token pricing for a larger context window and a different model stack.

Anthropic's current Claude model documentation lists Sonnet 5 at:

  • Context window: 1M tokens
  • Maximum synchronous output: 128K tokens
  • Input: $2 per 1M tokens
  • Output: $10 per 1M tokens

Kimi K2.6 has a 256K context window and direct API pricing of $0.95 per 1M uncached input tokens and $4 per 1M output tokens.

At current list prices, K2.6 is the cheaper option. Sonnet 5 costs more but gives the application four times as much context. The better pick depends on whether lower token cost or the larger context window matters more, then on how both models perform against the same test set.

Chatbase's Claude API overview covers Anthropic's model IDs, setup, and pricing for a direct API evaluation.

Kimi K2 API limitations and when to use another model

K2.6 covers a broad range of workloads, but several cases point elsewhere.

More than 256K context is required

K2.6 and K2.7 Code both stop at 256K context. Kimi K3 supports 1M tokens, which makes it the natural Moonshot option for very large codebases, long document sets, or extended context-heavy sessions.

Coding is the main workload

K2.7 Code is purpose-built for software engineering and should be tested before K2.6 on repository-scale coding, refactoring, debugging, and long agent sessions.

An OpenAI migration depends on exact parameter behavior

Kimi is OpenAI-compatible, not identical to OpenAI. Temperature rules, thinking controls, tool_choice, and deprecated function-calling patterns can require code changes.

Free production access is a hard requirement

Direct Moonshot API usage requires account balance and does not currently include a permanent production free tier. Third-party promotional endpoints can change quota or disappear, which makes them a weak foundation for production capacity planning.

Tools can trigger high-impact actions

Tool calls that can move money, approve refunds, delete accounts, change production systems, or expose sensitive data need stronger controls than a normal read-only lookup.

Use application-level validation, explicit confirmation, or human approval for actions that are costly or hard to reverse. The model can propose the tool call; the application remains responsible for what is allowed to run.

Kimi K2 API FAQs

Is the Kimi K2 API free?

No permanent production free tier is currently available through Moonshot's direct API. New API accounts need at least a $1 recharge before requests can start. Third-party providers may offer free Kimi routes, but their quotas and rate limits are separate from Moonshot's own API.

What is the Kimi K2 API model ID?

Use kimi-k2.6 for the current general-purpose K2-family model. Coding workloads can use kimi-k2.7-code or kimi-k2.7-code-highspeed. Original IDs such as kimi-k2-0905-preview and kimi-k2-thinking are retired.

What is the Kimi K2 context window?

Kimi K2.6 and K2.7 Code both support 262,144 tokens, usually described as a 256K context window. That number covers the model's total working context and should not be read as a guaranteed output length.

Can I use the OpenAI SDK with the Kimi API?

Yes. Kimi supports the OpenAI Python and Node.js SDKs. Set Moonshot's API key and base URL, choose a current Kimi model ID, then test Kimi-specific behavior for thinking, temperature, tool_choice, and tool calls before production rollout.

Share this article:

Zeyad Genena
Article byZeyad Genena

Zeyad Genena is a Senior Content Writer at Chatbase with 5+ years of experience in SaaS and AI driven customer solutions. He holds a degree in Business Economics. At Chatbase, he covers AI agent design, CX strategy, and customer operations for midsize and enterprise businesses.

Reviewed by
Sandra Dajic

Build AI Agents for free with Chatbase

Upload files, connect sources like Notion or URLs, and go live in minutes.

cta