logo
04

Configure LLM Providers

⏱️ 20 min

Configuring LLM Providers

You probably already picked a model during the onboarding wizard. But the real power of OpenClaw is this: you can configure multiple models and let it auto-select based on the task. I started out using GPT-5 for everything because I was lazy. January's bill came in — $47. I was stunned. Switched to smart routing, and February dropped to around $18. Roughly 60% savings.

Supported Providers

OpenClaw doesn't lock you into any specific model. That alone puts it ahead of many competitors. Here are the main options:

OpenAI (GPT-5, GPT-4o-mini) — strongest general capabilities, most mature ecosystem, moderate cost. Most people's first choice. Nothing wrong with it.

Anthropic (Claude Sonnet 4.6) — excels at long-text, code, and reasoning. For coding, I personally think Claude is better than GPT-5, though this opinion regularly gets flamed in the community.

Google (Gemini 3 Pro) — multimodal and long-context are its strengths, relatively cheaper. Stability though... it has its moments.

Local models (Ollama + Llama/Qwen) — completely offline, zero API cost, but needs decent hardware. No GPU? Don't bother.

Chinese models (Qwen, DeepSeek, Zhipu) — strong Chinese capabilities, extremely low cost, fast access from China. Someone in the community won't stop recommending DeepSeek, says the value-for-money is unbeatable.

Basic Configuration

Pick one of three approaches.

Via wizard (simplest):

openclaw config model

Manually edit the config file (note: JSON5 format, supports comments and trailing commas):

// ~/.openclaw/openclaw.json
{
	ai: {
		provider: 'openai',
		model: 'gpt-5',
		apiKey: 'sk-...'
	}
}

Or use environment variables:

export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GOOGLE_AI_API_KEY="..."

Provider Configuration Examples

OpenAI

{
	"ai": {
		"provider": "openai",
		"model": "gpt-5",
		"apiKey": "sk-..."
	}
}

Quick note: OpenAI supports an OAuth login flow — during openclaw onboard, a browser pops up for you to authorize with your OpenAI account. No manual copy-pasting of API Keys. The OAuth happens during the onboarding wizard, and the token auto-saves locally. Pretty convenient.

Anthropic (Claude)

{
	"ai": {
		"provider": "anthropic",
		"model": "claude-sonnet-4-6",
		"apiKey": "sk-ant-..."
	}
}

Anthropic recommends API Key over OAuth.

Google Gemini

{
	"ai": {
		"provider": "google",
		"model": "gemini-3-pro",
		"apiKey": "..."
	}
}

Local Models (Ollama)

Completely offline. Good for privacy-sensitive scenarios:

# Install Ollama first
curl -fsSL https://ollama.com/install.sh | sh

# Download model
ollama pull llama3.3

Configure OpenClaw to connect:

{
	"ai": {
		"provider": "ollama",
		"model": "llama3.3",
		"baseUrl": "http://localhost:11434"
	}
}

Real talk — local models still lag behind cloud models, especially on complex reasoning tasks. But if your data truly can't leave the premises, there's no other option. I naively thought a 7B model would perform like GPT-5. Gave up after a few days.

Chinese Models (Budget Option)

Qwen, DeepSeek and similar — costs are genuinely low, and Chinese language quality is solid:

{
	"ai": {
		"provider": "openai-compatible",
		"model": "qwen-plus",
		"apiKey": "...",
		"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1"
	}
}

Most Chinese models support OpenAI-compatible APIs. Set provider to openai-compatible and add the corresponding baseUrl. This compatibility mode saves a lot of hassle — Chinese providers proactively adopted OpenAI's API format.

/think Command: Controlling Reasoning Depth

Very useful feature that not many people know about. Send /think <level> in a conversation to control the AI's reasoning depth, directly affecting response quality and token consumption:

LevelDescriptionBest For
/think offNo deep reasoningSimple Q&A, casual chat
/think lowLight reasoningEveryday tasks
/think mediumModerate reasoningGeneral analysis
/think highDeep reasoningComplex logic, code architecture
/think xhighMaximum reasoningMath proofs, tricky debugging

