Claude Code
Route Claude Code through OpenGateway's Anthropic Messages API with an isolated claude-opengateway alias, verified model settings, and a reusable setup.
claude-opengateway alias and saves it as the opengateway-claude-code skill.Run it once, nothing saved#
For a one-session test, replace the key placeholder and run this command. It does not write to a shell profile or Claude Code settings file.
ANTHROPIC_BASE_URL="https://apis.opengateway.ai" \ANTHROPIC_AUTH_TOKEN="YOUR_OPENGATEWAY_API_KEY" \ANTHROPIC_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" \ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" \ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" \ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" \CLAUDE_CODE_SUBAGENT_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" \claude
Set it up by hand#
1. Get an API key#
opengateway.ai → API Keys → Create Key. The key is shown once.
2. Add the launcher#
Append this line to ~/.zshrc or ~/.bashrc, replacing the key placeholder.
The trailing tag identifies the line for later removal.
alias claude-opengateway='ANTHROPIC_BASE_URL="https://apis.opengateway.ai" ANTHROPIC_AUTH_TOKEN="YOUR_OPENGATEWAY_API_KEY" ANTHROPIC_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" CLAUDE_CODE_SUBAGENT_MODEL="deepseek/deepseek-v4.1-flash-ultrafast" claude' # opengateway-claude-code
The alias sets the base URL to the host root; Claude Code appends
/v1/messages. ANTHROPIC_AUTH_TOKEN sends the key as Authorization: Bearer. Do not append /v1 to the base URL.
ANTHROPIC_MODEL selects the launch model. Use /model to switch inside a
session; a --model argument also overrides the environment value for that
run. The ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, and
ANTHROPIC_DEFAULT_HAIKU_MODEL variables map those aliases to the chosen
OpenGateway model. CLAUDE_CODE_SUBAGENT_MODEL sets the default for subagents
that are not assigned a model another way. ANTHROPIC_SMALL_FAST_MODEL is
deprecated; use the Haiku default variable instead.
Claude Code sends Anthropic Messages-format requests. A gateway must handle
/v1/messages and forward the features Claude Code uses. Anthropic states
that it does not support routing Claude Code to non-Claude models through
third-party gateways.
Use deepseek/deepseek-v4.1-flash-ultrafast as the recommended UltraFast
model; z-ai/glm-5.3-flash-ultrafast is the cheaper alternative. Both are
active in the model catalog, support /v1/messages, and have a
1M-token context window. For another model, choose an active catalog entry
whose endpoints include messages.
UltraFast has a per-key in-flight request limit for each model. Parallel
subagents can exceed it and receive 429 with
concurrency_limit_exceeded and Retry-After; OpenGateway rejects excess
requests immediately without sending them upstream. Reduce parallel work or
wait before retrying, or contact support to request a higher limit. See
UltraFast for details. For either of these two
models, a request with more than 256K input tokens has
double the input-token price for the whole request; cache reads and output
tokens are not included in that surcharge. Shared prompt prefixes can benefit
from automatic prompt caching, so keep stable instructions and tools at the
beginning of the prompt. Check
/models for current pricing and any active time-based pricing.
3. Run the launcher#
source ~/.zshrc # or open a new terminalclaude-opengateway
claude-opengateway uses OpenGateway while plain claude keeps its existing
configuration.
4. Verify#
claude-opengateway --print "Reply with OK"
In an interactive session, /status shows the active base URL and credential
source. A response confirms the connection; usage appears on the
dashboard.
Make OpenGateway the default#
For a persistent user-level configuration, put the same variables in the
env block of ~/.claude/settings.json. Keep this personal file out of a
project repository; do not put an API key in a shared .claude/settings.json.
{"env": {"ANTHROPIC_BASE_URL": "https://apis.opengateway.ai","ANTHROPIC_AUTH_TOKEN": "YOUR_OPENGATEWAY_API_KEY","ANTHROPIC_MODEL": "deepseek/deepseek-v4.1-flash-ultrafast","ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek/deepseek-v4.1-flash-ultrafast","ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek/deepseek-v4.1-flash-ultrafast","ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek/deepseek-v4.1-flash-ultrafast","CLAUDE_CODE_SUBAGENT_MODEL": "deepseek/deepseek-v4.1-flash-ultrafast"}}
Use the Anthropic SDK#
The Anthropic SDK's authToken / auth_token option sends
Authorization: Bearer, which works for OpenGateway endpoints. The default
apiKey / api_key option sends x-api-key; /v1/messages accepts it only when the request carries no
Authorization header. If both headers are sent,
Authorization takes precedence. An empty or invalid Bearer value returns
401 without falling back to x-api-key.
import Anthropic from "@anthropic-ai/sdk";const anthropic = new Anthropic({baseURL: "https://apis.opengateway.ai",authToken: process.env.OPENGATEWAY_API_KEY,});const response = await anthropic.messages.create({model: "deepseek/deepseek-v4.1-flash-ultrafast",max_tokens: 256,messages: [{ role: "user", content: "Hello" }],});
import osfrom anthropic import Anthropicclient = Anthropic(base_url="https://apis.opengateway.ai",auth_token=os.environ["OPENGATEWAY_API_KEY"],)response = client.messages.create(model="deepseek/deepseek-v4.1-flash-ultrafast",max_tokens=256,messages=[{"role": "user", "content": "Hello"}],)