Kimi K2.7 Code API setup: base URL, both ids, first request.

Updated 2026-07-16

Moonshot's current Kimi K2 generation is two served ids here: kimi-k2.7-code, the June 2026 coding specialist, and kimi-k2.6, the April 2026 generalist. Point any OpenAI-compatible client at https://api.apisrouter.com/v1, set the model field to either id exactly, and the request is a standard chat completion with no Moonshot account involved.

Quick answer: one base URL, two model strings.

Every OpenAI-compatible SDK takes a base URL and a key. Set the base URL to https://api.apisrouter.com/v1, pick the id, kimi-k2.7-code for coding-agent work, kimi-k2.6 for general and mixed workloads, and the payload is the same /v1/chat/completions shape you already send everywhere else. Spell the ids exactly: lowercase, with the dots and the -code suffix where it applies. kimi-k2.7-code and kimi-k2.6 are separate models; a typo returns model-not-found rather than silently routing to the other one, so a smoke test on each id you plan to use settles the wiring in two requests.

curl https://api.apisrouter.com/v1/chat/completions \
  -H "Authorization: Bearer $APISROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k2.7-code",
    "messages": [{"role": "user", "content": "Write a bash one-liner that finds the largest file in a git repo."}]
  }'

What the two ids actually are.

Kimi K2.7-Code shipped on June 12, 2026, per Moonshot's announcement and launch coverage (MarkTechPost, June 12, 2026): a coding-focused release with open weights on Hugging Face under a Modified MIT license, a Mixture-of-Experts design reported at 1 trillion total parameters with about 32 billion active per token, and a 256K-token context window. Moonshot's headline claims are efficiency claims: roughly a third fewer reasoning tokens than K2.6 on comparable work, and a 21.8% gain on Kimi Code Bench v2, a benchmark Moonshot itself maintains, so weigh it as a vendor-graded number. Kimi K2.6 is the April 2026 generalist the -Code model branched from, positioned by Moonshot for long-horizon agent work: launch materials claimed autonomous coding sessions of roughly 12 hours and agent swarms coordinating up to 300 sub-agents. It remains the id to reach for when the workload is not purely code: analysis, writing, mixed agent loops, and anything conversational. Both ids serve a 256K context in the catalog here, and both carry the same per-token rate, so the choice between them is fit, not price.

Quickstart: Python and JavaScript.

Both official OpenAI SDKs accept a custom base URL at client construction. The model field passes through as a plain string, so one client object can send a kimi-k2.7-code request and a claude-sonnet-4-6 request back to back, which is exactly how you A/B them. Keep the key in an environment variable, and pin the id in one config constant so a later switch between the two Kimi ids is a one-line diff.

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["APISROUTER_API_KEY"],
    base_url="https://api.apisrouter.com/v1",
)

resp = client.chat.completions.create(
    model="kimi-k2.7-code",
    messages=[
        {"role": "system", "content": "You are a precise coding assistant."},
        {"role": "user", "content": "Refactor this loop into a comprehension and explain the tradeoff: ..."},
    ],
    max_tokens=4000,
)
print(resp.choices[0].message.content)
print(resp.usage)  # prompt_tokens / completion_tokens per request

Long agent runs: what the family is built for, and how to budget them.

The K2 line's defining trait since the K2 Thinking release in late 2025 has been long tool-calling chains: Moonshot has claimed hundreds of sequential tool calls without human intervention, and K2.6's launch materials extended that to multi-hour autonomous coding sessions. Those are vendor claims, but the community experience matches the direction: this family degrades late and holds plans across long loops better than most open-weight peers. Long runs move the cost question from per-request to per-run. Three habits keep a multi-hour agent session predictable. First, watch completion_tokens per step, not per session: K2.7-Code's reported one-third reasoning-token reduction against K2.6 is precisely a completion_tokens claim, and your own usage log verifies it on your workload in an afternoon. Second, set max_tokens with headroom on every step; a truncated reasoning pass mid-plan costs a whole run. Third, scope one key to one agent experiment, so the usage view doubles as the run's cost ledger. The 256K window matters here too: a long session accumulates repository state, diffs, and test output, and 256K holds a serious working set without aggressive summarization. It is smaller than the 1M windows elsewhere in the catalog, so agents that carry giant contexts should either trim state or route the context-heavy steps to a longer-window id.

The Anthropic-compatible route, stated precisely.

