Integrations
Claude Code
Anthropic's coding agent for the terminal. Step-by-step setup with Laras Router through the Anthropic Messages API.
On this page
This guide connects Claude Code to Laras Router through the Anthropic Messages API. The connection settings were checked against the Claude Code gateway documentation.
You need an API key (lr_live_…) and a topped-up balance. New to Laras Router? Start with the Quickstart.
Set up
Point Claude Code at Laras Router
Set the base URL and your key in the shell you start Claude Code from.
export ANTHROPIC_BASE_URL="https://api.larasrouter.com"
export ANTHROPIC_AUTH_TOKEN="lr_live_your_key_here"
Leave /v1 off the base URL: Claude Code adds /v1/messages itself. ANTHROPIC_AUTH_TOKEN sends the key as Authorization: Bearer, and ANTHROPIC_API_KEY sends it as x-api-key. Laras Router accepts both.
Choose the model
Claude Code sends Claude model names unless you tell it otherwise, and Laras Router answers those with 404 model_not_found. Point every role at deepseek-flash.
export ANTHROPIC_MODEL="deepseek-flash[1m]"
export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-flash[1m]"
export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-flash[1m]"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-flash"
export CLAUDE_CODE_SUBAGENT_MODEL="deepseek-flash"
The [1m] suffix tells Claude Code that the model has a 1M-token context window. Without it, Claude Code does not recognize deepseek-flash, assumes 200k tokens, warns at startup, and compacts the conversation far earlier than it needs to. Claude Code removes the suffix before it sends the request.
The Haiku and subagent variables matter: Claude Code uses those models for background tasks and subagents, and a request for any other name fails.
Start Claude Code
Run claude, then /status. The Anthropic base URL line should show https://api.larasrouter.com and the credential line should name ANTHROPIC_AUTH_TOKEN. Send a message to confirm it answers.
Keep it in a settings file
Shell exports last for one terminal session. To apply the settings everywhere Claude Code runs, put them in the env block of ~/.claude/settings.json.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.larasrouter.com",
"ANTHROPIC_AUTH_TOKEN": "lr_live_your_key_here",
"ANTHROPIC_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-flash",
"CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-flash"
}
}
Never put the key in a project's .claude/settings.json: that file is committed and shared with everyone who clones the repository.
Check the connection first
To rule out Claude Code itself, send one request with curl.
curl -sS https://api.larasrouter.com/v1/messages \
-H "x-api-key: $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "deepseek-flash", "max_tokens": 16, "messages": [{"role": "user", "content": "Say hi."}]}'
A JSON reply that starts with {"id":"msg_ means the key and the model are good.
Good to know
- A
[claude-code:unrecognized_model]diagnostic line may still print when you runclaude -p. It is informational: Claude Code does not know the model id, and the[1m]suffix already gave it the context window. - Create a separate API key for Claude Code with a monthly budget. A coding agent resends the whole conversation on every turn, so a long session adds up.
- Claude Code asks
deepseek-flashto reason, and reasoning tokens are billed as output. The usage Claude Code shows is the usage you are charged for. - Image input is not supported: pasting an image fails with
400 invalid_request_error. Web search runs on Anthropic's servers and is not available. POST /v1/messages/count_tokensis not offered. Claude Code falls back to a character-based estimate, so/contextshows approximate counts.- Streaming keeps the connection alive with
pingevents during long pauses, so Claude Code's idle timeout does not cut a long generation. - To stop Claude Code sending background traffic to Anthropic (update checks, telemetry), add
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1. It also turns off auto-updates.
Troubleshooting
| You see | Cause | Fix |
|---|---|---|
404 with model_not_found | A Claude model name reached Laras Router | Set ANTHROPIC_MODEL and the ANTHROPIC_DEFAULT_*_MODEL variables from the steps above |
| A startup warning that Claude Code "assumes a context window of 200k tokens" | The model was set without [1m] | Use deepseek-flash[1m] for ANTHROPIC_MODEL, Opus, and Sonnet, as in the steps above |
401 with authentication_error | The key is wrong, revoked, or truncated | Copy the key again from the console. Check /status for which variable is in use |
402 with billing_error | The balance or the key's budget cannot cover the request | Top up or raise the key's budget |
400 mentioning an image | An image was attached | Remove it; the model takes text only |
429 with rate_limit_error | The key hit its request or concurrency limit | Wait for Retry-After. See Rate limits |
| Claude Code asks you to log in | It found no credential in the environment it started with | Set ANTHROPIC_AUTH_TOKEN in a shell export or in ~/.claude/settings.json, then restart claude |
Settings and screens can change between versions. If something looks different, check the Claude Code documentation. For other tools, see all integrations.