Claude Code
Claude Code supports LLM gateways through environment variables, so you can point it at OpenPike, give it its own virtual key, and put a budget and loop detection on it.
| OpenPike endpoint | POST /v1/messages (Anthropic format) |
| Base URL | https://api.openpike.dev |
| Key | A virtual key, in ANTHROPIC_AUTH_TOKEN |
| Models | anthropic/..., deepseek/... or a messages alias, set with ANTHROPIC_DEFAULT_*_MODEL |
| Tags | ANTHROPIC_CUSTOM_HEADERS |
1. Create a key for Claude Code
Section titled “1. Create a key for Claude Code”On the Keys page, create a virtual key named for the developer, for example claude-code-alice, with the tag agent=claude-code. Then add a budget and a loop limit on that key or tag; see Stop a runaway agent. The workspace needs a provider key for the models you choose: Anthropic for the setup below, DeepSeek for the DeepSeek models.
2. Configure Claude Code
Section titled “2. Configure Claude Code”Put the settings in the env block of your user settings file, ~/.claude/settings.json (on Windows, %USERPROFILE%\.claude\settings.json), so they apply to every session, background agents included:
{ "env": { "ANTHROPIC_BASE_URL": "https://api.openpike.dev", "ANTHROPIC_AUTH_TOKEN": "opk_live_...", "ANTHROPIC_DEFAULT_OPUS_MODEL": "anthropic/claude-opus-5-5", "ANTHROPIC_DEFAULT_SONNET_MODEL": "anthropic/claude-sonnet-5-5", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "anthropic/claude-haiku-5-5", "ANTHROPIC_CUSTOM_HEADERS": "x-openpike-tags: agent=claude-code" }}ANTHROPIC_BASE_URLpoints Claude Code at OpenPike. Claude Code adds/v1/messagesitself.ANTHROPIC_AUTH_TOKENsends the virtual key asAuthorization: Bearer, which OpenPike accepts. It replaces a claude.ai login for these requests, so your subscription’s limits do not apply and the tokens are billed to the Anthropic key in your workspace.- The
ANTHROPIC_DEFAULT_*_MODELvariables decide what Claude Code’sopus,sonnetandhaikuchoices send. OpenPike needs theanthropic/prefix. Claude Code recognizes a name that contains a Claude model ID it knows, so it treatsanthropic/claude-sonnet-5-5as Sonnet 5.5, with its features and context window. ANTHROPIC_CUSTOM_HEADERSaddsx-openpike-tagsto every request, so its spend shows under the agentclaude-code. Use oneName: Valueper line,\nbetween them in JSON.
For a single terminal session you can set the same variables in your shell instead. On Windows the user settings file is %USERPROFILE%\.claude\settings.json, and the JSON above is the same there. In PowerShell, $env: variables last only for that window.
export ANTHROPIC_BASE_URL=https://api.openpike.devexport ANTHROPIC_AUTH_TOKEN=opk_live_...export ANTHROPIC_DEFAULT_OPUS_MODEL=anthropic/claude-opus-5-5export ANTHROPIC_DEFAULT_SONNET_MODEL=anthropic/claude-sonnet-5-5export ANTHROPIC_DEFAULT_HAIKU_MODEL=anthropic/claude-haiku-5-5export ANTHROPIC_CUSTOM_HEADERS="x-openpike-tags: agent=claude-code"# The settings file is %USERPROFILE%\.claude\settings.json, with the JSON above.$env:ANTHROPIC_BASE_URL = "https://api.openpike.dev"$env:ANTHROPIC_AUTH_TOKEN = "opk_live_..."$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "anthropic/claude-opus-5-5"$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "anthropic/claude-sonnet-5-5"$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "anthropic/claude-haiku-5-5"$env:ANTHROPIC_CUSTOM_HEADERS = "x-openpike-tags: agent=claude-code"In the VS Code extension, set the same names in claudeCode.environmentVariables in VS Code’s user settings.
A run ID per task
Section titled “A run ID per task”A run budget caps one task’s spend, requests and time. Claude Code sends whatever ANTHROPIC_CUSTOM_HEADERS holds, so give each task its own run ID by setting the variable in the shell that starts it, with one header per line:
RUN_ID="fix-login-test-$(date +%s)"export ANTHROPIC_CUSTOM_HEADERS="x-openpike-tags: agent=claude-codex-openpike-run: $RUN_IDx-openpike-run-label: Fix the login test"claude$run = "fix-login-test-$(Get-Date -UFormat %s)"$env:ANTHROPIC_CUSTOM_HEADERS = "x-openpike-tags: agent=claude-code`nx-openpike-run: $run`nx-openpike-run-label: Fix the login test"claudeValues in settings.json are the same for every session, so leave ANTHROPIC_CUSTOM_HEADERS out of it when you set the run in the shell. Every request of that claude session then counts toward the run, and once the run reaches a cap its requests get 429 run_limit_exceeded. Start the next task in a new shell with a new ID.
3. Check it works
Section titled “3. Check it works”- Start
claudeand run/status. The Anthropic base URL line should showhttps://api.openpike.dev, and the auth line should nameANTHROPIC_AUTH_TOKEN. - Send a prompt. A normal answer means the route works.
- Open Logs in OpenPike: the request is there, with the agent
claude-code, the model and its cost.
If Claude Code asks you to log in, it did not find the token: set it in the user settings file or your shell, not only in a project file.
Which models work
Section titled “Which models work”Claude Code speaks only the Anthropic Messages format, so it can use the models OpenPike serves on /v1/messages:
| Models | Model names | Claude Code recognizes them |
|---|---|---|
| Anthropic | anthropic/claude-opus-5-5, anthropic/claude-sonnet-5-5, anthropic/claude-haiku-5-5 |
Yes |
| DeepSeek, through its Anthropic-compatible endpoint | deepseek/deepseek-v4-pro, deepseek/deepseek-flash |
No |
| An alias created with the Messages format | openpike/<name> |
No |
Models from OpenAI, Google and the other providers are served on chat completions only, so Claude Code cannot use them through OpenPike.
Claude Code recognizes a name that contains a Claude model ID it knows, so anthropic/claude-sonnet-5-5 gets Sonnet 5.5’s context window and features. For a name it does not recognize:
- It shows a warning that the model isn’t recognized and which context window it assumes. With
-pit also prints a[claude-code:unrecognized_model]line, even when the window is set. The requests still go through. - It assumes a 1M-token context window, unless you set
CLAUDE_CODE_MAX_CONTEXT_TOKENS. - It turns on features such as extended thinking and effort levels by matching the model name, so these may stay off.
Use DeepSeek models
Section titled “Use DeepSeek models”DeepSeek publishes its own setup for running Claude Code on its models, and OpenPike sends deepseek/... requests on /v1/messages to that same Anthropic-compatible endpoint. Add a DeepSeek key on the Providers page and set:
{ "env": { "ANTHROPIC_BASE_URL": "https://api.openpike.dev", "ANTHROPIC_AUTH_TOKEN": "opk_live_...", "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek/deepseek-v4-pro", "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek/deepseek-flash", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek/deepseek-flash", "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1000000", "ANTHROPIC_CUSTOM_HEADERS": "x-openpike-tags: agent=claude-code" }}DeepSeek’s endpoint ignores some Anthropic fields, such as cache_control and top_k, and does not support redacted_thinking blocks; see DeepSeek’s Anthropic API guide.
Fall back with an alias
Section titled “Fall back with an alias”To fall back to another model when one fails, use an alias as the model:
- On the Routing page, create an alias named
claudewith the format Messages, the policy ordered, and the targetsanthropic/claude-sonnet-5-5thendeepseek/deepseek-flash. The workspace needs a key for both providers. - Set the model variables to the alias, and give Claude Code the context window:
{ "env": { "ANTHROPIC_BASE_URL": "https://api.openpike.dev", "ANTHROPIC_AUTH_TOKEN": "opk_live_...", "ANTHROPIC_DEFAULT_OPUS_MODEL": "openpike/claude", "ANTHROPIC_DEFAULT_SONNET_MODEL": "openpike/claude", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "openpike/claude", "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1000000", "ANTHROPIC_CUSTOM_HEADERS": "x-openpike-tags: agent=claude-code" }}Each request falls back on its own, before any of the response is sent: when Anthropic fails, that request is answered by DeepSeek and the session goes on. Logs shows which model served each request. You can also point only one variable at the alias, for example ANTHROPIC_DEFAULT_SONNET_MODEL, and keep Anthropic names for the others.
CLAUDE_CODE_MAX_CONTEXT_TOKENS
Section titled “CLAUDE_CODE_MAX_CONTEXT_TOKENS”CLAUDE_CODE_MAX_CONTEXT_TOKENS tells Claude Code the context window, in tokens, of a model name it does not recognize. Claude Code compacts the conversation before it reaches that size, so a request never grows beyond what the model accepts.
- It applies on its own to names that Claude Code does not recognize and that do not start with
claude-or contain[1m]. That coversdeepseek/...andopenpike/...names. - It has no effect on recognized names such as
anthropic/claude-sonnet-5-5unless compaction is turned off: Claude Code already knows their window. - Without it, Claude Code assumes 1M tokens for an unrecognized name (200K before Claude Code 2.1.323).
- It is one value for the whole session. With an alias, set it to the smallest context window among the alias’s targets, since any of them may answer.
The Claude and DeepSeek models above all have a 1M-token window, so the examples set 1000000. That is what Claude Code would assume anyway; setting it states the window, and Claude Code no longer warns about an assumed window. If an alias includes a model with a 200K window, set 200000, so Claude Code compacts before that model would reject the request.
Source: Claude Code’s model configuration docs, Correct the window for a gateway or custom model ID.
What to know
Section titled “What to know”- Token counts in
/contextare estimates. OpenPike does not serve/v1/messages/count_tokens, so Claude Code estimates instead. Usage and cost in OpenPike come from the provider’s own counts and are exact. - Not through OpenPike: Remote Control, voice dictation, Claude Code in Slack and cloud sessions, which need a claude.ai login or run on Anthropic’s side.
Set it up with a skill
Section titled “Set it up with a skill”The OpenPike skills repo has an openpike-setup skill that Claude Code can use to point a project at OpenPike from a one-line request. It never asks for or writes a provider key. Install steps are in the repo’s README.
Example
Section titled “Example”A runnable copy of this setup, with a .env.example, is in the OpenPike examples repo.