Field SOP
Field SOP

Kimi Dual Protocol: One Config for Codex and Claude Code

Moonshot announced on 2026-09-02 that the Kimi API natively supports dual protocols: OpenAI Responses (api.moonshot.cn/v1) plus Anthropic Messages (api.moonshot.cn/anthropic), with kimi-k3 as the flagship model. Hands-on SOP: point Claude Code's ~/.claude/settings.json ANTHROPIC_BASE_URL to /anthropic with model kimi-k3[1m]; set Codex's ~/.codex/config.toml wire_api="responses". This turns Kimi into a unified model-routing gateway — switch the backend without touching client code. Boundaries: Responses is text+image only, kimi-k2.7-code forces thinking, and the old ANTHROPIC_API_KEY must be removed.

Published September 5, 202611 min read
<!-- kimi-dual-protocol-sop | sop | Kimi Dual Protocol: One Config for Codex and Claude Code -->

Overview

On September 2, 2026, Moonshot announced that the Kimi API natively supports dual-protocol access. This means a single Kimi model can now be served simultaneously through two different protocols: the OpenAI Responses API and the Anthropic Messages API. For teams that already rely on Codex or Claude Code, the practical benefit is immediate: you do not need to rewrite any client code. You only adjust a handful of environment variables and configuration files, and the underlying model switches from the original vendor to Kimi.

This article is a step-by-step SOP. It walks you through the complete flow, from obtaining an API key, configuring Claude Code, configuring Codex, and finally verifying that the integration works. It also explains how to use dual-protocol routing as a unified gateway, the official pricing in RMB, and a set of boundary conditions that are easy to trip over. If you are evaluating how to migrate an existing development toolchain to a domestic large model at the lowest possible cost, you can follow this guide directly.

Background and Use Cases

In the past, if you wanted to use Kimi inside a tool that spoke the OpenAI protocol, you usually had to build your own compatibility gateway. Tools such as Claude Code, which are bound to the Anthropic protocol, were even harder to repoint at a different underlying model. Dual-protocol access removes that barrier by providing protocol compatibility directly at the Kimi server side.

Typical use cases include the following:

  • You already use Codex, which speaks the OpenAI Responses protocol, for daily development, and you want to swap the underlying model to Kimi K3 to reduce cost or improve Chinese-language ability, without touching any client code.
  • Your team's primary IDE assistant is Claude Code, which speaks the Anthropic Messages protocol, and you want to switch to Kimi without rewriting the toolchain.
  • You want to treat Kimi as a unified multi-model routing gateway: with one client configuration, you switch only the model name referenced by an environment variable to move flexibly between K3, K2.7 Code, and K2.6.

It is important to be clear that protocol compatibility does not mean capability or pricing parity with the original vendor. Kimi provides protocol-level compatibility; the actual context window, tool-calling behavior, and pricing must be checked against the official Moonshot documentation. The most accurate mental model is a gateway: Kimi translates between protocols and its own processing, but the model's capability envelope is decided by Kimi itself.

Prerequisites

Before you begin, confirm that you meet the following conditions:

  1. A valid Moonshot account with API access enabled.
  2. A working API key, referred to below as <MOONSHOT_API_KEY>.
  3. Claude Code and the Codex command-line tool installed and runnable locally.
  4. A shell profile such as ~/.bashrc or ~/.zshrc that can export and load environment variables correctly.

If you are on Windows, note that paths such as ~/.claude/settings.json and ~/.codex/config.toml refer to the corresponding files under your user home directory. In a PowerShell environment, environment variables should be set through the $env: syntax or the system environment variable panel rather than bash's export.

Step 1: Obtain Your Moonshot API Key

Log in to the Moonshot developer console and create a new key on the API Key management page. Store the key in a safe place. Do not commit it to a code repository, and do not hardcode it into any configuration file.

All configuration in this guide injects the key through environment variables, so you only need to export it into your current shell. For example, add the following to ~/.bashrc:

