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.

Recommended first step

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

Codex

CostRouter-compatible setup

Configure
1

Install Codex

Install the tool, or confirm that your current version starts correctly.

Install Codex

npm install -g @openai/codex
codex --version
2
Recommended: test first

Copy 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"'
3

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.
Antigravity

Claude Code

CostRouter-compatible setup

Configure
1

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 --version
2
Recommended: test first

Copy 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" && \
claude
3

Persistent 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

Gemini CLI

CostRouter-compatible setup

Configure
1

Install Gemini CLI

Install the tool, or confirm that your current version starts correctly.

Install Gemini CLI

npm install -g @google/gemini-cli
gemini --version
2
Recommended: test first

Copy 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" && \
gemini
3

Persistent 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

Cursor

CostRouter-compatible setup

Configure
1

Install Cursor

Install the tool, or confirm that your current version starts correctly.

Install Cursor

cursor .
2
Recommended: test first

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 .
3

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.

Get cc-switch

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.

Copyright 2026 CostRouter. All rights reserved.

CostRouter is prohibited for users located in mainland China. If use from mainland China is discovered, CostRouter may suspend or terminate the account, and any paid fees or remaining balance will not be refunded.

Contact us

Choose the channel that best matches your request.

Contact us
Connect AI Apps and Coding Agents | CostRouter