Connect Claude Code to ROIBest AI in Three Steps
Claude Code talks to Anthropic's endpoint by default. Pointing it at ROIBest AI takes two environment variables — no config file, no plugin, no changes to your project.
Before you start
You need an API key from the Anthropic-compatible group. This is where most setups go wrong: ROIBest AI issues keys per protocol group. Anthropic-compatible keys work against /v1/messages; OpenAI-compatible keys work against /v1/chat/completions and /v1/responses. An OpenAI-group key in Claude Code returns 401, and the error will not tell you the group is the problem.
In the console, go to API Keys, create a key in the Anthropic-compatible group, and copy it immediately — it is shown in full only once.
Step 1: Set the environment variables
export ANTHROPIC_BASE_URL="https://ai.roibest.com"
export ANTHROPIC_AUTH_TOKEN="your-key"Two things worth noting:
ANTHROPIC_BASE_URLis the domain only — do not append/v1. Claude Code adds/v1/messagesitself, so an extra segment produces/v1/v1/messagesand a 404.- Use
ANTHROPIC_AUTH_TOKEN, notANTHROPIC_API_KEY. The former is what Claude Code provides for third-party gateways and is sent asAuthorization: Bearer. The gateway also acceptsx-api-key, but setting both variables invites one silently overriding the other.
To make this persistent, add both lines to ~/.zshrc or ~/.bashrc and source the file once.
Step 2: Verify the connection
Before launching Claude Code, hit the endpoint directly. This separates "is the gateway reachable" from "is the client configured correctly":
curl https://ai.roibest.com/v1/messages \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 64,
"messages": [{"role": "user", "content": "ping"}]
}'A normal response means the key, the group and the URL are all correct. Now start the client:
claudeStep 3: Confirm the usage was recorded
Run one conversation, then open the usage records in the console. Every request logs the model, the protocol group, input and output tokens, cache tokens, the billing mode, the cost and the latency.
This step is not a formality. It is the only way to confirm the request actually went through ROIBest AI — if the environment variables did not take effect, Claude Code quietly falls back to the official endpoint, the conversation works normally, and you find out when the bill arrives.
Troubleshooting
401 with a freshly created key Check the protocol group first — only Anthropic-compatible keys reach /v1/messages. Then confirm the variable is actually set in this shell: echo $ANTHROPIC_BASE_URL. A new terminal window that never sourced your shell config is the most common cause.
404, or two /v1 segments in the path ANTHROPIC_BASE_URL was set to https://ai.roibest.com/v1. Drop the trailing /v1.
The model name is rejected Available models depend on your account and group. Look up the current names in the console's model directory and copy them — do not type them from memory.
Switching back to the official endpoint unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN and open a new terminal. The two setups do not interfere with each other.
Summary
Connecting Claude Code to a gateway is really just a URL and a key. The two things that actually cost people time are picking the wrong protocol group and appending /v1 to the base URL. One curl call before launching the client catches both.