Claude Code Proxy Connection Tutorial: Terminal Agent and Base URL Configuration
Tutorial for connecting the official Anthropic terminal coding agent (Claude Code): installation, setting ANTHROPIC_BASE_URL and API keys, switching models, and troubleshooting.
1. What is Claude Code
Claude Code is Anthropic's official terminal coding agent (CLI), which 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 run using your own API keys and credits.
2. Installing Claude Code
Node.js is required (v18 or higher is officially recommended). Install it globally using:
npm install -g @anthropic-ai/claude-code
After installation, 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 will be sent in the request header, and the ANTHROPIC_BASE_URL is used to override the default API endpoint to point to this site's Anthropic gateway.
4. API Address Reference
| Model Group | Base URL (This Site) | Protocol |
|---|---|---|
| Claude / Anthropic | https://www.relay-api.com | Anthropic Messages |
| GPT / OpenAI | https://www.relay-api.com/v1 | OpenAI Chat Completions |
| Gemini | https://www.relay-api.com/v1beta | Google generateContent |
5. Troubleshooting Common Issues
| Symptom | Resolution |
|---|---|
| 401 / 403 | Invalid key, disabled, or insufficient balance; verify the sk- prefix and top up your account. |
| 404 / Model unavailable | Model name mismatch with platform slug or model not enabled; verify the Model ID. |
| Unknown model | Ensure the Model ID is exact (case-sensitive); verify it in the Model Plaza. |
| Request timeout | Increase timeout for long tasks; retry if there are network fluctuations. |
Security Advice: Do not commit keys to public repositories; use .env files or environment variables. Generation tasks can consume significant tokens, so monitor your balance via the "Usage Logs" to track every call.
Base URL Note: This site accepts both /v1beta/models/... and /v1beta/v1beta/models/... (as well as /v1/... and /v1/v1/...), so it does not matter if your client appends /v1 or /v1beta automatically: you can set the Base URL to either the domain root or the full path with /v1beta. Please copy the Model ID from the "Model ID" section in the top right of the "Tokens" page in your console.
