Skip to content

How to Connect Claude Code to Kimi K2.5 and GLM-4.7: Complete Setup Guide

Claude Code kept timing out on me.

I’d type a simple request, wait 30 seconds, and then get slapped with an API timeout error. Living in China, this was my daily reality with the official Claude API. Account bans, slow connections, and that constant anxiety of whether my subscription would survive the week.

Then I discovered Kimi K2.5 and GLM-4.7 - Chinese AI models that work with Claude Code through a simple configuration change.

The Problem with Official Claude API in China

If you’re a developer in China using Claude Code, you probably recognize this pattern:

Error output
Error: API request timed out after 30000ms

Or worse:

Account error
Error: Your account has been suspended

The official Claude API has several issues for Chinese users:

  • High latency: Requests often take 10-30 seconds just to connect
  • Account instability: Random bans and suspensions
  • Cost: At $20/month for Claude Pro, it adds up
  • Payment barriers: Getting a subscription requires jumping through hoops

I needed an alternative that:

  1. Works reliably in China
  2. Costs less
  3. Still integrates with Claude Code

The Solution: Anthropic-Compatible Endpoints

Both Kimi K2.5 and GLM-4.7 offer Anthropic-compatible API endpoints. This means you can point Claude Code to their servers instead of Anthropic’s, and everything just works.

API routing diagram
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Claude Code │────▶│ Anthropic API │────▶│ Claude Model │
│ (Your PC) │ │ Compatible API │ │ (Kimi/GLM) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │
│ Three environment variables │
└────────────────────────────────────────────────┘

The magic happens through three environment variables:

VariablePurpose
ANTHROPIC_BASE_URLAPI endpoint URL
ANTHROPIC_AUTH_TOKENYour API key
ANTHROPIC_MODELModel identifier

Setting Up GLM-4.7

GLM-4.7 from Zhipu AI is a strong all-rounder. Here’s how to set it up:

Step 1: Get Your API Key

Head to bigmodel.cn, register, and grab your API key from the console.

Step 2: Configure Environment Variables

GLM-4.7 configuration
export ANTHROPIC_BASE_URL=https://open.bigmodel.cn/api/anthropic
export ANTHROPIC_AUTH_TOKEN=your_api_key_here
export ANTHROPIC_MODEL=GLM-4.7

Step 3: Test It

Start Claude Code
claude

If configured correctly, Claude Code will connect to GLM-4.7 instead of Anthropic’s servers.

Setting Up Kimi K2.5

Kimi K2.5 from Moonshot AI has been dominating OpenRouter’s weekly leaderboard, often sitting at #1. It’s particularly good at coding tasks.

Step 1: Get Your API Key

Visit moonshot.cn and create an account.

Step 2: Configure Environment Variables

Kimi K2.5 configuration
export ANTHROPIC_BASE_URL=https://api.moonshot.cn/anthropic
export ANTHROPIC_AUTH_TOKEN=your_api_key_here
export ANTHROPIC_MODEL=kimi-k2.5

Step 3: Restart Claude Code

Start Claude Code
claude

Quick Model Switching with claude-code-router

Manually setting environment variables gets tedious. I built claude-code-router (ccr) to make switching instant:

Using claude-code-router
# Install
pip install claude-code-router
# Switch models
ccr use kimi # Switch to Kimi K2.5
ccr use glm # Switch to GLM-4.7
ccr use claude # Back to official Claude

Behind the scenes, it just updates those three environment variables for you.

Performance Comparison

After using both for a month, here’s my honest assessment:

AspectClaude OfficialKimi K2.5GLM-4.7
Connection SpeedSlow/Unstable in ChinaFastFast
Code QualityExcellentVery GoodGood
Chinese UnderstandingGoodExcellentExcellent
Cost (per 1M tokens)~$3~$0.5~$0.3
Availability95% (with VPN)99.9%99.9%

Kimi K2.5 feels closer to Claude’s reasoning capabilities, while GLM-4.7 is more cost-effective for simpler tasks.

Why This Works

Claude Code uses the Anthropic SDK internally, which respects these environment variables:

How variables work
ANTHROPIC_BASE_URL ──▶ Overrides api.anthropic.com
ANTHROPIC_AUTH_TOKEN ──▶ Replaces the API key
ANTHROPIC_MODEL ──▶ Specifies which model to use

Both Kimi and GLM implemented Anthropic’s API specification, so Claude Code can’t tell the difference. It’s like putting a different engine in your car - the steering wheel still works the same.

Common Pitfalls

Wrong Model Name

Model name correction
# Wrong
export ANTHROPIC_MODEL=glm-4-7 # Will fail
# Correct
export ANTHROPIC_MODEL=GLM-4.7

Always check the exact model identifier from the provider’s documentation.

Forgetting to Restart

Environment variables only apply to new sessions. If Claude Code is already running, restart it:

Restart Claude Code
# Exit current session, then
claude

Missing API Key

Check configuration
# Check your configuration
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKEN
echo $ANTHROPIC_MODEL

If any are empty, set them in your shell profile:

Add to shell profile
# Add to ~/.zshrc or ~/.bashrc
export ANTHROPIC_BASE_URL=https://api.moonshot.cn/anthropic
export ANTHROPIC_AUTH_TOKEN=your_api_key_here
export ANTHROPIC_MODEL=kimi-k2.5

Making It Permanent

Add the configuration to your shell profile:

Permanent configuration in ~/.zshrc
# ~/.zshrc or ~/.bashrc
# Claude Code with Kimi K2.5
export ANTHROPIC_BASE_URL="https://api.moonshot.cn/anthropic"
export ANTHROPIC_AUTH_TOKEN="your_api_key_here"
export ANTHROPIC_MODEL="kimi-k2.5"

Then reload:

Reload shell profile
source ~/.zshrc # or ~/.bashrc

When to Use Which Model

I use different models for different tasks:

  • Kimi K2.5: Complex reasoning, architecture decisions, debugging tricky issues
  • GLM-4.7: Quick questions, simple refactors, Chinese language tasks
  • Claude Official: When I need Claude’s specific strengths (rare, but happens)

OpenRouter Alternative

If you want access to multiple models through one API, OpenRouter works too:

OpenRouter configuration
export ANTHROPIC_BASE_URL=https://openrouter.ai/api/v1
export ANTHROPIC_AUTH_TOKEN=your_openrouter_key
export ANTHROPIC_MODEL=anthropic/claude-3.5-sonnet

The advantage is you can switch models by just changing ANTHROPIC_MODEL:

Switch models via OpenRouter
export ANTHROPIC_MODEL=google/gemini-2.0-flash # Switch to Gemini
export ANTHROPIC_MODEL=openai/gpt-4o # Switch to GPT-4

Summary

In this post, I showed how to connect Claude Code to Kimi K2.5 and GLM-4.7 using three environment variables. The key point is that these models offer comparable performance at a fraction of the cost, with better reliability for users in China.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments