Claude Code API Setup with Sprelay
Claude Code uses the Anthropic Messages protocol. Its base URL is the site root because the client appends /v1/messages.
Before starting, create a dedicated API key, select a group that supports your model, and check the live model catalog. For Claude Fable 5.1, the Sprelay model ID is claude-fable-5-1; see the model and billing guide. The examples below use another model ID and must be changed to match your key's group.
Temporary configuration
# Keep the root URL; do not add /v1.
export ANTHROPIC_BASE_URL="https://sprelaytoken.com"
# Replace only the placeholder with the complete dedicated key.
export ANTHROPIC_AUTH_TOKEN="sk-your-key"
# Copy an available Claude model ID from the live catalog.
export ANTHROPIC_MODEL="claude-sonnet-4-6"
# Start Claude Code from this same terminal.
claude# These variables apply to this PowerShell and its child processes.
$env:ANTHROPIC_BASE_URL = "https://sprelaytoken.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-your-key"
$env:ANTHROPIC_MODEL = "claude-sonnet-4-6"
# Launch Claude Code after setting all three values.
claudeFor a team repository, commit only an empty template:
# Safe template: never commit a real token here.
ANTHROPIC_BASE_URL=https://sprelaytoken.com
ANTHROPIC_AUTH_TOKEN=
ANTHROPIC_MODEL=Test with a small, read-only task, then verify the model and charge in Sprelay usage logs. If Claude Code opens an Anthropic login flow, restart it from the terminal where the variables were set. A 404 usually means /v1 was incorrectly added to the base URL.
Verify the connection
- Ask Claude Code to explain a small file without changing it.
- Check Sprelay usage logs for a successful request and the expected model and key.
- Review the actual input, output and cache charges before increasing the key quota. Agent tasks can make several requests.
Troubleshooting
| Symptom | Check |
|---|---|
| Anthropic login opens | Start a new Claude Code process from the terminal containing the environment variables. Check for conflicting credential settings. |
| 401 | Confirm the complete token, key status, expiry and available balance. |
| 404 | Use the site root as the base URL; do not include /v1/messages. |
| Model unavailable | Match the exact model ID and the key's selected group. |
| Unexpected spend | Inspect multi-turn calls, context length and cache usage in the logs. |
If the client still fails, isolate it with a Claude Messages API request. Read API error handling and billing before retrying repeatedly. The environment variable approach is described in the official Claude Code gateway documentation.
