You can connect ClawRouters to Cursor, Windsurf, OpenClaw, and any OpenAI-compatible AI agent by changing one setting โ the base URL โ to get automatic smart routing that picks the best model for each task and reduces your AI costs by 60-90%.
Why Route Your AI Coding Tools Through ClawRouters?
If you're using Cursor, Windsurf, or other AI-powered coding tools, you're making hundreds of API calls per coding session. Each call costs money โ and most of them don't need an expensive model.
Here's what happens in a typical Cursor session over 4 hours:
| Activity | Calls | % of Total | Ideal Model | Cost/M Output | |----------|-------|-----------|-------------|---------------| | Autocomplete / tab completions | ~120 | 48% | Gemini 3 Flash | $0.30 | | Inline suggestions | ~50 | 20% | Mistral Small 3 | $0.30 | | Chat questions ("how do I...") | ~30 | 12% | DeepSeek V3 | $1.10 | | Code generation (composer) | ~25 | 10% | Claude Sonnet 4 | $15.00 | | Complex refactoring / debugging | ~15 | 6% | Claude Sonnet 4 | $15.00 | | Architecture decisions | ~10 | 4% | Claude Opus 4 | $75.00 | | Total | ~250 | 100% | | |
Without ClawRouters, all 250 calls hit the same model. With Claude Sonnet 4 as default, that's $15/M output on every autocomplete โ 50x overpaying for tab completions.
With ClawRouters, each call automatically routes to the best model for the task โ same quality, dramatically lower cost.
Real Cost Comparison for a Day of Coding
| Approach | Daily Cost | Monthly Cost | |----------|-----------|-------------| | All Opus | ~$18.75 | ~$562 | | All Sonnet | ~$3.75 | ~$112 | | ClawRouters (smart routing) | ~$1.20 | ~$36 | | ClawRouters (cheapest strategy) | ~$0.65 | ~$19 |
Smart routing saves 68-97% compared to using a single model. Even compared to the already-reasonable Sonnet, you save 68%.
Setting Up ClawRouters (2 Minutes)
Before connecting any tool, you need a ClawRouters account and API key:
- Sign up at ClawRouters โ Free account, no credit card needed
- Add your provider keys โ Go to Dashboard โ Models, add your OpenAI, Anthropic, Google, and/or DeepSeek API keys
- Get your ClawRouters key โ Go to Dashboard โ Keys, generate a new API key (starts with
cr_)
That's it. You now have a key that gives you smart routing across all your provider models. Let's connect your tools.
Cursor Integration
Cursor is one of the most popular AI-powered code editors in 2026. Here's how to route it through ClawRouters:
Step 1: Open Cursor Settings
Go to Cursor Settings โ Models โ OpenAI API Key
Step 2: Configure the API
- API Key: Enter your ClawRouters key (
cr_your_key_here) - Base URL:
https://www.clawrouters.com/api/v1
Step 3: Select Models
In Cursor's model dropdown, you can use:
autoโ ClawRouters picks the optimal model for each request (recommended)- Any specific model like
claude-sonnet-4,gpt-4o,deepseek-v3, etc.
Step 4: Test It
Open a file and try a code completion or ask Cursor to explain some code. You should see responses coming through. Check your ClawRouters dashboard to verify routing is working.
Cursor-Specific Tips
For Tab Completions (Inline):
The auto strategy will route these to fast, cheap models like Gemini 3 Flash ($0.30/M) or Mistral Small 3 ($0.30/M) โ perfect since autocomplete needs speed more than deep reasoning. This alone can save 50-100x compared to using Sonnet for completions.
For Chat: Questions like "how do I sort a list in Python?" go to DeepSeek V3 or Haiku. Complex questions like "design a caching strategy for this microservice" go to Sonnet or Opus. The router handles this automatically.
For Composer (Multi-File Edits): Composer requests are typically more complex and get routed to Sonnet or Opus. This is the right behavior โ you want quality for multi-file refactoring.
Cursor Cost Breakdown with ClawRouters:
| Cursor Feature | Calls/Day | Without Router (Sonnet) | With ClawRouters | |---------------|----------|------------------------|-----------------| | Tab completions | 120 | $0.90 | $0.02 (Flash) | | Inline suggestions | 50 | $0.38 | $0.01 (Mistral Small) | | Chat | 30 | $0.23 | $0.05 (DeepSeek V3) | | Composer | 25 | $0.19 | $0.12 (Sonnet) | | Complex tasks | 25 | $0.19 | $0.35 (mix Sonnet/Opus) | | Daily total | 250 | $1.89 | $0.55 | | Monthly total | | $56.70 | $16.50 |
Monthly savings: $40.20 (71%)
Windsurf Integration
Windsurf (formerly Codeium) supports custom API endpoints:
Step 1: Open Settings
Navigate to Settings โ AI Provider or Custom API
Step 2: Configure
- Provider: Select "OpenAI-Compatible" or "Custom"
- API Endpoint:
https://www.clawrouters.com/api/v1 - API Key: Your ClawRouters key (
cr_your_key_here) - Model:
auto(or any specific model)
Step 3: Verify
Write some code and test that completions and chat are working. Check your ClawRouters dashboard for routing activity.
Windsurf-Specific Tips
Windsurf's Cascade feature makes multi-step agent calls. With ClawRouters:
- Early planning steps โ Routed to cheaper models (understanding the task doesn't need Opus)
- Code generation steps โ Mid-tier models (Sonnet, DeepSeek V3)
- Complex reasoning steps โ Premium models (Opus, GPT-5.2)
This multi-step routing is where ClawRouters shines most โ each step in a Cascade gets the right model.
OpenClaw Integration
OpenClaw agents work seamlessly with ClawRouters. You can set it up with a one-liner:
Quick Setup (One Command)
curl -fsSL https://www.clawrouters.com/setup.sh | bash -s -- cr_YOUR_KEY_HERE
Manual Configuration
Edit your OpenClaw config (~/.openclaw/openclaw.json):
{
"models": {
"providers": {
"clawrouters": {
"baseUrl": "https://www.clawrouters.com/api/v1",
"apiKey": "cr_YOUR_KEY_HERE",
"api": "openai-completions",
"models": [
{ "id": "auto", "name": "ClawRouters Auto" },
{ "id": "claude-sonnet-4", "name": "Claude Sonnet 4" },
{ "id": "gpt-4o", "name": "GPT-4o" },
{ "id": "deepseek-v3", "name": "DeepSeek V3" }
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "clawrouters/auto"
}
}
}
}
Why OpenClaw + ClawRouters is the Perfect Combination
OpenClaw agents make a lot of API calls โ reading files, analyzing code, writing responses, running tools, planning next steps. A single session can make 50-200+ calls. Without routing, every call hits the same expensive model. With ClawRouters:
| Agent Action | Model Selected | Cost/M Output | |-------------|---------------|---------------| | Read file contents | Gemini 3 Flash | $0.30 | | Summarize code | DeepSeek V3 | $1.10 | | Plan next steps | Claude Haiku 3.5 | $1.25 | | Generate code | Claude Sonnet 4 | $15.00 | | Complex reasoning | Claude Opus 4 | $75.00 | | Format output | Mistral Small 3 | $0.30 |
Without routing: 100 calls ร avg $15/M (Sonnet) = ~$7.50 per session With routing: 100 calls ร avg $2.50/M (weighted) = ~$1.25 per session
That's a 6x reduction per session. For a developer running 5-10 sessions/day, it's $31-62/day saved.
Claude Code & Codex Integration
Claude Code and OpenAI Codex also support custom API endpoints:
Claude Code
# Set environment variables
export ANTHROPIC_BASE_URL=https://www.clawrouters.com/api/v1
export ANTHROPIC_API_KEY=cr_YOUR_KEY_HERE
Or configure in Claude Code's settings file.
Codex CLI
# Use with OpenAI-compatible endpoint
export OPENAI_API_BASE=https://www.clawrouters.com/api/v1
export OPENAI_API_KEY=cr_YOUR_KEY_HERE
Any OpenAI-Compatible Tool
ClawRouters works with any tool that supports the OpenAI API format. The pattern is always the same:
- Find the API configuration settings
- Set the base URL to
https://www.clawrouters.com/api/v1 - Set the API key to your ClawRouters key
- Set the model to
auto(or a specific model)
Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://www.clawrouters.com/api/v1",
api_key="cr_your_key_here"
)
response = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Write a React component for a todo list"}]
)
print(response.choices[0].message.content)
Node.js
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://www.clawrouters.com/api/v1',
apiKey: 'cr_your_key_here',
});
const response = await client.chat.completions.create({
model: 'auto',
messages: [{ role: 'user', content: 'Optimize this SQL query...' }],
});
console.log(response.choices[0].message.content);
cURL
curl https://www.clawrouters.com/api/v1/chat/completions \
-H "Authorization: Bearer cr_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Environment Variables (Universal)
# Works with most OpenAI-compatible tools
export OPENAI_API_BASE=https://www.clawrouters.com/api/v1
export OPENAI_API_KEY=cr_your_key_here
LangChain / LlamaIndex
# LangChain
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://www.clawrouters.com/api/v1",
api_key="cr_your_key_here",
model="auto"
)
# LlamaIndex
from llama_index.llms.openai import OpenAI as LlamaOpenAI
llm = LlamaOpenAI(
api_base="https://www.clawrouters.com/api/v1",
api_key="cr_your_key_here",
model="auto"
)
Routing Strategies for Different Workflows
ClawRouters supports different routing strategies you can set per request or as a default:
For Coding (Recommended: Balanced)
response = client.chat.completions.create(
model="auto",
messages=[...],
extra_body={"strategy": "balanced"}
)
Balanced mode picks the best quality-to-cost ratio. For coding, this typically means:
- Simple completions โ Flash/Haiku ($0.30-1.25/M)
- Standard generation โ DeepSeek V3/Sonnet ($1.10-15/M)
- Complex tasks โ Opus ($75/M)
For Cost-Sensitive Agents (Cheapest)
response = client.chat.completions.create(
model="auto",
messages=[...],
extra_body={"strategy": "cheapest"}
)
Maximum savings. Uses the cheapest model that meets minimum quality thresholds. Great for:
- Background processing tasks
- High-volume batch operations
- Tasks where cost matters more than marginal quality
For Quality-Critical Tasks (Best Quality)
response = client.chat.completions.create(
model="auto",
messages=[...],
extra_body={"strategy": "quality"}
)
Always picks the highest-quality model for the task type. Use for:
- Production code for critical systems
- Customer-facing code generation
- Security-sensitive tasks
Mixing Strategies in the Same Session
You can switch strategies per-request, which is powerful for agents:
# Agent planning phase โ save money
plan = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "What files should I modify for this feature?"}],
extra_body={"strategy": "cheapest"}
)
# Code generation phase โ balanced quality
code = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Implement the feature..."}],
extra_body={"strategy": "balanced"}
)
# Security review phase โ maximum quality
review = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Review this code for security vulnerabilities..."}],
extra_body={"strategy": "quality"}
)
Monitoring Your Usage
Once connected, check your ClawRouters dashboard to see:
- Model distribution โ Which models are handling your traffic (pie chart)
- Cost savings โ Real-time comparison vs. single-model approach
- Request patterns โ Volume, latency, and cost over time
- Task classification โ How the router is categorizing your requests
- Per-tool breakdown โ See Cursor vs. OpenClaw vs. API usage separately
This data helps you understand your AI usage patterns and optimize further. For more optimization techniques, see our guide on reducing LLM API costs.
Advanced: Custom Model Preferences
You can override the router's default behavior for specific use cases:
# Force a specific model for a request
response = client.chat.completions.create(
model="claude-opus-4", # Skip auto-routing, use Opus directly
messages=[{"role": "user", "content": "Design a distributed system..."}]
)
# Use auto-routing but exclude certain models
response = client.chat.completions.create(
model="auto",
messages=[...],
extra_body={
"strategy": "balanced",
"exclude_models": ["deepseek-v3"] # If you prefer not to use DeepSeek
}
)
# Set a maximum cost per request
response = client.chat.completions.create(
model="auto",
messages=[...],
extra_body={
"max_cost_per_1m_output": 15 # Never use models above $15/M output
}
)
Troubleshooting
"Connection refused" or timeout
- Verify the base URL is exactly
https://www.clawrouters.com/api/v1(no trailing slash) - Check that your ClawRouters API key is valid (starts with
cr_) - Test with cURL to isolate the issue:
curl https://www.clawrouters.com/api/v1/models -H "Authorization: Bearer cr_your_key_here"
"Model not found"
- Make sure you've added the relevant provider API keys in Dashboard โ Models
- If using BYOK, ensure your provider keys have access to the models you're requesting
- Check that the model name is correct (e.g.,
claude-sonnet-4notclaude-3-sonnet)
Slow responses
- This is usually the upstream model, not ClawRouters (we add <10ms overhead, including task classification)
- Try setting
strategy: "cheapest"to route to faster, lighter models - Check the ClawRouters status page for any ongoing issues
- If using Opus for many requests, consider
strategy: "balanced"to route simpler tasks to faster models
Streaming not working
- ClawRouters supports full SSE streaming for all models
- Make sure your client is configured for streaming:
stream=Truein Python,stream: truein JS - Some tools require explicit streaming enable โ check your tool's documentation
Rate limiting
- ClawRouters handles rate limits across providers โ if one provider is rate-limited, requests automatically route to alternatives
- Check your provider API key tier if you're hitting limits frequently
- Consider upgrading your provider plan or adding keys from multiple providers
What's Next
Now that you're connected:
- Explore all available models and understand what each excels at
- Check out the best LLMs for coding to understand the price/quality landscape
- Read about what an LLM router is if you want to understand the technology
- Compare ClawRouters vs alternatives like OpenRouter and LiteLLM
- Learn more AI agent cost optimization strategies
Happy coding โ and happy saving! ๐