LLM Gateway
Guides

Claude Code Integration

Use GPT-5, Gemini, or any model with Claude Code. Three environment variables, full cost tracking.

Claude Code is locked to Anthropic's API by default. With LLM Gateway, you can point it at any model—GPT-5, Gemini, Llama, or 180+ others—while keeping the same Anthropic API format Claude Code expects.

Three environment variables. No code changes. Full cost tracking in your dashboard.

Using DevPass? This integration also works with a DevPass plan key. Use root model IDs without a provider prefix (claude-sonnet-4-5, not anthropic/claude-sonnet-4-5) — provider-pinned routing is not available on coding plans; the gateway picks the provider for you.

Setup

Sign Up for LLM Gateway

Sign up free — no credit card required. Copy your API key from the dashboard.

Set Environment Variables

Configure Claude Code to use LLM Gateway:

export ANTHROPIC_BASE_URL=https://api.llmgateway.io
export ANTHROPIC_AUTH_TOKEN=llmgtwy_your_api_key_here
# optional: specify a model, otherwise it uses the default Claude model
export ANTHROPIC_MODEL=gpt-5  # or any model from our catalog

Run Claude Code

claude

All requests will now be routed through LLM Gateway.

Why This Works

LLM Gateway's /v1/messages endpoint speaks Anthropic's API format natively. We handle the translation to each provider behind the scenes. This means:

  • Use any model — GPT-5, Gemini, Llama, or Claude itself
  • Keep your workflow — Claude Code doesn't know the difference
  • Track costs — Every request appears in your LLM Gateway dashboard
  • Automatic caching — Repeated requests hit cache, saving money

Choosing Models

You can use any model from the models page.

Use OpenAI's Latest Models

# Use the latest GPT model
export ANTHROPIC_MODEL=gpt-5

# Use a cost-effective alternative
export ANTHROPIC_MODEL=gpt-5-mini

Use Google's Gemini

export ANTHROPIC_MODEL=gemini-3.1-pro-preview

Use Anthropic's Claude Models

export ANTHROPIC_MODEL=anthropic/claude-3-5-sonnet-20241022

Predefining Models in a Settings File

Environment variables are read once at startup, so changing ANTHROPIC_MODEL means restarting Claude Code. To switch models mid-session instead, put the configuration in ~/.claude/settings.json (user-wide) or .claude/settings.json (per project) and use /model to switch on the fly:

~/.claude/settings.json
{
	"env": {
		"ANTHROPIC_BASE_URL": "https://api.llmgateway.io",
		"ANTHROPIC_AUTH_TOKEN": "llmgtwy_your_api_key_here"
	},
	"model": "claude-sonnet-5"
}

model sets the model a new session starts on. /model overrides it for the running session and saves your choice as the new default.

Restricting the Model List

availableModels limits which models the /model picker offers — useful for keeping a team on an approved, budget-appropriate set:

~/.claude/settings.json
{
	"availableModels": ["claude-sonnet-5", "claude-haiku-4-5"],
	"fallbackModel": ["claude-haiku-4-5"]
}

fallbackModel names the models to try when the primary one is unavailable, capped at three.

availableModels only filters the rows Claude Code already has — it never creates new ones. To put a non-Claude model in the picker, see Adding Non-Claude Models to the Picker.

Fetching Models From LLM Gateway

Claude Code can populate its /model picker directly from our catalog instead of you hardcoding IDs. Set the discovery flag alongside the base URL:

export ANTHROPIC_BASE_URL=https://api.llmgateway.io
export ANTHROPIC_AUTH_TOKEN=llmgtwy_your_api_key_here
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1

On startup Claude Code calls our /v1/models endpoint and adds what it returns to the picker, labeled From gateway. Entries are cached in ~/.claude/cache/gateway-models.json and refreshed on each launch, so a failed lookup falls back to the previous list rather than breaking your session. Requires Claude Code v2.1.129 or later.

The LLM Gateway CLI can apply this whole setup (base URL, auth token, and the discovery flag) to your ~/.claude/settings.json in one command:

npx @llmgateway/cli configure claude

Claude Code drops discovered models whose ID does not start with claude or anthropic, before they ever reach the picker — the cache it writes to ~/.claude/cache/gateway-models.json contains only the surviving entries. Discovery therefore surfaces just the Claude models in our catalog. GPT-5, Gemini, and custom models are filtered out by the client, not by the gateway.

Adding Non-Claude Models to the Picker

The /model picker is a Claude-model list. Its own header says so: "Switch between Claude models… For other/previous model names, specify with --model." Neither gateway discovery nor availableModels adds a non-Claude row — availableModels filters the rows Claude Code already has rather than creating new ones.

ANTHROPIC_CUSTOM_MODEL_OPTION is the one setting that adds a non-Claude row:

export ANTHROPIC_CUSTOM_MODEL_OPTION=gemini-3.5-flash
export ANTHROPIC_CUSTOM_MODEL_OPTION_NAME="Gemini 3.5 Flash"
export ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION="Routed through LLM Gateway"

The entry appears at the bottom of the picker under your chosen name. Only one is supported at a time, so it suits a single alternate model rather than a menu. If you also set availableModels, include this ID there or it will be filtered back out.

Selecting Any Other Model

For everything else — including custom models — name the model directly. These paths accept any ID our gateway routes, with no picker row involved:

export ANTHROPIC_MODEL=gemini-3.5-flash   # session default
claude --model gemini-3.5-flash           # single session

To rotate between several non-Claude models, keep a per-project .claude/settings.json with the model you want for that repo.

Environment Variables

ANTHROPIC_MODEL

Specifies the main model to use for primary requests.

export ANTHROPIC_MODEL=gpt-5

Complete Configuration Example

export ANTHROPIC_BASE_URL=https://api.llmgateway.io
export ANTHROPIC_AUTH_TOKEN=llmgtwy_your_api_key_here
export ANTHROPIC_MODEL=gpt-5
export ANTHROPIC_SMALL_FAST_MODEL=gpt-5-nano

Making Manual API Requests

If you want to test the endpoint directly, you can make manual requests:

curl -X POST "https://api.llmgateway.io/v1/messages" \
  -H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5",
    "messages": [
      {"role": "user", "content": "Hello, how are you?"}
    ],
    "max_tokens": 100
  }'

Response Format

The endpoint returns responses in Anthropic's message format:

{
	"id": "msg_abc123",
	"type": "message",
	"role": "assistant",
	"model": "gpt-5",
	"content": [
		{
			"type": "text",
			"text": "Hello! I'm doing well, thank you for asking. How can I help you today?"
		}
	],
	"stop_reason": "end_turn",
	"stop_sequence": null,
	"usage": {
		"input_tokens": 13,
		"output_tokens": 20
	}
}

What You Get

  • Any model in Claude Code — GPT-5 for heavy lifting, GPT-4o Mini for routine tasks
  • Cost visibility — See exactly what each coding agent costs
  • One bill — Stop managing separate accounts for OpenAI, Anthropic, Google
  • Response caching — Repeated requests (like linting the same file) hit cache
  • Discounts — Check discounted models for savings up to 90%

View all available models on the models page.

Need help? Join our Discord community for support and troubleshooting assistance.

How is this guide?

Last updated on

On this page

Ready for production?

Ship to production with SSO, audit logs, spend controls, and guardrails your security team will approve.

Explore Enterprise