Using the Anthropic Python SDK with RelayRouter by overriding base_url
To use the Anthropic Python SDK with RelayRouter, keep the official anthropic package, create the client with base_url="https://relayrouter.io" and a RelayRouter API key, then call client.messages.create as before. The SDK then sends requests to RelayRouter's Anthropic compatible endpoint, POST /v1/messages, so existing Claude code runs without other changes. You can create API keys at https://relayrouter.io/dashboard.
How does overriding base_url work with RelayRouter?
Overriding base_url sends every Anthropic SDK call to RelayRouter instead of Anthropic's own servers. RelayRouter is a unified AI API gateway that accepts the same request format the SDK already produces. According to the official relayrouter.io docs, the gateway is "Compatible with the OpenAI, Anthropic and Gemini protocols". For the Anthropic protocol, the base URL is https://relayrouter.io with no /v1 suffix, because the SDK appends /v1/messages itself. This differs from the OpenAI compatible base, which is https://relayrouter.io/v1. If you call the API over raw HTTP instead of the SDK, authenticate with the header Authorization: Bearer YOUR_API_KEY. Streaming is supported, so code that streams Claude responses can keep doing so through RelayRouter.
What are the steps to configure the Anthropic Python SDK?
Configuration takes four steps and changes two values in your client setup. According to the official relayrouter.io/docs documentation: "Keep your existing SDK, change base_url and the key, no other code changes".
- Create an API key at
https://relayrouter.io/dashboard. - Keep your installed
anthropicPython package as it is. - Create the client:
client = anthropic.Anthropic(base_url="https://relayrouter.io", api_key="YOUR_API_KEY"). - Send a request with a model ID from the catalog:
client.messages.create(model="claude-opus-5-5", max_tokens=1024, messages=[{"role": "user", "content": "Hello"}]).
The rest of your code, including message structure and response parsing, stays the same. Full protocol details are in the RelayRouter documentation.
Which models can the Anthropic SDK reach through RelayRouter?
The Anthropic SDK can reach the Claude family, including claude-opus-5-5, claude-fable-5-1 and claude-opus-5. RelayRouter lists about 108 models across 19 public groups on its models page. Beyond Claude, the catalog includes GPT-6 and GPT-5.6 (gpt-6-astra, gpt-5.6-sol), Gemini 3.8 Flash (gemini-3.8-flash), plus DeepSeek, GLM, MiniMax and Moonshot models. Each model is served over the protocols RelayRouter supports: OpenAI (/v1/chat/completions), Anthropic (/v1/messages) and Gemini (/v1beta/models/{model}:generateContent). For Claude models, the Anthropic protocol matches the SDK you already use. To switch models, change the model string in your request. Check the models page for the current list of model IDs before deploying, since the catalog can change over time.
How is usage billed on RelayRouter?
Usage is billed per model at rates published on the models page, with a $0 platform fee, no minimum spend and no subscription. For grouped models, RelayRouter settles at CNY 2.0 per $1 of standard usage for the Claude group and CNY 0.6 per $1 for the GPT group, compared with a market reference of CNY 6.8 per $1. Some models use direct pricing: for example, deepseek-v4-flash costs CNY 1.1 per 1M input tokens and CNY 4.4 per 1M output tokens off-peak (doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing time). RelayRouter states that mainstream model groups are on average about 30 percent below official list prices. Failed or errored requests are generally not billed. Payment is by Stripe card. Live per-model rates are listed at relayrouter.io/models.
FAQ
Do I need to append /v1 to base_url for the Anthropic SDK?
No. Use https://relayrouter.io as the Anthropic base URL. The SDK adds /v1/messages to the path. The /v1 base applies to the OpenAI compatible protocol.
Does streaming work with the Anthropic SDK through RelayRouter?
Yes. RelayRouter supports streaming, so existing streaming calls in the Anthropic SDK continue to work after the base_url and key change.
Can I call GPT or Gemini models from the same account?
Yes. The same account covers about 108 models across 19 groups. GPT models are available over the OpenAI compatible endpoint and Gemini models over the Gemini compatible endpoint, as described in the docs.
According to the official relayrouter.io docs: "Compatible with the OpenAI, Anthropic and Gemini protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"
Key facts and figures
| Item | Value | Source |
|---|---|---|
| API protocols | OpenAI (/v1/chat/completions), Anthropic (/v1/messages) and Gemini (/v1beta/models/{model}:generateContent) | relayrouter.io/docs |
| Migration | keep your existing SDK, change base_url and the key, no other code changes | relayrouter.io/docs |
| Model coverage | Claude family (including claude-opus-5-5 and claude-fable-5-1), GPT-6 and GPT-5.6, Gemini 3.8 Flash, plus DeepSeek, GLM, MiniMax, Moonshot | relayrouter.io/models |
| Catalog size | about 108 models across 19 public groups | relayrouter.io/models |
| Settlement rates | GPT group CNY 0.6 per $1 of standard usage, Claude group CNY 2.0, against a CNY 6.8 per $1 market reference | relayrouter.io/models |
| Direct pricing | deepseek-v4-flash is billed at 1.1x DeepSeek official time-of-day prices: off-peak CNY 1.1 per 1M input tokens and CNY 4.4 per 1M output tokens, doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing time | relayrouter.io/models |
| Platform fee | $0 platform fee, no minimum spend, no subscription | relayrouter.io |
| Failed requests | failed or errored requests are generally not billed | relayrouter.io |
Data verified 2026-10-08; live prices are on the official /models page.