How I connected 300+ AI Models to OpenClaw with Kilo Code API Key
A step-by-step guide to setting up Kilo Code API with OpenClaw — with the sync script that makes it all work.
A few weeks ago, I was juggling three different API keys and auths just to test various AI models. GPT-5.2, sonnet-4.5, Gemini... you get the picture. Each had its own pricing, rate limits, and authentication quirks. It was a mess and quite pricey.
Then I stumbled upon a tweet by Kilo Code mentioning GLM-5 and MiniMax 2.5 available for free. One API key, 300+ models, unified interface. Sounds perfect, right?
Well, almost. Getting it working with OpenClaw wasn't as straightforward as the docs suggested. I ran into weird context window bugs, reasoning parameter conflicts, and authentication errors that took hours to debug.
This guide is everything I wish I knew before starting. Let's save you that headache.
Why Kilo Code API?
Managing five different AI provider keys is annoying. Kilo solves that. One API key, 300+ models, all through a single OpenAI-compatible endpoint:
https://api.kilo.ai/api/gateway
Supports GPT, Claude, Gemini, Kimi, GLM, and hundreds more. Often cheaper than going direct. Has a generous free tier too.
Step 1: Get Your Kilo API Key
- Sign up at kilo.ai
- Go to your dashboard → API Keys
- Generate a new key and copy it
Step 2: Connect Kilo to OpenClaw
Run the onboarding wizard:
openclaw onboard
When prompted, select:
- AI Provider → Custom Provider
- Base URL →
https://api.kilo.ai/api/gateway - API Type → OpenAI-compatible
- API Key → Your Kilo key from Step 1
- Model ID → e.g.
anthropic/claude-sonnet-4.5 - API Alias →
kilo-api
⚠️ The alias
kilo-apiis important — the sync script in Step 3 references this exact name in the config. Use it as-is.
At this point one model works. But to unlock all 300+, you need the next step.
Step 3: Sync All Models
The onboarding only registers one model. This script syncs all 300+ and fixes three bugs you would hit otherwise:
- Context window stuck at 4096 — some models have 128K–256K windows but OpenClaw defaults them down
- Reasoning parameter conflict — 7 models have mutually exclusive reasoning params, causing a 400 error
- Model not allowed — models must be in both provider list AND allowlist; onboarding only does one
Save as ~/sync-kilo-models.sh
#!/bin/bash
# sync-kilo-models.sh - Sync model metadata from Kilo API to OpenClaw config
# Models are added directly under the kilo-api provider (no prefix)
CONFIG_FILE="/home/antarikshc/.openclaw/openclaw.json"
KILO_API_KEY=$(jq -r '.models.providers."kilo-api".apiKey' "$CONFIG_FILE")
echo "Fetching models from Kilo API..."
MODELS_JSON=$(curl -s "https://api.kilo.ai/api/gateway/models" \
-H "Authorization: Bearer $KILO_API_KEY")
# Check if we got valid data
if [ -z "$MODELS_JSON" ] || [ "$MODELS_JSON" = "null" ]; then
echo "❌ Failed to fetch models from Kilo API"
exit 1
fi
echo "Building OpenClaw model config..."
# Create the models array from Kilo data
# Handle reasoning parameter:
# - If model has BOTH "reasoning" AND "reasoning_effort" -> set reasoning: false (they're mutually exclusive)
# - If model has ONLY "reasoning" -> set reasoning: true
# - Otherwise -> set reasoning: false
MODELS_ARRAY=$(echo "$MODELS_JSON" | jq '[.data[] |
{
"id": .id,
"name": (.name // .id),
"reasoning": (
if (.supported_parameters // [] | contains(["reasoning"])) and
(.supported_parameters // [] | contains(["reasoning_effort"])) then
false # Both present - mutually exclusive, let user configure manually
elif (.supported_parameters // [] | contains(["reasoning"])) then
true # Only reasoning supported
else
false # No reasoning support
end
),
"input": ["text"],
"cost": {
"input": ((.pricing.prompt // "0") | tonumber * 1000000),
"output": ((.pricing.completion // "0") | tonumber * 1000000),
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": (.context_length // .top_provider.context_length // 128000),
"maxTokens": (.top_provider.max_completion_tokens // 4096)
}
]')
echo "Found $(echo "$MODELS_ARRAY" | jq 'length') models"
# Count reasoning models
REASONING_COUNT=$(echo "$MODELS_ARRAY" | jq '[.[] | select(.reasoning == true)] | length')
echo " - $REASONING_COUNT models with reasoning (exclusive)"
# Count models with both reasoning + reasoning_effort (set to false)
BOTH_COUNT=$(echo "$MODELS_JSON" | jq '[.data[] | select(
(.supported_parameters // [] | contains(["reasoning"])) and
(.supported_parameters // [] | contains(["reasoning_effort"]))
)] | length')
echo " - $BOTH_COUNT models have BOTH reasoning + reasoning_effort (set to false to avoid conflict)"
# Create the agents.defaults.models entries (for allowlist)
MODELS_ALLOWLIST=$(echo "$MODELS_JSON" | jq '[
.data[] |
{
"key": ("kilo-api/" + .id),
"value": {"alias": (.id | split("/") | last | gsub(":free"; "") | gsub(":exacto"; ""))}
}
] | from_entries')
echo "Updating OpenClaw config..."
# Update both the provider models AND the agents.defaults.models
jq --argjson models "$MODELS_ARRAY" --argjson allowlist "$MODELS_ALLOWLIST" '
.models.providers."kilo-api".models = $models |
.agents.defaults.models = $allowlist
' "$CONFIG_FILE" > "${CONFIG_FILE}.tmp" && mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE"
echo "✅ Config updated!"
echo ""
echo "Sample models synced:"
echo "$MODELS_ARRAY" | jq -r '.[] | " - \(.id): contextWindow=\(.contextWindow), reasoning=\(.reasoning)"' | head -10
echo " ... and $(echo "$MODELS_ARRAY" | jq 'length - 10') more"
echo ""
echo "Allowlist entries: $(echo "$MODELS_ALLOWLIST" | jq 'length')"
Run It
chmod +x ~/sync-kilo-models.sh
~/sync-kilo-models.sh
✅ Expected: Found 319 models ... Done! 319 models synced.
Step 4: Restart and Verify
openclaw gateway restart
Then test a couple of models:
/model kilo-api/moonshotai/kimi-k2.5
Hey, working?
/model kilo-api/anthropic/claude-opus-4.6
How about you?
If both respond, you're done! 🎉
You will see all the Kilo models with a kilo-api/ prefix.
Free Models Worth Knowing
z-ai/glm-5:free— 202K context, general + reasoningminimax/minimax-m2.5:free— 204K context, coding & productivitystepfun/step-3.5-flash:free— 256K context, fast responsesarcee-ai/trinity-large-preview:free— 131K context, creative writing
Quick Reference
# Switch model
/model kilo-api/moonshotai/kimi-k2.5
# Check current model
/status
# Re-sync models (run monthly or after Kilo adds new ones)
~/sync-kilo-models.sh && openclaw gateway restart