sh
export MOONSHOT_API_KEY="sk-xxxxxxxxxxxxxxxx"
export KIMI_API_KEY="sk-xxxxxxxxxxxxxxxx"

Note that the Claude Code configuration reads the key from ANTHROPIC_AUTH_TOKEN, while the Codex configuration reads it from KIMI_API_KEY. Both can point to the same value, but the variable names differ, so do not confuse them. It is recommended to export both variables so you do not miss one when switching tools later.

Step 2: Configure Claude Code

Claude Code communicates with the model over the Anthropic Messages protocol. Kimi provides a compatible endpoint for this protocol, so you only need to write a set of environment variables into the env block of ~/.claude/settings.json to complete the switch.

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.moonshot.cn/anthropic",
    "ANTHROPIC_AUTH_TOKEN": "<MOONSHOT_API_KEY>",
    "ANTHROPIC_MODEL": "kimi-k3[1m]",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-k3[1m]",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-k3[1m]",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-k2.7-code",
    "ANTHROPIC_DEFAULT_FABLE_MODEL": "kimi-k3[1m]",
    "CLAUDE_CODE_SUBAGENT_MODEL": "kimi-k3[1m]",
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000",
    "CLAUDE_CODE_EFFORT_LEVEL": "max"
  }
}

Key field notes:

  • ANTHROPIC_BASE_URL must point to https://api.moonshot.cn/anthropic, the Anthropic-protocol compatible endpoint that Kimi exposes (POST /anthropic/v1/messages).
  • ANTHROPIC_AUTH_TOKEN holds your Moonshot API key. Delete the old ANTHROPIC_API_KEY, otherwise it may conflict with ANTHROPIC_AUTH_TOKEN and cause authentication errors.
  • ANTHROPIC_MODEL is the primary model kimi-k3[1m], where [1m] enables a roughly one-million-token context window.
  • ANTHROPIC_DEFAULT_HAIKU_MODEL can be set to kimi-k2.7-code so that a lightweight model is used when a lighter tier is needed.
  • CLAUDE_CODE_AUTO_COMPACT_WINDOW is set to 1000000 to align with K3's long-context capability.
  • CLAUDE_CODE_EFFORT_LEVEL is set to max so the model spends a higher reasoning budget on coding tasks.

Step 3: Configure Codex

Codex speaks the OpenAI Responses protocol, which maps to Kimi's https://api.moonshot.cn/v1 endpoint (POST /v1/responses). Edit ~/.codex/config.toml:

toml
model="kimi-k3"
model_provider="kimi"
model_context_window=1048576

[model_providers.kimi]
name="Kimi"
base_url="https://api.moonshot.cn/v1"
env_key="KIMI_API_KEY"
wire_api="responses"

Key points:

  • base_url must be https://api.moonshot.cn/v1, the OpenAI Responses compatible endpoint that Kimi exposes.
  • wire_api="responses" tells Codex to use the Responses API rather than the older Chat Completions API.
  • The key is read from the environment via env_key="KIMI_API_KEY"; do not hardcode it in the toml file, to avoid leaking the secret.
  • model_context_window=1048576 matches K3's million-token context (1048576 equals 1024 times 1024).
  • model_provider="kimi" must match the [model_providers.kimi] block name below; the two names have to be identical.

Step 4: Verify the Integration

Verify Claude Code

After launching Claude Code, run the /status command. The correct output should show:

  • Base URL = https://api.moonshot.cn/anthropic
  • Model = kimi-k3[1m]

If the original vendor's address or model is still displayed, the environment variables did not take effect. Check whether settings.json is loaded correctly and whether the old ANTHROPIC_API_KEY was removed. You can also send a simple message and observe whether the response comes from Kimi.

Verify Codex

Run a single Codex request in the terminal and observe whether the response comes from the Kimi endpoint. If the model name matches the configuration and a normal conversation is possible, the integration succeeded. If you see an error, first check whether KIMI_API_KEY was exported and whether the base_url spelling in the toml is correct.

