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

  1. 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.
  2. 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.
  3. Pick it for an agentIn the Agents tab, choose a Kimi model on the agent’s row: kimi-k2.6 on the API, say, or kimi-for-coding on Kimi Code.
Terminal
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

PresetPlanOpenAI Chat CompletionsAnthropic MessagesKey from
KimiKimi API, pay as you gohttps://api.moonshot.ai/v1https://api.moonshot.ai/anthropicplatform.kimi.ai
Kimi (China)Kimi API, pay as you gohttps://api.moonshot.cn/v1https://api.moonshot.cn/anthropicplatform.kimi.com
Kimi CodeKimi Code membershiphttps://api.kimi.ai/coding/v1https://api.kimi.ai/codingkimi.ai/code/console
Kimi Code (China)Kimi Code membershiphttps://api.kimi.com/coding/v1https://api.kimi.com/codingkimi.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.

Terminal
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

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

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.