You're trading money for quality. off and low save tokens but give shallow answers. high and xhigh cost more but can crack problems that low can't. I default to low and manually /think high when things get tough. This is per-session — doesn't affect global config.

Smart Routing: Pick Models by Task

This is the biggest money-saver, and personally what I think is one of OpenClaw's smartest designs.

{
	"ai": {
		"routing": {
			"default": "gpt-4o-mini",
			"complex": "gpt-5",
			"coding": "claude-sonnet-4-6",
			"chinese": "qwen-plus"
		}
	}
}

The idea is straightforward: everyday chat uses cheap GPT-4o-mini (roughly $0.15/1M tokens), complex reasoning triggers GPT-5, coding goes to Claude (it genuinely produces better code — can't argue with that), Chinese tasks go to Qwen.

After two months of actual usage, GPT-4o-mini handles most daily tasks just fine. The bill dropped from forty-something dollars to under twenty. Barely noticed a quality difference.

Failover Configuration

What if the primary model's API goes down? Configure failover for automatic switching:

{
	"ai": {
		"provider": "openai",
		"model": "gpt-5",
		"apiKey": "sk-...",
		"failover": [
			{
				"provider": "anthropic",
				"model": "claude-sonnet-4-6",
				"apiKey": "sk-ant-..."
			},
			{
				"provider": "ollama",
				"model": "llama3.3"
			}
		]
	}
}

If you're using OpenClaw as a serious production tool, strongly recommend setting up failover. Everyone knows OpenAI goes down occasionally, right? Last month the API was out for nearly an hour. People in the community were yelling "the lobster is frozen!" — but it was OpenAI's problem. Those with failover configured were completely unaffected.

API Key Security

Keys are stored in two places: API Key in ~/.openclaw/agents/<agentId>/agent/auth-profiles.json, OAuth credentials in ~/.openclaw/credentials/oauth.json.

A few security tips:

  1. Don't commit API Keys to Git — sounds obvious but people do it. Someone in the community did exactly this, and their Key got scraped overnight for $200+
  2. Set monthly spending limits in each provider's dashboard — don't skip this
  3. Rotate Keys regularly
  4. Use OpenClaw's built-in Key Rotation feature for automatic rotation

Key Rotation config:

{
	"ai": {
		"apiKeys": ["sk-key1...", "sk-key2...", "sk-key3..."],
		"keyRotation": "round-robin"
	}
}

Model Selection by Role

Students or casual users? GPT-4o-mini or DeepSeek is plenty — maybe $1-3/month. Personal daily use: GPT-4o-mini + GPT-5 smart routing, roughly $5-12/month. Developers: Claude Sonnet 4.6 + GPT-5 combo, $8-25/month or so. Privacy-first: Ollama local models, free but needs a good GPU. Teams and enterprise: multi-provider + failover + rate limiting, costs scale with usage.

Oh, and if you're a student on a budget, seriously try DeepSeek. For Chinese-language tasks the quality is close to GPT-4o-mini at a fraction of the cost.

Verifying Model Configuration

# Check current model config (config file is openclaw.json)
openclaw config show

# Test model connectivity
openclaw health

# Check token usage
openclaw usage

FAQ

Q: API Key returns 401 error?

First check if the Key is expired or out of credits. Then verify the Key has permissions for the model you're using. OpenAI Keys sometimes need specific model access enabled in the dashboard — I've been burned by this. New Keys don't have GPT-5 access by default; you have to manually enable it.

Q: Responses are slow?

Try a faster model (like GPT-4o-mini). Users in China accessing overseas models will experience latency — that's normal. Consider switching to Chinese models or using a proxy.

Q: How do I control monthly spend?

Three steps: set monthly spending limits in the model provider's dashboard; use smart routing so you're not sending everything to expensive models; regularly check openclaw usage. The second step is the most effective by far — that single change can cut costs by more than half.


Model configured? Time to explore OpenClaw's 49 built-in skills. Try asking your AI assistant in chat: "What can you do?" — see what it says.