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.
First working request
curl Example
curl -X POST "https://costrouter.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_COSTROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly: CostRouter connected"
}
],
"stream": false
}'Three values to set
- Base URL: https://costrouter.ai/v1
- Authorization: Bearer YOUR_COSTROUTER_API_KEY
- Model: copy the exact ID from Models
Path 2
Configure a coding agent
Each setup shows the Base URL and the environment variable that carries your API Key. Replace YOUR_COSTROUTER_API_KEY and the model placeholder, then run the commands shown to start the tool.
Codex
CostRouter-compatible setup
Configure
Codex
CostRouter-compatible setup
Install Codex
Install the tool, or confirm that your current version starts correctly.
Install Codex
npm install -g @openai/codex
codex --versionCopy one command to verify the connection
The command exports the API Key in the current terminal, then starts Codex with a temporary CostRouter provider. It does not edit config.toml, and the values expire when you close this terminal.
Current terminal (zsh / bash)
export OPENAI_API_KEY="YOUR_COSTROUTER_API_KEY" && \
codex \
-c 'model_provider="costrouter"' \
-c 'model="gpt-5.6-luna"' \
-c 'model_providers.costrouter.name="CostRouter"' \
-c 'model_providers.costrouter.wire_api="responses"' \
-c 'model_providers.costrouter.env_key="OPENAI_API_KEY"' \
-c 'model_providers.costrouter.base_url="https://costrouter.ai/v1"'Persistent setup
Save both the provider endpoint and API Key in config.toml so future Codex sessions load them automatically. The API Key is stored as plain text on this device; use this option only on a personal machine and protect the file.
~/.codex/config.toml
model_provider = "costrouter"
model = "gpt-5.6-luna"
[model_providers.costrouter]
name = "CostRouter"
wire_api = "responses"
base_url = "https://costrouter.ai/v1"
experimental_bearer_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.
Claude Code
CostRouter-compatible setup
Configure
Claude Code
CostRouter-compatible setup
Install Claude Code
Install the tool, or confirm that your current version starts correctly.
Install Claude Code
npm install -g @anthropic-ai/claude-code
claude --versionCopy one command to verify the connection
Run the complete command below. It exports the Base URL and API Key into the current terminal without editing any configuration files. The values expire when you close this terminal.
Current terminal (zsh / bash)
export ANTHROPIC_BASE_URL="https://costrouter.ai" \
ANTHROPIC_AUTH_TOKEN="YOUR_COSTROUTER_API_KEY" && \
claudePersistent setup
Save these values in the tool configuration file so they remain available after restart.
~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://costrouter.ai",
"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
Install the tool, or confirm that your current version starts correctly.
Install Gemini CLI
npm install -g @google/gemini-cli
gemini --versionCopy one command to verify the connection
Run the complete command below. It exports the Base URL and API Key into the current terminal without editing any configuration files. The values expire when you close this terminal.
Current terminal (zsh / bash)
export GOOGLE_GEMINI_BASE_URL="https://costrouter.ai" \
GEMINI_API_KEY="YOUR_COSTROUTER_API_KEY" \
GEMINI_MODEL="gemini-available-model-id" && \
geminiPersistent setup
Save these values in the tool configuration file so they remain available after restart.
~/.gemini/settings.json
{
"env": {
"GOOGLE_GEMINI_BASE_URL": "https://costrouter.ai",
"GEMINI_API_KEY": "YOUR_COSTROUTER_API_KEY",
"GEMINI_MODEL": "gemini-available-model-id"
}
}- 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
Install the tool, or confirm that your current version starts correctly.
Install Cursor
cursor .Copy one command to verify the connection
This passes the environment variables only to this Cursor launch and its project processes. Whether they control the built-in Agent still depends on your Cursor version.
Current terminal (zsh / bash)
export OPENAI_API_KEY="YOUR_COSTROUTER_API_KEY" \
OPENAI_BASE_URL="https://costrouter.ai/v1" && \
cursor .Persistent setup
Save this in the project .env for code and scripts run inside Cursor. Custom Base URL support for Cursor's built-in Agent depends on the installed version.
.env
OPENAI_API_KEY="YOUR_COSTROUTER_API_KEY"
OPENAI_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 spend limits, expiry, model restrictions, and IP allowlists.
- Review Usage Logs after configuration and model changes.
- Load secrets from environment variables or a secret manager.