Claude Code Integration Guide: Terminal Agent and Base URL Configuration

  • 发布时间
  • 语言en

A guide to integrating Anthropic's official terminal coding agent, Claude Code: installation, setting up ANTHROPIC_BASE_URL and API keys, model switching, and troubleshooting common issues.

1. What is Claude Code?

Claude Code is Anthropic's official terminal coding agent (CLI) that allows you to read/write code, run commands, and execute tasks directly within your terminal. It natively supports environment variables like ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, making it easy to point to a proxy gateway and use your own API keys and credits.

2. Installing Claude Code

Requires Node.js (version 18 or higher recommended). Install it globally using:

npm install -g @anthropic-ai/claude-code

Once installed, type claude in your terminal to start; use /model or claude --model … to switch between models.

3. Configuring Environment Variables

Windows (PowerShell)

$env:ANTHROPIC_BASE_URL="https://www.relay-api.com"
$env:ANTHROPIC_API_KEY="sk-your-key"
$env:ANTHROPIC_MODEL="claude-sonnet-5"
claude

macOS / Linux (bash / zsh)

export ANTHROPIC_BASE_URL="https://www.relay-api.com"
export ANTHROPIC_API_KEY="sk-your-key"
export ANTHROPIC_MODEL="claude-sonnet-5"
claude

Note: The ANTHROPIC_API_KEY is included in the request header, and ANTHROPIC_BASE_URL overrides the default API endpoint to route requests through our Anthropic gateway.

4. API Endpoint Reference

Model GroupBase URLProtocol
Claude / Anthropichttps://www.relay-api.comAnthropic Messages
GPT / OpenAIhttps://www.relay-api.com/v1OpenAI Chat Completions
Geminihttps://www.relay-api.com/v1betaGoogle generateContent

5. Troubleshooting

IssueResolution
401 / 403Invalid key, disabled account, or insufficient balance; verify your sk- key and check your balance.
404 / Model unavailableModel name mismatch or model is not enabled; verify the model ID.
Unknown modelModel IDs must be exact (case-sensitive); verify them in the Model Marketplace.
Request timeoutIncrease timeout for long-running tasks or retry if there is network instability.

Security Recommendation: Never commit your API key to public repositories. Use .env files or system environment variables instead. Code generation tasks consume tokens quickly, so monitor your balance and check usage logs for every request.