Agent Tools

Claude Code

Connect Claude Code to Yolo Router and use a selected model for coding assistance.

iBefore you start
  • Claude Code is installed and available as claude.
  • A working Yolo Router endpoint, for example https://api.yolorouter.com.
  • A Yolo Router API Key generated from the console.
  • The model ID you want to use, for example glm-5.1. It must exactly match the model ID in the Yolo Router console.

Claude Code communicates with LLM gateways through the Anthropic Messages format. Confirm that your Yolo Router service supports the Claude Code required Anthropic-compatible endpoints, such as /v1/messages and /v1/messages/count_tokens.

Setup

Check Claude Code

Run:

claude --version

If Claude Code is not installed yet, install it first using the official Claude Code installation flow.

Set the Yolo Router key and endpoint

Claude Code supports environment variables for overriding the API endpoint and authentication. A common Yolo Router setup is:

export ANTHROPIC_BASE_URL="https://api.yolorouter.com"
export ANTHROPIC_AUTH_TOKEN="sk-yolo-..."
export ANTHROPIC_MODEL="glm-5.1"
export ANTHROPIC_CUSTOM_MODEL_OPTION="glm-5.1"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
$env:ANTHROPIC_BASE_URL = "https://api.yolorouter.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-yolo-..."
$env:ANTHROPIC_MODEL = "glm-5.1"
$env:ANTHROPIC_CUSTOM_MODEL_OPTION = "glm-5.1"
$env:CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY = "1"
set ANTHROPIC_BASE_URL=https://api.yolorouter.com
set ANTHROPIC_AUTH_TOKEN=sk-yolo-...
set ANTHROPIC_MODEL=glm-5.1
set ANTHROPIC_CUSTOM_MODEL_OPTION=glm-5.1
set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1

Variable reference:

  • ANTHROPIC_BASE_URL: routes Claude Code requests through Yolo Router. Usually use the root endpoint; do not append /v1
  • ANTHROPIC_AUTH_TOKEN: sent as Authorization: Bearer ...; use your Yolo Router API Key
  • ANTHROPIC_MODEL: default model ID at startup
  • ANTHROPIC_CUSTOM_MODEL_OPTION: adds a non-standard model ID to the /model picker
  • CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY: lets Claude Code populate /model from the gateway's /v1/models endpoint

Optional: write settings

For persistent non-secret settings, edit the Claude Code user settings file:

~/.claude/settings.json

Example:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.yolorouter.com",
    "ANTHROPIC_MODEL": "glm-5.1",
    "ANTHROPIC_CUSTOM_MODEL_OPTION": "glm-5.1",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}

Keep the API Key in your system environment or shell profile. Do not commit it to your repository.

Start Claude Code

Open any project directory and run:

claude

You can also select the model for this launch only:

claude --model glm-5.1

After startup, run /model and confirm that your configured model is available.

Test the connection

In Claude Code, send:

Introduce the model you are using in one sentence.

If Claude Code returns a normal response, the integration is working. You can also check the Yolo Router console for the corresponding request log.

Troubleshooting

401 or authentication error

Check that ANTHROPIC_AUTH_TOKEN is set to your Yolo Router API Key. Claude Code prefixes the value with Bearer, so do not include Bearer yourself.

404 or endpoint not found

Check that ANTHROPIC_BASE_URL is the root endpoint https://api.yolorouter.com, not https://api.yolorouter.com/v1. Also confirm that your Yolo Router service supports Claude Code/Anthropic-compatible endpoints.

Model does not appear in /model

Set ANTHROPIC_CUSTOM_MODEL_OPTION=glm-5.1 and restart Claude Code. You can also set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 to let Claude Code fetch models from the gateway's /v1/models endpoint.

Model not found

Check that ANTHROPIC_MODEL or --model exactly matches the model ID in the Yolo Router console. Do not use a display name, alias, or value with extra spaces.

Settings do not take effect

Claude Code reads environment variables at startup. After changing environment variables or ~/.claude/settings.json, close the current Claude Code session and start it again.

On this page