Context
Kimi (by Moonshot AI) offers a free "Kimi for Coding" tier with a dedicated API endpoint. This was the primary AI provider for PocketClaw due to its generous free tier and 262K context window. However, three issues blocked integration:
- The endpoint is
api.kimi.com/coding/v1, NOTapi.moonshot.cn/v1(the general Moonshot API) - Kimi Coding checks the
User-Agentheader and returns 403 for unrecognized clients. Only known coding tools (Claude Code, Roo Code, Cursor, etc.) are allowed - Kimi's K2.5 model returns
reasoning_contentfields in responses, which confuses OpenClaw's OpenAI-compatible response parser
Implementation
Configure the provider in openclaw.json:
{
"kimi-coding": {
"baseUrl": "https://api.kimi.com/coding/v1",
"apiKey": "sk-kimi-xxx",
"api": "openai-completions",
"headers": {
"User-Agent": "claude-code/1.0"
},
"models": [{
"id": "kimi-for-coding",
"name": "Kimi For Coding (K2.5)",
"contextWindow": 262144,
"maxTokens": 8192,
"reasoning": false
}]
}
}Key configuration points:
# 1. Correct endpoint (NOT moonshot.cn):
# WRONG: https://api.moonshot.cn/v1
# RIGHT: https://api.kimi.com/coding/v1
# 2. User-Agent must be a recognized coding tool:
# "claude-code/1.0" is allowed
# Default User-Agent ("node-fetch" etc.) returns 403
# 3. reasoning: false prevents K2.5 from returning
# reasoning_content fields that break the parserVerification
# Test API key validity:
curl -s -H "Authorization: Bearer sk-kimi-xxx" \
-H "User-Agent: claude-code/1.0" \
https://api.kimi.com/coding/v1/models | head -5
# Expected: JSON list of available models
# Test without correct User-Agent (should fail):
curl -s -H "Authorization: Bearer sk-kimi-xxx" \
https://api.kimi.com/coding/v1/models
# Expected: 403 Forbidden
# Test from gateway dashboard:
# Navigate to /keys -> click Test next to MOONSHOT_API_KEY
# Expected: green "OK" indicatorGotchas
- The Kimi Coding API key format is
sk-kimi-*, different from Moonshot'ssk-*format reasoning: falseis critical. With reasoning enabled, responses includereasoning_contentalongsidecontent, and OpenClaw's parser expects onlycontent- The 262K context window is the largest free option available, making Kimi ideal for PocketClaw's use case
- Rate limits on the free tier are generous but not unlimited. Monitor for 429 responses
- Kimi periodically updates their User-Agent allowlist. If access breaks, check what agents are currently recognized
Result
| Metric | Before | After |
|---|---|---|
| AI provider | None (setup blocked) | Kimi K2.5 free tier |
| Context window | N/A | 262K tokens |
| Monthly cost | N/A | $0 |
| Response parsing | Broken (reasoning_content) | Clean |