Use Claude Code with a Third-party API
Claude Code can connect to third-party services with an Anthropic-compatible API. Pick a provider to generate settings.json or environment variables from the endpoint in its docs; you add the API key on your own machine.
By provider
These providers document their endpoint. Open one to generate the config and see what each model costs there.
Enter manually
If your provider is not listed, enter the endpoint and model name from its docs.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.example.com/anthropic",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
"ANTHROPIC_API_KEY": ""
}
}
How it works
Claude Code talks to models over the Anthropic Messages API. ANTHROPIC_BASE_URL is the endpoint. The key goes in ANTHROPIC_AUTH_TOKEN (sent as a Bearer token; ANTHROPIC_API_KEY is then set to empty so a key already on your machine is not sent too) or in ANTHROPIC_API_KEY (sent as x-api-key), as the provider's docs say. ANTHROPIC_MODEL and ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_FABLE_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL choose the model for each tier; the Haiku tier is also used for small background tasks. Anthropic does not guarantee compatibility when non-Claude models are used through third-party APIs; follow the provider's docs.
FAQ
settings.json or environment variables?
settings.json applies every time Claude Code starts, for long-term use; the environment variables apply to the current terminal only, for a quick try.
How do I switch back to Anthropic?
Remove these variables from settings.json (or close the terminal where you set them), then restart Claude Code.
Does my key pass through this site?
No. The page only generates config text and never asks for your key; the key only goes into the config file or terminal on your own machine.