Skip to content

How to Route OpenClaw through LiteLLM

I’ve spent a lot of time manually switching between different model providers and trying to figure out where my API budget actually went. It usually involves hunting through multiple dashboards and updating configuration files every time I want to test a new model.

LiteLLM is an open-source LLM gateway that gives you a unified API for over 100 model providers. By routing OpenClaw through LiteLLM, you get centralized cost tracking and the ability to switch backends without touching your OpenClaw configuration.

  • LiteLLM
  • OpenClaw

You can get this running in about five minutes using either the onboarding command or a manual setup.

Terminal window
openclaw onboard --auth-choice litellm-api-key
  1. Start the LiteLLM Proxy:
Terminal window
pip install 'litellm[proxy]'
litellm --model claude-opus-4-6
  1. Point OpenClaw to LiteLLM:
Terminal window
export LITELLM_API_KEY="your-litellm-key"
openclaw

OpenClaw now routes all requests through LiteLLM.

You can configure the connection using environment variables or a configuration file.

Terminal window
export LITELLM_API_KEY="sk-litellm-key"

Use this JSON5 structure to define your LiteLLM provider and models:

{
models: {
providers: {
litellm: {
baseUrl: "http://localhost:4000",
apiKey: "${LITELLM_API_KEY}",
api: "openai-completions",
models: [
{
id: "claude-opus-4-6",
name: "Claude Opus 4.6",
reasoning: true,
input: ["text", "image"],
contextWindow: 200000,
maxTokens: 64000,
},
{
id: "gpt-4o",
name: "GPT-4o",
reasoning: false,
input: ["text", "image"],
contextWindow: 128000,
maxTokens: 8192,
},
],
},
},
},
agents: {
defaults: {
model: { primary: "litellm/claude-opus-4-6" },
},
},
}

I recommend creating a dedicated key for OpenClaw to set specific spend limits:

Terminal window
curl -X POST "http://localhost:4000/key/generate" \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{
"key_alias": "openclaw",
"max_budget": 50.00,
"budget_duration": "monthly"
}'

Use the key generated from this request as your LITELLM_API_KEY.

LiteLLM handles the routing to different backends so you don’t have to. You can define this in your LiteLLM config.yaml:

model_list:
- model_name: claude-opus-4-6
litellm_params:
model: claude-opus-4-6
api_key: os.environ/ANTHROPIC_API_KEY
- model_name: gpt-4o
litellm_params:
model: gpt-4o
api_key: os.environ/OPENAI_API_KEY

OpenClaw will continue requesting claude-opus-4-6 while LiteLLM manages the actual provider connection.

You can check your spend logs or key information directly through the LiteLLM API:

Terminal window
# Key info
curl "http://localhost:4000/key/info" \
-H "Authorization: Bearer sk-litellm-key"
# Spend logs
curl "http://localhost:4000/spend/logs" \
-H "Authorization: Bearer $LITELLM_MASTER_KEY"

If you have trouble connecting, check these two points from the documentation:

  • Default Port: LiteLLM runs on http://localhost:4000 by default. Ensure your baseUrl in the config matches where your proxy is running.
  • Endpoint Compatibility: OpenClaw connects using the OpenAI-compatible /v1/chat/completions endpoint. Ensure your LiteLLM proxy is configured to accept these requests.

If you need more help with your specific environment, try the AI Setup Assistant.

OpenClaw

OpenClaw Expert

Still stuck?

If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.