Docs · Provider
Kimi K2 and Kimi Code in Claude Code, Codex, Gemini CLI and OpenCode
Kimi, from Moonshot AI, comes two ways: the Kimi API, paid as you go, and the Kimi Code membership, each with a global and a China endpoint. magpie has a preset for each of the four. Add a key once, and Claude Code, Codex, Gemini CLI, OpenCode and your other agents can use Kimi’s models through magpie’s gateway at 127.0.0.1:3425.
Add Kimi
- Get a keyFor the Kimi API, from the Kimi platform’s API keys page; for Kimi Code, from the Kimi Code console. The table below links each.
- Add the providerIn Providers, press + Add provider and pick the preset that issued your key: Kimi, Kimi (China), Kimi Code or Kimi Code (China). Paste the key and save. magpie asks Kimi which models it serves.
- Pick it for an agentIn the Agents tab, choose a Kimi model on the agent’s row:
kimi-k2.6on the API, say, orkimi-for-codingon Kimi Code.
magpie provider add moonshot sk-… # Kimi API (platform.kimi.ai) magpie provider add moonshot-cn sk-… # Kimi API, China (platform.kimi.com) magpie provider add kimi-code sk-… # Kimi Code membership magpie provider add kimi-code-cn sk-… # Kimi Code membership, China
Model ids are provider/model: moonshot/kimi-k2.6, kimi-code/kimi-for-coding. The models listed are the ones Kimi serves your key at the time.
Plans and endpoints
| Preset | Plan | OpenAI Chat Completions | Anthropic Messages | Key from |
|---|---|---|---|---|
| Kimi | Kimi API, pay as you go | https://api.moonshot.ai/v1 | https://api.moonshot.ai/anthropic | platform.kimi.ai |
| Kimi (China) | Kimi API, pay as you go | https://api.moonshot.cn/v1 | https://api.moonshot.cn/anthropic | platform.kimi.com |
| Kimi Code | Kimi Code membership | https://api.kimi.ai/coding/v1 | https://api.kimi.ai/coding | kimi.ai/code/console |
| Kimi Code (China) | Kimi Code membership | https://api.kimi.com/coding/v1 | https://api.kimi.com/coding | kimi.com/code/console |
A key works only on the endpoints of the plan and region that issued it, so pick the preset that matches where you got it.
In each agent
Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.
magpie claude moonshot/kimi-k2.6 magpie codex moonshot/kimi-k2.6 magpie gemini model moonshot/kimi-k2.6 magpie opencode kimi-code/kimi-for-coding
- Claude Code speaks Anthropic Messages, and so does Kimi’s Anthropic endpoint, so its requests are passed on as they are. Every tier (opus, sonnet, haiku) runs on the model you pick unless you give one its own. Models in Claude Code.
- Codex speaks only OpenAI Responses. Kimi serves Chat Completions and Anthropic Messages but not Responses, so magpie translates each request and the reply, streaming and tool calls included. The model shows in Codex’s
/modelwith its reasoning efforts. Models in Codex. - Gemini CLI speaks Gemini’s API. magpie points it at its gateway and translates. Models in Gemini CLI.
- OpenCode gets the model in
opencode.json, with its reasoning variants and cost. Models in OpenCode.
Thinking
Some Kimi models always think: Kimi Code (China)’s K3.1 turns away a request that switches thinking off. When an agent asks for it off and the model refuses, magpie asks again with thinking left on, so the agent gets an answer rather than the error.
Balance, windows and search
- Kimi API. The row shows your balance: in ¥ for Kimi (China), in $ for Kimi.
- Kimi Code. The row shows the membership’s windows, read from Kimi: the weekly allowance, shorter windows such as five hours, the monthly allowance and a booster pack’s balance.
- Cost. Kimi Code’s models are listed at $0, so magpie’s Usage tab prices their calls at the Kimi API’s price for the same model.
- Web search. A Kimi Code key searches the web through the membership’s own search endpoint, and magpie gives that search to Kimi Code models that can’t search by themselves.
FAQ
How do I use Kimi K2 in Codex?
Add your Kimi key in magpie, then pick a Kimi model such as kimi-k2.6 on Codex’s row, or run magpie codex moonshot/kimi-k2.6. Kimi serves Chat Completions and Anthropic Messages but not the Responses API Codex speaks, so magpie translates each request and the reply, streaming and tool calls included.
Can I use my Kimi Code membership in Claude Code or Codex?
Yes. Add the Kimi Code preset (or Kimi Code (China)) with a key from the Kimi Code console. magpie sends requests to the membership’s own endpoints, https://api.kimi.ai/coding for Anthropic Messages and https://api.kimi.ai/coding/v1 for Chat Completions, and shows the membership’s usage windows.
Kimi or Kimi (China): which preset do I pick?
The one that issued your key. A key from platform.kimi.ai goes with Kimi (api.moonshot.ai); one from platform.kimi.com goes with Kimi (China) (api.moonshot.cn). Kimi Code has the same two: kimi.ai and kimi.com.
Why does Kimi Code show a cost when the membership is prepaid?
Kimi Code’s model list prices its models at $0, so magpie prices each call at the Kimi API’s price for the same model. The figure shows what the work would have cost on the API; it isn’t charged.
Can Kimi Code search the web for my agent?
Yes. A Kimi Code key searches the web through the membership’s own search endpoint, so a Kimi Code model that can’t search by itself is given magpie’s search on your plan.
Every agent: Models in Claude Code, Models in Codex, Models in Gemini CLI, Models in OpenCode. Ask on Discord if you get stuck.