API Keys Guide
OpenClaw requires at least one LLM provider's API Key to function. This guide walks you through obtaining API Keys from major LLM providers and configuring them in OpenClaw.
Using LLM APIs incurs costs. Each provider has different billing structures — check pricing before signing up. Most providers offer free credits for initial testing.
Quick Comparison
| Provider | Recommended Model | Free Tier | Cost per Million Tokens (approx.) | Best For |
|---|---|---|---|---|
| OpenAI | GPT-5.2 Codex | Limited | $2-15 | General conversation, code generation |
| Anthropic | Claude Opus 4.6 | Limited | $3-15 | Long-form analysis, complex reasoning |
| Gemini 2.5 Pro | Generous free tier | $1-7 | Multimodal, cost-effective | |
| DeepSeek | DeepSeek-V3 | Very low cost | $0.1-0.5 | Budget-conscious, Chinese-optimized |
| Ollama (Local) | Various open-source models | Completely free | $0 (hardware cost only) | Offline use, privacy-first |
OpenAI API Key
Steps
- Go to platform.openai.com
- Sign up or log in to your existing account
- Click API Keys in the left sidebar
- Click Create new secret key
- Name the key (e.g.,
openclaw-production) - Copy and securely store the key (shown only once)
OpenClaw Configuration
llm:
provider: openai
api_key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
model: gpt-5.2-codex
Or use environment variables:
export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Cost Management Tips
- Set a monthly usage cap (Monthly Budget)
- Monitor consumption via the Usage Dashboard
- Use cheaper models (e.g., GPT-4o-mini) during development and testing
Never commit API Keys to a Git repository or share them with others. Use environment variables or a dedicated secrets manager.
Anthropic API Key
Steps
- Go to console.anthropic.com
- Sign up (phone number verification required)
- Navigate to Settings > API Keys
- Click Create Key
- Copy and securely store
OpenClaw Configuration
llm:
provider: anthropic
api_key: sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
model: claude-opus-4-6
Or environment variable:
export ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Recommended Usage
Claude models excel at:
- Long-context understanding: Up to 1M token context window
- Complex reasoning tasks: Multi-step logical analysis
- Code review: Precise code analysis and suggestions
Google Gemini API Key
Steps
- Go to aistudio.google.com
- Sign in with your Google account
- Click Get API Key
- Select or create a Google Cloud Project
- Copy the generated API Key
OpenClaw Configuration
llm:
provider: google
api_key: AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
model: gemini-2.5-pro
Key Features
- Multimodal support (images, video, audio)
- Relatively generous free tier
- Good integration with Google Workspace
DeepSeek API Key
Steps
- Go to platform.deepseek.com
- Register an account (supports mainland China phone numbers)
- Enter the console and find the API Keys section
- Create a new Key and copy it
OpenClaw Configuration
llm:
provider: deepseek
api_key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
model: deepseek-v3
Best For
- Budget-limited: Pricing is 1/10 to 1/30 of OpenAI
- Chinese-language scenarios: Specifically optimized for Chinese
- Mainland China users: Accessible without a VPN
DeepSeek is the preferred LLM provider for mainland China users due to direct access without a VPN and extremely low pricing. Note that state-owned enterprises may have additional compliance requirements for AI services. See Chinese Ecosystem for details.
Ollama (Local Models)
Installation
Ollama does not require an API Key — it runs open-source models on your local machine.
- Go to ollama.com to download and install
- After installation, pull models:
ollama pull llama3.3
ollama pull deepseek-r1:32b
- Configure in OpenClaw:
llm:
provider: ollama
base_url: http://localhost:11434
model: llama3.3
Pros & Cons
| Pros | Cons |
|---|---|
| Completely free | Requires capable hardware (GPU) |
| Data never leaves your machine | Model capabilities usually lag behind cloud |
| No internet connection needed | Large models are slow to start |
| No API rate limiting | You manage model updates |
Multi-Model Routing Strategy
OpenClaw supports configuring multiple LLM providers simultaneously, automatically selecting the best model based on task type:
llm:
default_provider: anthropic
default_model: claude-opus-4-6
routing:
- task: code_generation
provider: openai
model: gpt-5.2-codex
- task: casual_chat
provider: deepseek
model: deepseek-v3
- task: image_analysis
provider: google
model: gemini-2.5-pro
- task: offline_fallback
provider: ollama
model: llama3.3
Route casual conversations to DeepSeek or Ollama, and only use Claude or GPT when high-quality reasoning is needed. This can significantly reduce your monthly API costs.
API Key Security Best Practices
- Use environment variables: Do not write Keys directly in config files
- Rotate regularly: Replace API Keys every 90 days
- Set usage caps: Configure monthly budgets in each provider's console
- Least privilege: If the provider supports it, set minimum necessary permissions for the Key
- Monitor abnormal usage: Regularly check API usage dashboards
If your API Key is accidentally leaked (e.g., committed to GitHub):
- Immediately revoke the Key in the provider's console
- Create a new Key
- Check your billing for abnormal charges
- Review Git history and clean up sensitive data
Related Pages
- Choose an AI Model — Detailed model comparisons
- First Setup — Complete initial configuration
- Chinese Ecosystem — DeepSeek and mainland China considerations
- Security Best Practices — Complete security setup guide