Dual-Protocol Routing: Switch Models Without Changing Client Code

The real value of dual-protocol access is unified routing. You can treat Kimi as a multi-model gateway where the client code never changes and only the configuration layer switches:

  • When you need stronger reasoning during peak workloads, point both ANTHROPIC_MODEL and Codex's model at kimi-k3[1m].
  • When you want lightweight code completion, point the HAIKU tier at kimi-k2.7-code.
  • When you want to try an earlier version, switch to kimi-k2.6.

The whole process requires no change to client code; you only edit the model name in an environment variable or configuration file. This is exactly what "one config for Codex and Claude Code" means: one integration logic, two protocols, each mapped to the client you already know.

A reminder: the different models are not fully equivalent in capability. For example, kimi-k2.7-code forces thinking on. If Thinking is not enabled on the Claude Code side, the call returns 400. So when you switch models, confirm the target model's protocol behavior requirements to avoid triggering errors.

Migration Strategy: Staged Rollout and Rollback

When you roll this out to a team, avoid switching everyone to Kimi at once. Use a staged approach: validate stability in a small scope first, then expand coverage gradually. That way, even if something goes wrong, the blast radius stays minimal.

Step one: on your own machine, complete the integration and verification described above. Make sure /status and your Codex requests both point at the Kimi endpoints, and that everyday tasks such as code completion, function refactoring, and unit-test generation all finish correctly. The core goal here is to confirm there are no hidden protocol-compatibility gaps, especially around whether tool-call parameters are passed through correctly.

Step two: pick a non-critical project as a pilot. Point both Claude Code and Codex at Kimi, run them for one or two days, and actively record three metrics: response quality, end-to-end latency, and the share of failed requests. Pay close attention to whether tool use returns as expected, whether long context stays stable across many turns, and whether rate limits or timeouts appear during peak hours.

Step three: if the pilot metrics hold up, migrate more projects the same way. If you hit problems, rollback is just restoring the environment variables and config files to the original vendor's addresses; the client code does not change at all. This configuration-level rollback is the biggest operational advantage of dual-protocol access: risk stays in the config layer, not the code layer, so the cost of backing out is extremely low.

Finally, fold key management into your team norms. Inject API keys through environment variables only, and never hardcode them in repositories or shared config. Give each member an independent key so you can measure usage, investigate anomalies, and control cost per key in the Moonshot console. For CI pipelines, inject secrets the same way and keep plaintext keys out of logs.

Boundary Conditions and Gotchas

  1. The Responses API supports text and images only, with no video channel. If you upload video through the Responses API, the request is rejected.
  2. search_context_size is not supported. Passing it returns 400. Kimi's built-in web_search runs server-side, so the client does not need to specify a context size.
  3. kimi-k2.7-code forces thinking. In Claude Code, if Thinking is not enabled, calls to this model return 400.
  4. The old ANTHROPIC_API_KEY must be deleted. It conflicts with ANTHROPIC_AUTH_TOKEN, and its residue causes authentication failures.
  5. Protocol compatibility is not capability or pricing parity. Kimi provides protocol compatibility; the concrete context window, tool behavior, and pricing follow the official documentation.

Pricing Reference (Official RMB)

The following are the RMB prices published by Moonshot officially. Do not cite second-hand USD figures:

ModelCachedInputOutput
K3¥2.00 / MTok¥20.00 / MTok¥100.00 / MTok
K2.7 Code¥6.50 / MTok¥27.00 / MTok

Pricing unit: MTok = one million tokens. Please refer to the latest official Moonshot announcement for the most current numbers.

Frequently Asked Questions

Q1: What is dual-protocol access? Dual-protocol access means the Kimi API natively supports both the OpenAI Responses API and the Anthropic Messages API at the same time. A single Kimi model can be reached through two endpoints, https://api.moonshot.cn/v1 or https://api.moonshot.cn/anthropic, which lets it serve client tools from different ecosystems without each one building its own compatibility gateway.

