OpenAI's GPT-4o is one of the most capable models you can plug into OpenClaw. This guide covers the exact steps to get it connected, how to choose between models, and how to keep costs sensible.
If you haven't installed OpenClaw yet, start with the getting started guide first.
Step 1: Get Your OpenAI API Key
- Go to platform.openai.com and sign in (or create an account)
- Navigate to API Keys in the left sidebar
- Click Create new secret key — give it a name like "OpenClaw"
- Copy the key immediately. You won't be able to see it again.
- Add credits under Billing → Add payment method. Start with $10–20.
Keep your API key secure. Don't put it in any public repository or share it.
Step 2: Add OpenAI to OpenClaw's Provider Config
OpenClaw stores LLM configuration in its providers file. Open the config directory:
nano ~/.openclaw/config/providers.yml
Add the OpenAI provider block:
providers:
openai:
api_key: "sk-your-key-here"
default_model: "gpt-4o"
models:
- id: "gpt-4o"
max_tokens: 4096
- id: "gpt-4o-mini"
max_tokens: 4096
- id: "gpt-4-turbo"
max_tokens: 4096
Save the file and restart OpenClaw:
openclaw restart
Step 3: Set OpenAI as Your Active Provider
In your main OpenClaw config (~/.openclaw/config/config.yml), set the active provider:
llm:
active_provider: "openai"
active_model: "gpt-4o"
Test the connection by sending a message through your connected messaging app. If you get a response, it's working.
Choosing the Right Model
| Model | Best For | Cost (approx.) |
|---|---|---|
gpt-4o | Complex tasks, reasoning, code, long documents | ~$5 per 1M input tokens |
gpt-4o-mini | Everyday messages, quick tasks, cost efficiency | ~$0.15 per 1M input tokens |
gpt-4-turbo | Long context, detailed analysis | ~$10 per 1M input tokens |
Practical recommendation: Use gpt-4o-mini as your default for everyday messages — it handles 80% of tasks well at a fraction of the cost. Reserve gpt-4o for complex requests. You can trigger different models using prefixes in OpenClaw's routing config:
llm:
routing:
- pattern: "^(analyse|research|code|review)"
model: "gpt-4o"
- default:
model: "gpt-4o-mini"
Managing Costs
OpenAI API costs are pay-per-token. For typical personal use (30–50 messages/day across WhatsApp and Telegram), expect:
- GPT-4o only: $15–40/month
- GPT-4o-mini only: $1–5/month
- Mixed (mini default, 4o for complex): $5–15/month
To monitor spend: OpenAI's dashboard shows usage in real time. Set a usage limit under Billing → Usage limits to cap your monthly spend and avoid surprises.
# Check how many tokens OpenClaw sent in the last 24h
openclaw stats --period 24h
Troubleshooting Common Issues
"Invalid API key" error:
- Confirm the key starts with
sk- - Check there's no trailing space in the YAML value
- Ensure the key hasn't been revoked in the OpenAI dashboard
"Quota exceeded" or "Insufficient funds":
- Add more credits under Billing
- Check your usage limit hasn't been hit
Slow responses:
- GPT-4o can be slower during high-load periods. Switch to
gpt-4o-minitemporarily. - Check OpenAI's status page for ongoing incidents.
Responses feel less capable than ChatGPT:
- Verify you're actually hitting
gpt-4o, not a lower-tier model - Check your SOUL.md — aggressive token limits in system prompts can degrade quality
Switching Between OpenAI and Other Providers
One of OpenClaw's strengths is that you can run multiple providers simultaneously and switch between them:
providers:
openai:
api_key: "sk-openai-key"
default_model: "gpt-4o"
anthropic:
api_key: "sk-ant-key"
default_model: "claude-sonnet-4-5"
This lets you fall back to Anthropic if OpenAI has an outage, or use different models for different task types.
Related reading: