How to Use Claude Code with Kimi Code on Windows: A Complete Setup Guide (Fix 401 & 400 Errors)
If you’ve tried connecting Kimi Code to Claude Code on Windows and kept hitting 401 Invalid Authentication or 400 Invalid Request, you’re not alone. Most setup failures come down to three specific mistakes — wrong Base URL, wrong model name, and API keys pulled from the wrong platform.
This guide walks you through every step, explains why each error happens, and gets you from a broken config to a fully working AI coding environment.
What Is Kimi Code?
Kimi Code is a code-focused AI service built by Moonshot AI, the company behind the Kimi large language model. The core model is called kimi-for-coding, built on the Kimi K2 architecture and optimized specifically for software development tasks.
Unlike general-purpose chatbots, Kimi Code is designed to:
-
Read and understand entire codebases -
Write, debug, and refactor code -
Execute terminal commands -
Integrate with development tools like VS Code, Roo Code, and Claude Code
Kimi Code exposes an OpenAI-compatible API, which means you can use Claude Code — Anthropic’s CLI coding agent — as the frontend, while routing all requests through Kimi’s model instead of Claude’s.
Why Your Configuration Is Probably Failing
Most setup errors trace back to one of three root causes. Understanding them makes the fix obvious.
Mistake 1: Wrong Base URL
The most common mistake. Many tutorials and blog posts list the Moonshot API endpoint as:
https://api.moonshot.cn/v1
That address is for Moonshot’s general-purpose API — not Kimi Code. The Kimi Code service runs on a completely separate endpoint:
https://api.kimi.com/coding/v1
These two endpoints serve different backends and use different account systems. Sending a Kimi Code key to the Moonshot endpoint — or vice versa — will always result in a 401 error.
Here’s how the URLs map to their respective use cases:
| Use Case | Base URL |
|---|---|
| Moonshot General API | https://api.moonshot.cn/v1 |
| Kimi Code API | https://api.kimi.com/coding/v1 |
Claude Code (ANTHROPIC_BASE_URL) |
https://api.kimi.com/coding/ |
Note: Claude Code’s environment variable omits the trailing
/v1. Roo Code and other tools include it. Use the correct format for each tool.
Mistake 2: Wrong Model Name
Common incorrect model names you’ll find floating around:
kimi-k2.5
kimi-k2
moonshot-v1-8k
kimi-k2-0905-preview
The correct model ID for Kimi Code is simply:
kimi-for-coding
Entering a wrong model name doesn’t always produce a “model not found” error. Instead, it often triggers an authentication or request error — which sends you in the wrong debugging direction.
Mistake 3: Using the Wrong API Key
Kimi Code API keys and Moonshot platform API keys are not interchangeable. They come from different places and authenticate against different systems.
| Key Type | Where to Generate |
|---|---|
| Moonshot General API Key | platform.moonshot.cn |
| Kimi Code API Key | kimi.com/code (membership page) |
Using a Moonshot key on a Kimi Code endpoint returns 401. Using a Kimi Code key on the Moonshot endpoint also returns 401. The services don’t share authentication.
To verify your key is valid, run this in CMD (one line):
curl https://api.kimi.com/coding/v1/models -H "Authorization: Bearer your-api-key-here"
If it returns a list of models, your key is valid. If it returns 401, go regenerate the key from your Kimi Code membership page.
The Correct Configuration Parameters
Once you understand the three failure points, the right configuration is straightforward.
For Claude Code (Environment Variables)
ANTHROPIC_BASE_URL = https://api.kimi.com/coding/
ANTHROPIC_API_KEY = sk-kimi-your-key-here
ENABLE_TOOL_SEARCH = FALSE
For Roo Code (VS Code Extension)
Open Roo Code settings and fill in the Provider section:
| Field | Value |
|---|---|
| Provider Type | OpenAI Compatible |
| Entrypoint | https://api.kimi.com/coding/v1 |
| API Key | Your Kimi Code key |
| Model | kimi-for-coding |
| Use legacy OpenAI API format | ✅ Enabled |
| Enable streaming | ✅ Enabled |
| Include max output tokens | ✅ Enabled |
| Enable Reasoning Effort | Medium |
| Max Output Tokens | 32768 |
| Context Window Size | 262144 |
Why You Need ENABLE_TOOL_SEARCH=FALSE
After fixing the authentication errors, many users run into a second problem. The pattern looks like this:
-
First message (“hello”) → works fine -
Second message (“list files in current directory”) → 400 Invalid Request -
Third message (“hello again”) → also 400 Invalid Request
This behavior is caused by Claude Code’s internal tool_search mechanism.
Before Claude Code executes any action — file operations, terminal commands, anything — it sends a preliminary tool_search call to discover what tools are available in the current environment. This is a Claude Code-specific protocol that Kimi’s API does not currently support. When tool_search hits Kimi’s endpoint, it returns a 400 error.
The first “hello” succeeds because pure conversational messages don’t trigger any tool calls. The moment you ask for something actionable, tool_search fires and fails.
By the third message, the conversation history contains the failed tool call records from the previous turns. This makes the request payload more complex, and it continues to fail even for simple messages.
Setting ENABLE_TOOL_SEARCH=FALSE tells Claude Code to skip the tool discovery step entirely and proceed directly to execution. Kimi’s API handles the rest normally.
This is a temporary compatibility workaround. Moonshot’s official documentation acknowledges the issue and states that a proper compatibility fix is in development.
Step-by-Step Installation on Windows
Step 1: Install Git and Node.js
Open Windows Terminal (PowerShell) and run:
winget install --id Git.Git -e --source winget
winget install OpenJS.NodeJS
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
After these commands finish, close the terminal and open a new one. This reloads the PATH so Node.js and Git are recognized.
Step 2: Install Claude Code
npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com
Step 3: Initialize the Configuration File
node --eval "
const homeDir = os.homedir();
const filePath = path.join(homeDir, '.claude.json');
if (fs.existsSync(filePath)) {
const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
fs.writeFileSync(filePath, JSON.stringify({ ...content, hasCompletedOnboarding: true }, null, 2), 'utf-8');
} else {
fs.writeFileSync(filePath, JSON.stringify({ hasCompletedOnboarding: true }), 'utf-8');
}"
Step 4: Set Environment Variables
There are three ways to do this. The permanent methods are recommended so you don’t have to reconfigure every session.
Option A: Windows GUI (Easiest)
-
Press Win + S, search for “environment variables”, and click Edit the system environment variables -
Click the Environment Variables button in the bottom right -
Under User variables, click New -
Add these three variables one at a time:
| Variable Name | Value |
|---|---|
ANTHROPIC_BASE_URL |
https://api.kimi.com/coding/ |
ANTHROPIC_API_KEY |
sk-kimi-your-key-here |
ENABLE_TOOL_SEARCH |
FALSE |
-
Click OK on each dialog, then OK to close the Environment Variables window -
Restart your terminal — changes take effect in new windows only
Option B: PowerShell Command (Permanent)
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://api.kimi.com/coding/", "User")
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-kimi-your-key-here", "User")
[System.Environment]::SetEnvironmentVariable("ENABLE_TOOL_SEARCH", "FALSE", "User")
Close and reopen your terminal after running these. The variables persist across reboots.
Option C: Temporary Session (Testing Only)
If you just want to test without touching system settings, run all four lines together in a single PowerShell session:
$env:ANTHROPIC_BASE_URL="https://api.kimi.com/coding/";
$env:ANTHROPIC_API_KEY="sk-kimi-your-key-here";
$env:ENABLE_TOOL_SEARCH="FALSE";
claude
These variables disappear when you close the terminal window.
Step 5: Verify the Setup
After starting Claude Code, type /status in the input prompt. This displays the current model and connection state. Confirm the model shows correctly.
You can also verify environment variables before launching:
echo $env:ENABLE_TOOL_SEARCH
# Expected output: FALSE
echo $env:ANTHROPIC_BASE_URL
# Expected output: https://api.kimi.com/coding/
Error Reference Table
| Error Message | Likely Cause | Fix |
|---|---|---|
401 Invalid Authentication |
Wrong Base URL or wrong API key source | Use https://api.kimi.com/coding/ as Base URL; generate key from Kimi Code membership page |
400 Invalid Request (on tool use) |
tool_search compatibility issue |
Set ENABLE_TOOL_SEARCH=FALSE |
| First message works, subsequent messages fail with 400 | Same as above — tool_search triggered | Set ENABLE_TOOL_SEARCH=FALSE |
| Model unavailable / not found | Wrong model ID | Change to kimi-for-coding |
Frequently Asked Questions
Where do I get a Kimi Code API key?
Go to kimi.com/code and open the membership or API key management page. Do not use keys generated from platform.moonshot.cn — those are for Moonshot’s general API and won’t authenticate against Kimi Code’s endpoint.
What should I do if my API key gets leaked?
Immediately go to the Kimi Code API key management page and revoke the compromised key. Generate a new one and update your environment variables. A leaked key can be exploited by others to consume your quota, so act quickly.
Does setting ENABLE_TOOL_SEARCH=FALSE break any features?
Not meaningfully, for current Kimi Code usage. This is a targeted workaround for a specific compatibility gap, and core coding functionality works normally with it enabled. Moonshot has acknowledged the issue and is working on a native fix.
Does Roo Code also need ENABLE_TOOL_SEARCH=FALSE?
No. ENABLE_TOOL_SEARCH is a Claude Code CLI environment variable and has no effect on Roo Code, which uses its own configuration system and plugin architecture.
How do I switch models inside Claude Code?
Type /model in the Claude Code input prompt to view available models and switch between them.
Why does CMD curl syntax look different from Linux?
On Windows CMD, you must write the entire curl command on one line — the backslash \ line continuation used in Linux/macOS doesn’t work. In PowerShell, the syntax uses -Uri and -Headers parameters instead of positional arguments. When in doubt, use the CMD single-line format for testing.
Summary: Four Things to Get Right
Everything above reduces to four checkpoints. If you verify all four, you’ll have a working setup:
-
Base URL must be https://api.kimi.com/coding/for Claude Code, orhttps://api.kimi.com/coding/v1for Roo Code — notapi.moonshot.cn -
Model name must be kimi-for-coding— notkimi-k2.5,kimi-k2, or any other variant -
API key must come from the Kimi Code membership page at kimi.com/code— not from Moonshot’s developer platform -
Claude Code requires ENABLE_TOOL_SEARCH=FALSE— without it, any non-conversational request will return a 400 error
Get these four right and you’ll have a fully functional AI coding assistant running locally on Windows, powered by Kimi’s model through the Claude Code interface.

