Skip to main content

Claude Code Setup

Use Korad.AI optimization with Claude Code Configure Claude Code Desktop to use the Korad.AI gateway.

Overview​

Claude Code can be configured to use any OpenAI-compatible API, including Korad.AI. This gives you automatic cost savings while using the Claude Code interface.

Configuration Options​

Option 1: Settings File​

Edit ~/.claude/settings.json:

{
"apiUrl": "http://localhost:8084/v1",
"apiKey": "sk-bf-YOUR_VIRTUAL_KEY"
}

For production:

{
"apiUrl": "https://api.korad.ai/v1",
"apiKey": "sk-bf-YOUR_VIRTUAL_KEY"
}

Option 2: Custom Provider File​

Create ~/.claude/custom_providers.json:

{
"providers": [
{
"name": "korad-ai",
"base_url": "http://localhost:8084/v1",
"api_key": "sk-bf-YOUR_VIRTUAL_KEY",
"models": [
"anthropic/claude-opus-4-20250514",
"anthropic/claude-sonnet-4-5-20250929",
"anthropic/claude-haiku-4-5-20251001"
]
}
]
}

Option 3: Environment Variables​

export OPENAI_API_BASE="http://localhost:8084/v1"
export OPENAI_API_KEY="sk-bf-YOUR_VIRTUAL_KEY"

Add to ~/.bashrc or ~/.zshrc for persistence.

Option 4: Desktop App Settings​

  1. Open Claude Code Desktop
  2. Go to Settings → API Provider
  3. Select "Custom" or "OpenAI-compatible"
  4. Enter:
    • Base URL: http://localhost:8084/v1
    • API Key: Your Virtual Key

Verification​

After configuration, verify it works:

# In Claude Code
/ask What is 2+2?

Check the response headers in your logs to confirm optimization:

X-Korad-Strategy: Passthrough (no optimization needed)
X-Korad-Billed-Amount: $0.000057

Using Optimization Tiers​

Enable Cost Savings​

Add custom headers by creating a wrapper script:

# ~/.claude/hooks/pre-request.sh
export OPENAI_API_EXTRA_HEADERS='{
"X-Savings-Level": "med"
}'
Use CaseSetting
DevelopmentX-Savings-Level: med
Codebase AnalysisX-Vanishing-Context: true
Cost SensitiveX-Savings-Level: extreme
Quality CriticalNo headers (automatic)

Troubleshooting​

Connection Refused​

Make sure the optimizer is running:

docker-compose ps optimizer

Invalid API Key​

Check your virtual key is valid:

curl http://localhost:8081/api/governance/virtual-keys

No Optimization Applied​

Small requests may not trigger optimization. Try with larger context:

# Paste a large file and ask questions
/ask Summarize this file

Use Claude Code with automatic cost savings.