Kimi K2 API Tutorial: Pricing, Free Credits & Python (2026)

Get started with Moonshot's Kimi K2 API — grab a key, call it from curl and Python, compare direct vs. aggregator pricing (input from $0.55/M), understand the 256K context, rate limits and common errors, and call Kimi, GPT and Claude with one key.

Kimi K2 is Moonshot AI’s flagship MoE model. With a long context window and solid price-performance, it has become a serious option for teams building agents, coding tools and long-document pipelines. This guide walks you through it in order: get a key, send your first request, work out the real cost, and understand the rate limits. In a hurry? Grab free credits on GetModel with a referral code and call Kimi, GPT and Claude with a single key.

What Kimi K2 offers

Kimi K2 uses a Mixture-of-Experts (MoE) architecture — roughly 1T total parameters with about 32B active per inference, aiming for “big-model capability at sparse-activation cost.” There are three main variants; the API and usage are identical, they differ in capability tier and price:

  • kimi-k2 (original 0711) — the first open release, lowest price, good for cost-sensitive general tasks.
  • kimi-k2.5 — an all-round upgrade with cache-hit discounts, good for everyday mid-complexity calls.
  • kimi-k2.6 (latest) — the strongest tier today, best at coding and agent workloads, also supports cache discounts.

There are also derivatives such as kimi-k2-thinking (stronger reasoning), kimi-k2-turbo (higher speed) and the coding-specialized kimi-k2.7-code; Moonshot iterates quickly, so check the current lineup in the console before you build. Every variant ships a 256K-token context window, big enough to swallow a whole manual or a large chunk of a codebase — this is its main edge over many similarly priced models.

On the interface side, Kimi K2 is fully compatible with OpenAI’s Chat Completions format (some channels also expose an Anthropic-compatible format), so your existing openai SDK code usually only needs two fields changed to switch over.

Getting started + code

There are two paths below. Direct (official) suits Kimi-only use; aggregator suits you if you also use GPT, Claude or Gemini and would rather not juggle several keys and bills.

Option 1: Direct via the Moonshot platform

  1. Sign up at the Moonshot open platform (users in China can use platform.moonshot.cn);
  2. Create a key under “API Key management”;
  3. Note the base URL: https://api.moonshot.ai/v1 (or https://api.moonshot.cn/v1 in China).

curl:

curl https://api.moonshot.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MOONSHOT_API_KEY" \
  -d '{
    "model": "kimi-k2.6",
    "messages": [{"role": "user", "content": "Introduce Kimi K2 in one sentence"}]
  }'

Python (reuse the openai SDK; only base_url and model change):

from openai import OpenAI

client = OpenAI(
    api_key="your-moonshot-key",
    base_url="https://api.moonshot.ai/v1",
)

resp = client.chat.completions.create(
    model="kimi-k2.6",
    messages=[{"role": "user", "content": "Introduce Kimi K2 in one sentence"}],
)
print(resp.choices[0].message.content)

Add stream=True for streaming (SSE format matches OpenAI); tool calling uses OpenAI’s tools field, no extra adapter needed.

Option 2: Aggregator (one key for Kimi / GPT / Claude)

If your project isn’t Kimi-only, an aggregation gateway like GetModel saves a lot of overhead: one key, one OpenAI-compatible endpoint, switch models by changing the model field only — balance is shared across all models and you get a single bill.

  1. Log in to the GetModel console and create a key (starts with sk-) under “API Tokens”;
  2. Set the base URL to https://getmodel.ai/v1;
  3. Set model to kimi-k2 — see the Kimi K2 model page for variants and capabilities.
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-getmodel-key",
    base_url="https://getmodel.ai/v1",
)

# Call Kimi K2
resp = client.chat.completions.create(
    model="kimi-k2",
    messages=[{"role": "user", "content": "Hello, Kimi"}],
)
print(resp.choices[0].message.content)

# Same code — change model to gpt-5.2 or claude-sonnet-5 to switch providers

The gateway has built-in multi-channel failover, so if one upstream hiccups it switches automatically — steadier for production.

Pricing: direct vs. aggregator

Kimi K2 is billed per token, prices vary by variant, and K2.5 / K2.6 support “cache hits” — a repeated prefix (a long system prompt, a fixed document) that hits the cache drops the input price to 10–20% of list. Below are reference prices per 1M tokens (USD; always defer to live prices on the official site / console):

VariantInput / 1MOutput / 1MCached input / 1M
kimi-k2 (original 0711)$0.55$2.20
kimi-k2.5$0.60$3.00$0.10
kimi-k2.6 (latest)$0.95$4.00$0.16

A few things worth noting:

  • The original K2 has the lowest unit price — best for pure volume when you don’t need peak capability;
  • K2.6 has the highest unit price, but cached input is only $0.16 — for long prompts called repeatedly, the real cost can be far lower than it looks;
  • Official and reseller/aggregator prices fluctuate, so check live pricing before you commit. Live Kimi and other-model prices on GetModel are on the pricing page.

Free credits: sign up on GetModel with a referral code from a partner or creator to claim trial credits, and those credits work across all models — use them to try Kimi, GPT and Claude side by side before picking your primary. Moonshot’s own trial-credit policy is whatever its official site states at the time.

Context length and rate limits

Context: the whole Kimi K2 line offers a 256K-token context, ideal for long-document Q&A, whole-repo code analysis and long multi-turn chats. Remember that longer context raises both token cost and latency per request, so for long-doc work pair it with caching to reuse the fixed parts and save money.

Rate limits: officially, accounts are tiered by RPM (requests per minute), TPM (tokens per minute) and concurrency. New accounts start low and loosen as you top up or grow usage. When throttled, the API returns 429 — always use exponential backoff in production. Via GetModel, limits apply per key and group (visible in the console) and are layered with multi-channel failover, so a single throttled upstream is routed around automatically.

Common errors & troubleshooting

  • 401 / auth failed: mistyped key, a missing Bearer prefix, or a key from another environment. Check that the Authorization header and base_url match.
  • 429 / rate limited: you’ve exceeded RPM/TPM or concurrency. Add exponential backoff, lower concurrency, or raise your account tier; via GetModel, multi-channel failover routes around it automatically.
  • Context length exceeded: input over 256K tokens errors out. Trim the input, chunk it, or enable caching to reuse a fixed prefix.
  • Timeout / dropped connection: caused by long inputs or a flaky network. Set a sensible timeout and retry; in production, enable gateway-side auto-retry and failover.

FAQ

  • Does Kimi K2 have free credits? Yes. Moonshot grants trial credits to new users; signing up via GetModel also gives cross-model credits — good for try-before-you-buy.
  • K2 vs. K2.5 vs. K2.6 — which one? For cheap volume pick kimi-k2; for balanced everyday use kimi-k2.5; for coding / agents / complex reasoning kimi-k2.6, which is most economical with caching on long prompts.
  • Tool calling and streaming supported? Both. Tool calling uses OpenAI’s tools field; streaming uses stream=True, matching OpenAI’s format.
  • Can I call it from China? Yes — Moonshot offers the api.moonshot.cn endpoint. If you also need overseas models like GPT or Claude, an aggregation gateway covers everything with one key.
  • Can I keep my existing OpenAI code? Yes. Kimi K2 is OpenAI Chat Completions-compatible; usually only base_url and model change.

To use Kimi, GPT, Claude and Gemini from one codebase with a single key and one bill, start from the GetModel console and spin up Kimi K2 with your trial credits.