Moving from the direct Anthropic API to a gateway barely touches your code. The base URL and the key change, and the model names need a check. Most of the time goes into testing, because the tests show what exactly behaves differently in your project. Below are five steps, in the order that is easiest to follow.
What changes in the move and what stays
| Parameter | Direct Anthropic | codexkey gateway |
|---|---|---|
| Base URL for the Anthropic SDK | https://api.anthropic.com | https://api.codexkey.online |
| Base URL for the OpenAI SDK | not applicable | https://api.codexkey.online/v1 |
| Key | sk-ant-... | sk_cdx_... |
| Model name | Anthropic ID | Stable gateway IDs, check them against GET /v1/models |
| Payment | Foreign card | Russian card or SBP (the Russian Faster Payments System) in rubles, crypto also accepted |
| Request format | Messages API | The same Messages API, plus Chat Completions on the same endpoint |
Model prices are quoted in dollars per million tokens; current values are on the models page. Top-ups by Russian card or through SBP are made in rubles.
SDK calls, the message structure, system, tools and streaming work as before. If the project is written against the OpenAI SDK, you can keep the client as it is; the details are in the OpenAI-compatible migration guide.
Step 1. Key and balance
Sign up at codexkey, create a sk_cdx_... key in the "API Keys" section and put a small amount on the balance. When you create the key you choose a channel (Premium or Cheap) and an expiry. Start with Premium: it has Haiku, and Cheap does not.
Keep the key in a secrets manager or in a .env file that never reaches git. Do not hardcode it in the source.
Step 2. Swap the base URL and the key
For Python and the Anthropic SDK:
import os
import anthropic
client = anthropic.Anthropic(
base_url=os.environ["LLM_BASE_URL"],
api_key=os.environ["LLM_API_KEY"],
)
For TypeScript:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: process.env.LLM_BASE_URL,
apiKey: process.env.LLM_API_KEY,
});
In the environment set LLM_BASE_URL=https://api.codexkey.online, LLM_API_KEY=sk_cdx_... and LLM_MODEL with the model name. Write the URL without /v1: the Anthropic SDK appends the /v1/messages path itself.
If the code uses the OpenAI SDK, the base URL carries /v1:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.codexkey.online/v1",
api_key=os.environ["LLM_API_KEY"],
)
For Claude Code, an env block in ~/.claude/settings.json is enough; it is covered in the setup guide. Instructions for Cursor, Cline and other editors are collected in the guides.
Step 3. Match the model names
The list of models available to your key comes from GET https://api.codexkey.online/v1/models. Compare it with what is set in your code and configs. If a model is requested by a name that is not in the list, the gateway returns an error. A Cheap-channel key that asks for Haiku gets model_not_in_channel: Cheap does not have that model, Premium does.
Look in the hidden places too. Model names like to hide in CI configuration, in background-job settings and in parameters nobody has opened for a long time.
Step 4. Run the checks
Start with the shortest possible request:
curl -sS -w '\n%{http_code}\n' https://api.codexkey.online/v1/messages \
-H "x-api-key: $LLM_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"claude-sonnet-5","max_tokens":1,"messages":[{"role":"user","content":"."}]}'
Then work through the list. Send each item as its own request and do not rely on a feature description on a website: that way you see how your own code behaves.
| What to check | How |
|---|---|
| A plain response | A one-token request, then a request with your typical prompt |
| Streaming | Turn on stream, compare the event order and the final text |
| Tools | A call with tools; check that the response contains tool_use and your code parses it |
| Images and files | If you send them, run a real example |
anthropic-beta headers | If you use them, test each header on its own |
| The heaviest prompt | The largest context you actually send |
| Errors | A wrong key and a wrong model name, to see how your code survives a refusal |
Compare cost using the usage field in the response: multiply input and output tokens by the price from the catalog. That gives you actual spend rather than an estimate.
Step 5. Ramp traffic up gradually
While the direct channel still works, do not move all traffic at once. Keep the gateway's share in a variable and raise it in steps:
import os
import random
def pick_base_url() -> str:
share = float(os.environ.get("GATEWAY_SHARE", "0"))
use_gateway = random.random() < share
return os.environ["GATEWAY_URL"] if use_gateway else os.environ["DIRECT_URL"]
Start at 5% and watch the error rate and response time. After a day raise it to 25%, then to 100%. If you have no direct channel, this step falls away: the checks from step 4 are your pilot.
Rolling back in a minute
You always need a rollback, even when everything went smoothly. That is why the base URL, the key and the model live in environment variables. To go back, change three values (LLM_BASE_URL, LLM_API_KEY, LLM_MODEL) and restart the service. The code stays untouched and no deploy is needed. If something stops responding after the switch, start with the troubleshooting article. If your Anthropic account is blocked, the recovery plan is in the article on blocked Claude accounts, and exporting your chat data is covered in the data export guide.
What Anthropic says about gateways and what happens to your data
The Claude Code documentation is blunt: Anthropic does not endorse, maintain or audit third-party gateways, and it does not support routing Claude Code to non-Claude models. Any gateway remains the infrastructure of its operator. Your prompts and responses pass through it, so read the service's privacy policy and decide whether it meets your requirements. What you should never send to a model, whichever provider you use, is covered in what not to send to an LLM, and security questions are collected in the security and compliance article.
Moving to a gateway does not make Anthropic's regional policy go away. The regional policy page takes effect on November 12, 2026, and it does not say what that means for third-party gateways. We do not give legal opinions; a checklist for this case is in what to do before November 12.
FAQ
Do I need to rewrite my code to move to a gateway?
Usually not. The base URL, the key and sometimes the model name change. The client library, the message structure, tools and streaming stay as they were.
Which base URL do I set in the Anthropic SDK?
https://api.codexkey.online without /v1. OpenAI-compatible clients need the URL with /v1: https://api.codexkey.online/v1.
Why does the gateway return model_not_in_channel?
The requested model is not in your key's channel. Haiku is available in Premium and not in Cheap. Check the key's channel in your account and take the model list from GET /v1/models.
How do I pay for the API in rubles?
The balance is topped up by Russian card or through SBP in rubles, and crypto is also accepted. Model prices are quoted in dollars per million tokens on the models page.
How do I roll back if something goes wrong?
Restore the previous values of the base URL, the key and the model in your environment variables and restart the service. That is why these three parameters should not be hardcoded.