On Moonshot's own platform, the Kimi API also exposes an Anthropic-compatible Messages endpoint, and community guides plus Moonshot's forum document pointing Claude Code at it by overriding ANTHROPIC_BASE_URL with a Moonshot key. That is a real and popular path, and it is worth knowing it exists: it is how much of the community first ran K2 models inside Claude Code. Through APIsRouter the surface is the OpenAI-compatible /v1 documented on this page, so tools that speak chat completions, which is nearly everything, connect with the base URL and key above. If your tool only speaks the Anthropic Messages protocol, use Moonshot's direct platform for that specific integration; for everything else, one gateway key covers both Kimi ids next to the Claude, GPT, and DeepSeek ids you would benchmark them against.

Which id to wire in.

Pin whichever id wins in your config, and record it next to results the way you would a random seed: Moonshot ships fast, and a config that says which exact id produced last month's numbers is the difference between a rerun and an argument.

  • kimi-k2.7-code: coding agents, refactors, test generation, CI loops. The efficiency claims target exactly this traffic, and less reasoning volume per step compounds over a long run.
  • kimi-k2.6: general assistant work, analysis, writing, and mixed agent loops where steps alternate between code and prose. Also the safer default while K2.7-Code is new to your eval set.
  • Both at once: planner and executor splits work well here, k2.6 holding the plan, k2.7-code writing the diffs, since both ids share one endpoint and one key.
  • Neither blindly: the ids price identically, so the A/B costs nothing extra to run. Ten representative tasks through each id, judged on your rubric plus completion_tokens, settles the seat.

Pay-as-you-go · transparent per-model pricing

Selected models are priced below official list prices. Exact input, output, cache, and per-request prices are shown for each model.

ModelOfficial PriceOur Price
Kimi K2.7 Code$0.95 / $4.00 per M$0.85 / $3.60 per M
Kimi K2.6$0.95 / $4.00 per M$0.85 / $3.60 per M
Claude Sonnet 4.6$3.00 / $15.00 per M$2.40 / $12.00 per M
GPT-5.5$5.00 / $30.00 per M$4.00 / $24.00 per M

Verify the endpoint and debug the first request.

List the served models first; both Kimi ids must appear exactly as you plan to send them. First-request failures follow the usual short list. A 401 means the key was not exported into the shell your code runs in. A 404 on the path means the base URL is missing its /v1 suffix, because SDKs append /chat/completions to whatever base they get. Model-not-found is a spelling issue: kimi-k2.7-code has both dots and the suffix, and kimi-k2.6 has no suffix at all. A response cut off with finish_reason=length on agent work means max_tokens is too tight for a model that reasons before it answers; raise it before judging quality. Once requests flow, the console's per-request view shows model, token counts, and spend, which for long agent runs is the number that decides everything else on this page.

curl -s https://api.apisrouter.com/v1/models \
  -H "Authorization: Bearer $APISROUTER_API_KEY" | grep kimi

FAQ

What is the Kimi K2 API base URL?

Through APIsRouter it is https://api.apisrouter.com/v1, an OpenAI-compatible endpoint. Any OpenAI SDK accepts it as base_url (Python) or baseURL (JavaScript), and both kimi-k2.7-code and kimi-k2.6 are served under one key next to the rest of the catalog.

What is the difference between kimi-k2.7-code and kimi-k2.6?

kimi-k2.7-code is the June 12, 2026 coding specialist; Moonshot claims roughly a third fewer reasoning tokens than K2.6 and a 21.8% gain on its own Kimi Code Bench v2. kimi-k2.6 is the April 2026 generalist built for long-horizon agent work. Both serve 256K context here at the same rate.

Does the Kimi API work with the OpenAI SDK?

Yes. Moonshot's own platform is OpenAI-compatible, and so is the gateway route documented here: custom base URL, standard chat completions, streaming, and the standard tools array all work without a Kimi-specific client.

Can I use Kimi K2 with Claude Code?

On Moonshot's direct platform, yes: it exposes an Anthropic-compatible Messages endpoint, and community guides document overriding ANTHROPIC_BASE_URL to route Claude Code through it. The gateway route on this page is OpenAI-compatible, which covers most other tools with one key.

What context window do the Kimi K2 models have?

Both kimi-k2.7-code and kimi-k2.6 serve a 256K-token context in the catalog here, matching the window Moonshot published for the K2.7 generation. That holds a large agent working set, though it is smaller than the 1M windows some other catalog families carry.

Is Kimi K2.7 open source?

The weights are open: Moonshot published K2.7-Code on Hugging Face under a Modified MIT license at release. At a reported 1 trillion total parameters it needs multi-GPU server hardware to self-host, which is why most access runs through hosted APIs.