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.
What You’ll Need
Section titled “What You’ll Need”- LiteLLM
- OpenClaw
Quick Start
Section titled “Quick Start”You can get this running in about five minutes using either the onboarding command or a manual setup.
Via onboarding
Section titled “Via onboarding”openclaw onboard --auth-choice litellm-api-keyManual setup
Section titled “Manual setup”- Start the LiteLLM Proxy:
pip install 'litellm[proxy]'litellm --model claude-opus-4-6- Point OpenClaw to LiteLLM:
export LITELLM_API_KEY="your-litellm-key"
openclawOpenClaw now routes all requests through LiteLLM.
Configuration
Section titled “Configuration”You can configure the connection using environment variables or a configuration file.
Environment variables
Section titled “Environment variables”export LITELLM_API_KEY="sk-litellm-key"Config file
Section titled “Config file”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" }, }, },}Virtual keys
Section titled “Virtual keys”I recommend creating a dedicated key for OpenClaw to set specific spend limits:
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.
Model routing
Section titled “Model routing”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_KEYOpenClaw will continue requesting claude-opus-4-6 while LiteLLM manages the actual provider connection.
Viewing usage
Section titled “Viewing usage”You can check your spend logs or key information directly through the LiteLLM API:
# Key infocurl "http://localhost:4000/key/info" \ -H "Authorization: Bearer sk-litellm-key"
# Spend logscurl "http://localhost:4000/spend/logs" \ -H "Authorization: Bearer $LITELLM_MASTER_KEY"Troubleshooting
Section titled “Troubleshooting”If you have trouble connecting, check these two points from the documentation:
- Default Port: LiteLLM runs on
http://localhost:4000by default. Ensure yourbaseUrlin the config matches where your proxy is running. - Endpoint Compatibility: OpenClaw connects using the OpenAI-compatible
/v1/chat/completionsendpoint. Ensure your LiteLLM proxy is configured to accept these requests.
If you need more help with your specific environment, try the AI Setup Assistant.
What’s Next
Section titled “What’s Next”OpenClaw Expert
Still stuck?
If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.