Codex CLI runs fine on Kimi K2. Moonshot’s API is OpenAI-compatible — exactly what Codex expects — so you add it as a custom provider, set the wire protocol, and point Codex at a K2 model. Kimi’s strong reasoning and Codex’s speed make a capable pairing at pay-per-token rates well below the frontier providers.
This is the working config and the one detail that trips people up. For Codex’s general provider model, see Codex CLI custom provider setup.
Step 1: Codex CLI and a Moonshot key
Install Codex CLI per its docs, then sign up on the Moonshot platform and create an API key. On Windows, env vars are cleaner in WSL — see Codex CLI on Windows with WSL.
Step 2: Add Kimi to config.toml
Codex reads ~/.codex/config.toml. Add Moonshot via its OpenAI-compatible endpoint:
model = "kimi-k2-thinking"
model_provider = "moonshot"
[model_providers.moonshot]
name = "Moonshot Kimi"
base_url = "https://api.moonshot.ai/v1"
env_key = "MOONSHOT_API_KEY"
wire_api = "chat"
Export the key and run:
export MOONSHOT_API_KEY="sk-your-key"
codex
Confirm the base URL and model ID in Moonshot’s docs.
Step 3: Pick the model
Kimi K2 models in Codex
| kimi-k2-thinking | Reasoning mode; multi-step problems |
|---|---|
| kimi-k2 (turbo variants) | Faster, cheaper everyday coding |
Use Thinking for hard tasks and a faster variant for routine work. Confirm exact IDs on Moonshot.
Pricing
Kimi is pay-per-token with cache-hit discounts and no flat coding plan. Rates are low, and cache hits help during agent sessions that reuse context. Confirm current numbers on Moonshot’s docs — see Kimi K2 pricing explained.
Troubleshooting
- Format/streaming errors — missing
wire_api = "chat", or you used/anthropic. - Auth errors —
MOONSHOT_API_KEYnot set in the shell. - “Model not found” — confirm the Kimi model ID on Moonshot.
- Changes ignored — restart Codex;
config.tomlloads at startup.
Kimi + Codex checklist
- Codex CLI installed; Moonshot key created
- [model_providers.moonshot] block with /v1 base_url
- wire_api = "chat" set
- model and model_provider point to Kimi
- MOONSHOT_API_KEY exported; Codex restarted
Wrapping up
Using Kimi K2 with Codex CLI is a clean config.toml setup: a [model_providers.moonshot] block on the /v1 endpoint, wire_api = "chat", and a K2 model. Export the key, restart Codex, and you’ve got Kimi’s reasoning behind a fast agent at pay-per-token rates.
To run Kimi with other tools, see run Kimi K2 Thinking with Claude Code or Kimi K2.5 Turbo + OpenCode.