To connect Kimi K2 (Moonshot AI) with Claude Code, you can use the Anthropic-compatible API endpoint provided by Moonshot AI. Here’s a concise step-by-step guide based on the latest tutorials:
Go to Moonshot AI Platform and sign up.
Navigate to API Keys and generate a new key (starts with sk-). Save it securely.
Open your terminal and run:
export ANTHROPIC_AUTH_TOKEN=sk-YOURKEY
export ANTHROPIC_BASE_URL=https://api.moonshot.ai/anthropic
(On Windows, use set instead of export).
Start Claude Code normally. It will now use Kimi K2 as the backend model while retaining the Claude interface.
Claude Code Router: Install @musistudio/claude-code-router and configure it to route requests to Groq or OpenRouter with Kimi K2 for faster/cheaper inference.
Novita AI: Use Novita’s API endpoint (https://api.novita.ai/v1) for cost-efficient Kimi K2 access, following similar environment variable setup.
Cost: Up to 85% cheaper than Claude Sonnet.
Performance: Kimi K2 excels in agentic coding (71.6% on SWE-bench with retries).
Flexibility: Open-source and interoperable via API compatibility.
Start coding with Kimi K2 in Claude Code today!