โ† Back to Blog

Using ClawRouters with Cursor, Windsurf & AI Agents: Integration Guide

2026-03-12ยท13 min readยทClawRouters Team
cursor ai apiai agent routerwindsurf api setupopenclaw clawrouterscursor custom apiai coding tool setup

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:

  1. Sign up at ClawRouters โ€” Free account, no credit card needed
  2. Add your provider keys โ€” Go to Dashboard โ†’ Models, add your OpenAI, Anthropic, Google, and/or DeepSeek API keys
  3. 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

Step 3: Select Models

In Cursor's model dropdown, you can use:

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

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:

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:

  1. Find the API configuration settings
  2. Set the base URL to https://www.clawrouters.com/api/v1
  3. Set the API key to your ClawRouters key
  4. 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:

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:

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:

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:

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

"Model not found"

Slow responses

Streaming not working

Rate limiting

What's Next

Now that you're connected:

Happy coding โ€” and happy saving! ๐Ÿš€


FAQ

Ready to Reduce Your AI API Costs?

ClawRouters routes every API call to the optimal model โ€” automatically. Start saving today.

Get Started Free โ†’

Get weekly AI cost optimization tips

Join 2,000+ developers saving on LLM costs