You can connect Kimi K3 to Codex or Claude Code through a Kimi membership or a pay-as-you-go API account. Both coding agents keep their local file and command features while Kimi handles model requests.
The setup depends on where you create the API key. Choose one access method first, then copy the complete configuration for that method.
Choose How You Want to Access Kimi K3
Kimi Code is the coding service included with a Kimi membership. Its requests use membership quota, and its API keys come from the Kimi Code Console. Kimi Open Platform bills API usage separately and issues keys through the Open Platform console.
| Access method | Account and usage | Key source |
|---|---|---|
| Kimi Code membership | Kimi membership quota, with weekly and rolling rate limits | Kimi Code Console |
| Kimi Open Platform | Pay-as-you-go API billing and platform rate limits | Kimi Open Platform API Keys |
What You Need
Install the coding agent you plan to use, create the key for your chosen route, and open a terminal in a project you can safely inspect. Keep API keys out of repositories, screenshots, and shared configuration files.
Configure Kimi K3 in Codex
Codex stores personal settings in ~/.codex on macOS and Linux or %USERPROFILE%\.codex on Windows. Back up an existing configuration, preserve unrelated settings, and keep each top-level key or provider table only once.
Codex with a Kimi Code membership
Kimi Code requires model & provider settings. A Moderato or higher membership can use
k3-256k. Allegretto and higher can usek3with up to a 1M context window. This example uses the current recommendation for routine coding work,k3-256k.
Create ~/.codex/models.json, or %USERPROFILE%\.codex\models.json on Windows, with both K3 choices.
{
"models": [
{
"slug": "k3",
"display_name": "Kimi K3",
"description": "Kimi K3, 1M context",
"default_reasoning_level": "high",
"supported_reasoning_levels": [
{ "effort": "low", "description": "Light reasoning" },
{ "effort": "high", "description": "Enhanced reasoning" },
{ "effort": "max", "description": "Deep reasoning" }
],
"shell_type": "shell_command",
"visibility": "list",
"supported_in_api": true,
"priority": 0,
"base_instructions": "",
"supports_reasoning_summaries": true,
"default_reasoning_summary": "none",
"support_verbosity": false,
"truncation_policy": { "mode": "bytes", "limit": 10000 },
"context_window": 1048576,
"max_context_window": 1048576,
"effective_context_window_percent": 95,
"supports_parallel_tool_calls": true,
"experimental_supported_tools": [],
"input_modalities": ["text", "image"]
},
{
"slug": "k3-256k",
"display_name": "Kimi K3 256K",
"description": "Kimi K3 256K context",
"default_reasoning_level": "high",
"supported_reasoning_levels": [
{ "effort": "low", "description": "Light reasoning" },
{ "effort": "high", "description": "Enhanced reasoning" },
{ "effort": "max", "description": "Deep reasoning" }
],
"shell_type": "shell_command",
"visibility": "list",
"supported_in_api": true,
"priority": 1,
"base_instructions": "",
"supports_reasoning_summaries": true,
"default_reasoning_summary": "none",
"support_verbosity": false,
"truncation_policy": { "mode": "bytes", "limit": 10000 },
"context_window": 262144,
"max_context_window": 262144,
"effective_context_window_percent": 95,
"supports_parallel_tool_calls": true,
"experimental_supported_tools": [],
"input_modalities": ["text", "image"]
}
]
}Add the Kimi Code provider settings
Open ~/.codex/config.toml, or %USERPROFILE%\.codex\config.toml on Windows. Add the provider table and update existing top-level model settings.
model = "k3-256k"
model_provider = "kimi"
web_search = "live"
model_catalog_json = "~/.codex/models.json"
[model_providers.kimi]
name = "Kimi"
base_url = "https://api.kimi.com/coding/v1"
env_key = "KIMI_API_KEY"
wire_api = "responses"
[desktop]
enabled-reasoning-efforts = ["low", "high", "max"]Set the Kimi Code key for the current session
Make the Kimi Code Console key available in the terminal that will start Codex.
echo "Paste your Kimi Code key and press Enter (input is hidden):"
read -s KIMI_API_KEY
export KIMI_API_KEYWindows PowerShell
$kimiSecret = Read-Host "Paste your Kimi Code key" -AsSecureString
$env:KIMI_API_KEY = [System.Net.NetworkCredential]::new('', $kimiSecret).Password
Remove-Variable kimiSecretCodex with the Kimi Open Platform API
This requires a funded Kimi Open Platform account and an Open Platform API key. It uses
kimi-k3, the Open Platform endpoint.
Open ~/.codex/config.toml, or %USERPROFILE%\.codex\config.toml on Windows. Update existing top-level model settings and add the provider table once while preserving unrelated options.
model = "kimi-k3"
model_provider = "kimi"
model_context_window = 1048576
[model_providers.kimi]
name = "Kimi"
base_url = "https://api.moonshot.ai/v1"
env_key = "KIMI_API_KEY"
wire_api = "responses"Set the Open Platform key for the current session
echo "Paste your Kimi Open Platform key and press Enter (input is hidden):"
read -s KIMI_API_KEY
export KIMI_API_KEYWindows PowerShell
$kimiSecret = Read-Host "Paste your Kimi Open Platform key" -AsSecureString
$env:KIMI_API_KEY = [System.Net.NetworkCredential]::new('', $kimiSecret).Password
Remove-Variable kimiSecretVerify Codex
Close any running Codex session. Start Codex from the terminal where you set the key, then send hello. The startup display should show your configured provider and model.
cd "/path/to/your/project"
codexConfigure Kimi K3 in Claude Code
Claude Code loads personal connection values from ~/.claude/settings.json, or %USERPROFILE%\.claude\settings.json on Windows. Its env object overrides variables with matching names from your terminal. Back up the file, preserve unrelated settings, and remove old Kimi endpoint, credential, or model entries before adding one complete route.
If Claude Code has never completed its first-run flow, Kimi’s setup requires Node.js for a one-time initialization. Run the following command before the first launch.
node --eval "
const fs = require('fs');
const path = require('path');
const os = require('os');
const filePath = path.join(os.homedir(), '.claude.json');
const current = fs.existsSync(filePath)
? JSON.parse(fs.readFileSync(filePath, 'utf-8'))
: {};
fs.writeFileSync(filePath, JSON.stringify({
...current,
penguinModeOrgEnabled: true,
hasCompletedOnboarding: true
}, null, 2), 'utf-8');"Claude Code with a Kimi Code membership
Use a key from the Kimi Code Console. The persistent setup below uses k3-256k and the matching 256K context values. The key is stored as plaintext in your personal settings file.
Do not commit that file or a backup to a repository.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.kimi.com/coding/",
"ANTHROPIC_API_KEY": "YOUR_KIMI_CODE_KEY",
"ANTHROPIC_MODEL": "k3-256k",
"ANTHROPIC_DEFAULT_FABLE_MODEL": "k3-256k",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "k3-256k",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "k3-256k",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "k3-256k",
"CLAUDE_CODE_SUBAGENT_MODEL": "k3-256k",
"CLAUDE_CODE_EFFORT_LEVEL": "high",
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "262144",
"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "262144"
}
}Claude Code with the Kimi Open Platform API
Use an Open Platform API key and replace the placeholder inside the quotation marks.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.moonshot.ai/anthropic",
"ANTHROPIC_AUTH_TOKEN": "YOUR_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"
}
}Verify Claude Code
Restart Claude Code after saving the file. Open your project, launch the coding agent, and enter /status. For Kimi Code, the base URL should be https://api.kimi.com/coding/ and the model should be k3-256k. For Open Platform, the base URL should be https://api.moonshot.ai/anthropic and the model should be kimi-k3[1m]. Send hello to complete an authenticated request.
cd "/path/to/your/project"
claudeWhich Kimi K3 Model Should You Use?
For a Kimi Code membership, start with k3-256k for routine questions, code completion, feature work, and small file changes. It matches k3 within a 256K context while using about half as much membership quota.
Choose k3 when a task needs a larger working context. Moderato includes K3 with a 256K limit. Allegretto and higher tiers can use up to 1M.
What the Kimi Configuration Settings Mean
Codex connects through the Responses API. wire_api = "responses" selects that format, base_url identifies the correct Kimi service, and env_key names the environment variable that holds the secret. The Kimi Code model catalog supplies model metadata that Codex does not bundle.
Claude Code sends Anthropic-compatible Messages API requests. Its model-role variables select models for the main conversation, task tiers, and subagents. Setting every role prevents a background task from falling back to a Claude model name that Kimi does not recognize.
An environment variable is a named value inherited by a program. The session-only key commands disappear when that terminal closes. For persistent Codex access, add the variable through your private shell profile or Windows user environment settings. Shell profiles and user environment variables store the value in plaintext.
Context settings tell each coding agent when the selected model is nearing its input limit. The 256K membership setup uses 262144.
Reasoning effort controls how much inference K3 applies before answering. Kimi Code supports low, high, and max, with high as the default. Changing effort or models during a long session can invalidate cached context.
Try Kimi K3 on Your First Coding Task
Inspect your repository
A greeting checks the connection. A read-only repository request confirms that the coding agent can inspect your actual project and return file-specific findings.
Inspect this repository without changing any files. Explain its main components, identify the application entry points, and find the existing build and test commands. Name the files that establish those commands. If you cannot determine something, say what is missing.Make one small change
After checking the result, try one limited edit. Replace the bracketed text with a real issue and a result you can verify.
Fix this issue: [describe one concrete problem].
The change is successful when: [describe the expected behavior].
Inspect the relevant code first and propose a short plan. Wait for my approval before editing. Keep the change limited to this issue. Run the relevant existing checks after the edit and report the files changed, what passed, and anything you could not verify.Troubleshooting
A 401 authentication error appears
Check that the key came from the service named in your selected route. A Kimi Code Console key must use an api.kimi.com/coding endpoint. An Open Platform key must use an api.moonshot.ai endpoint. In Claude Code, Kimi Code uses ANTHROPIC_API_KEY, while Open Platform uses ANTHROPIC_AUTH_TOKEN.
A Kimi Code 401 can also indicate that the membership tier does not include the requested model or context size. K3 requires Moderato or higher, and 1M K3 context requires Allegretto or higher.
The endpoint or model is rejected
Copy the complete block for one route. Check the URL suffix and exact model spelling. k3, k3-256k, and k3[1m] are Kimi Code values. kimi-k3 and kimi-k3[1m] are Open Platform values. Claude Code alone uses the bracketed 1M form.
Configuration changes do not take effect
Restart the coding agent and confirm that you edited the personal configuration file. Check for duplicate TOML keys, invalid JSON commas, launch flags, selected profiles, and old environment values. Claude Code’s env object overrides matching shell variables. Codex Desktop on macOS may need KIMI_API_KEY injected into the user session because apps opened from Finder do not inherit terminal variables.
launchctl setenv KIMI_API_KEY "YOUR_KEY_FROM_THE_SELECTED_ROUTE"Claude Code background or subagent tasks fail
Confirm that every model-role variable in the selected Claude Code block is present. A successful main conversation does not validate the model used for summarization or subagents. Remove model values left by an older provider configuration.
Context, quota, or rate-limit errors appear
For Kimi Code, confirm that the chosen context matches the membership tier. The quota refreshes every seven days from the subscription date, unused quota does not roll over, and a rolling five-hour rate window can limit requests before weekly quota is exhausted. All Kimi Code keys and logged-in devices share the membership quota.
For Open Platform, check the account balance and current rate limits. Reduce concurrent work or wait for the applicable limit to reset.
Related Resources
- Kimi Code setup for Codex
- Kimi Code setup for Claude Code
- Kimi Code models and membership access
- Kimi Open Platform setup for Codex
- Kimi Open Platform setup for Claude Code
- The Ultimate Claude Code Resource List: Agents, Skills, Plugins & More
- How to use DeepSeek V4 Pro or Flash in Codex and cut API costs