Q2: How do I switch models without changing client code? You only change the model name and the corresponding environment variables in the configuration. For example, change Claude Code's ANTHROPIC_MODEL from kimi-k3[1m] to kimi-k2.7-code, or change Codex's model to kimi-k2.6; the client code needs no modification. When switching, pay attention to the target model's protocol behavior, because K2.7 Code forces thinking and would otherwise return 400.

Q3: How do I configure Claude Code to use Kimi? In the env block of ~/.claude/settings.json, set ANTHROPIC_BASE_URL=https://api.moonshot.cn/anthropic, ANTHROPIC_AUTH_TOKEN=<MOONSHOT_API_KEY>, ANTHROPIC_MODEL=kimi-k3[1m], and related fields, and delete the old ANTHROPIC_API_KEY. After launch, use /status to verify that the Base URL and Model are correct.

Q4: How do I configure Codex to use Kimi? In ~/.codex/config.toml, set model="kimi-k3", model_provider="kimi", and model_context_window=1048576, and fill the [model_providers.kimi] block with base_url="https://api.moonshot.cn/v1", env_key="KIMI_API_KEY", and wire_api="responses". The key is read from the environment; do not hardcode it.

Q5: What boundary conditions and gotchas should I watch for? The main ones are: the Responses API has no video channel; search_context_size is unsupported and returns 400; kimi-k2.7-code forces thinking and returns 400 if Thinking is off; the old ANTHROPIC_API_KEY must be deleted to avoid conflict; and protocol compatibility is not capability or pricing parity. For related reading, see the Gemini 3.8 Flash security hotspot, the DeepSeek open-source harness, and the CodeArena coding review.

This article is AI-assisted and human-edited. Last updated: 2026-09-05

FAQ

What is dual-protocol access?
Dual-protocol access means the Kimi API natively supports both the OpenAI Responses API and the Anthropic Messages API at the same time. A single Kimi model can be reached through two endpoints, `https://api.moonshot.cn/v1` or `https://api.moonshot.cn/anthropic`, which lets it serve client tools from different ecosystems without each one building its own compatibility gateway.
How do I switch models without changing client code?
You only change the model name and the corresponding environment variables in the configuration. For example, change Claude Code's `ANTHROPIC_MODEL` from `kimi-k3[1m]` to `kimi-k2.7-code`, or change Codex's `model` to `kimi-k2.6`; the client code needs no modification. When switching, pay attention to the target model's protocol behavior, because K2.7 Code forces thinking and would otherwise return 400.
How do I configure Claude Code to use Kimi?
In the `env` block of `~/.claude/settings.json`, set `ANTHROPIC_BASE_URL=https://api.moonshot.cn/anthropic`, `ANTHROPIC_AUTH_TOKEN=<MOONSHOT_API_KEY>`, `ANTHROPIC_MODEL=kimi-k3[1m]`, and related fields, and delete the old `ANTHROPIC_API_KEY`. After launch, use `/status` to verify that the Base URL and Model are correct.
How do I configure Codex to use Kimi?
In `~/.codex/config.toml`, set `model="kimi-k3"`, `model_provider="kimi"`, and `model_context_window=1048576`, and fill the `[model_providers.kimi]` block with `base_url="https://api.moonshot.cn/v1"`, `env_key="KIMI_API_KEY"`, and `wire_api="responses"`. The key is read from the environment; do not hardcode it.
What boundary conditions and gotchas should I watch for?
The main ones are: the Responses API has no video channel; `search_context_size` is unsupported and returns 400; `kimi-k2.7-code` forces thinking and returns 400 if Thinking is off; the old `ANTHROPIC_API_KEY` must be deleted to avoid conflict; and protocol compatibility is not capability or pricing parity. For related reading, see the [Gemini 3.8 Flash security hotspot](/en/posts/gemini-3-8-flash-cyber-hotspot), the [DeepSeek open-source harness](/en/posts/deepseek-harness-dsh-opensource), and the [CodeArena coding review](/en/posts/codearena-coding-review).

Related