Connect apps and coding agents
Choose a path, apply the CostRouter Base URL and API Key, then verify the first request in Usage Logs.
Path 1
Connect your AI application
Keep your compatible SDK or HTTP client. Replace only the Base URL, API Key, and model ID.
Three values to set
- Base URL: https://costrouter.ai/v1
- Authorization: Bearer YOUR_COSTROUTER_API_KEY
- Model: copy the exact ID from Models
First working request
curl https://costrouter.ai/v1/chat/completions \
-H "Authorization: Bearer YOUR_COSTROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}'Path 2
Configure a coding agent
Use a separate CostRouter key for each tool, then apply the matching provider configuration below.
Codex
CostRouter-compatible setup
Configure
Codex
CostRouter-compatible setup
Install Codex
npm install -g @openai/codex~/.codex/config.toml
model = "gpt-4o"
model_provider = "costrouter"
[model_providers.costrouter]
base_url = "https://costrouter.ai/v1"
env_key = "OPENAI_API_KEY"- Use a dedicated API Key for this tool.
- Choose an available model from Models.
- Restart the tool and verify the request in Usage Logs.
Claude Code
CostRouter-compatible setup
Configure
Claude Code
CostRouter-compatible setup
Install Claude Code
npm install -g @anthropic-ai/claude-codeEnvironment variables
export ANTHROPIC_BASE_URL="https://costrouter.ai"
export ANTHROPIC_AUTH_TOKEN="YOUR_COSTROUTER_API_KEY"- Use a dedicated API Key for this tool.
- Choose an available model from Models.
- Restart the tool and verify the request in Usage Logs.
Gemini CLI
CostRouter-compatible setup
Configure
Gemini CLI
CostRouter-compatible setup
Install Gemini CLI
npm install -g @google/gemini-cliEnvironment variables
export GEMINI_API_KEY="YOUR_COSTROUTER_API_KEY"
export GEMINI_MODEL="gemini-2.5-flash"- Use a dedicated API Key for this tool.
- Choose an available model from Models.
- Restart the tool and verify the request in Usage Logs.
Cursor
CostRouter-compatible setup
Configure
Cursor
CostRouter-compatible setup
Install Cursor
winget install Anysphere.CursorProject environment
COSTROUTER_API_KEY=YOUR_COSTROUTER_API_KEY
COSTROUTER_BASE_URL=https://costrouter.ai/v1- Use a dedicated API Key for this tool.
- Choose an available model from Models.
- Restart the tool and verify the request in Usage Logs.
Manage local agent profiles
cc-switch can store and switch local provider profiles. Add your CostRouter Base URL and API Key once.
Production
Before you ship
Keep access controlled and costs observable as traffic grows.
- Use one key per app, environment, or agent.
- Set quotas, expiry, model limits, and IP allowlists.
- Review Usage Logs after configuration and model changes.
- Load secrets from environment variables or a secret manager.