A 200 response from an AI gateway proves that one HTTP request worked. It does not prove that Claude Code can discover a model, send the right Messages payload, recover from an optional endpoint failure, and finish a task.
That distinction matters when Claude Code is configured through an Anthropic-compatible gateway such as XiuRouter.
This guide uses a two-layer acceptance test:
- Send a small request directly to
/v1/messages. - Run a complete short task in Claude Code.
If the first layer fails, debug the gateway configuration. If it passes but the second layer fails, debug the client workflow instead of rotating keys or changing models at random.
Configure the API root, not the Messages path
Claude Code appends /v1/messages to the configured base URL. Set the API root without /v1:
export ANTHROPIC_BASE_URL="https://router-api.xiu.ai"
export ANTHROPIC_AUTH_TOKEN="YOUR_XIUROUTER_API_KEY"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"
ANTHROPIC_AUTH_TOKEN sends a Bearer token, which XiuRouter accepts on the Messages route. Gateway model discovery lets Claude Code load models exposed by the configured gateway.
A base URL ending in /v1 produces the duplicated path:
https://router-api.xiu.ai/v1/v1/messages
That is a configuration error, not a model error.
Test /v1/messages before opening Claude Code
Use an exact model ID visible to the intended XiuRouter key. Do not copy a model ID from an old article or another service group.
curl -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "YOUR_MODEL_ID",
"max_tokens": 32,
"messages": [
{
"role": "user",
"content": "Reply only with: connected"
}
]
}'
The response should be JSON with a Messages content value. Check more than the status code:
- The body is JSON, not an HTML error page returned by a proxy.
- The response contains text content.
- The model and usage fields are plausible for the request.
- The request appears in the expected XiuRouter usage records.
An HTTP 200 with an empty body, malformed JSON, or HTML is still a failed integration.
Then test the Claude Code workflow
Start Claude Code in a non-critical repository:
claude
Use /model and select a model marked From gateway. Run /status and confirm the Anthropic base URL and gateway credential are active.
The test task should exercise the client, not just produce a greeting. For example:
Read package.json and report the package manager, test command, and build command.
Do not edit any files.
A useful pass condition is:
- Claude Code discovers a gateway model.
- The task starts without an authentication or payload error.
- The client receives a usable Messages response.
- The task reaches a final answer.
- The corresponding gateway request is visible in usage records.
This catches failures that a standalone curl request cannot expose.
Treat count_tokens 404 as a workflow signal
XiuRouter does not expose a dedicated /v1/messages/count_tokens route. Claude Code documents token counting as optional and can fall back through the inference endpoint.
Do not classify the connection as broken from that 404 alone. Check what happens next:
- If Claude Code falls back to
/v1/messagesand completes the task, the missing optional route did not block the workflow. - If the task stops after the 404, capture the client version and logs, then diagnose the client behavior.
The pass condition is task completion, not the absence of every warning.
Failure patterns and the shortest useful check
401 or invalid token
Confirm that the variable is ANTHROPIC_AUTH_TOKEN, the key is active, and the shell that starts Claude Code actually contains the variable.
If Claude Code reports multiple credential sources, run /logout to use the gateway credential, or unset the gateway variables to keep the saved Claude login. Do not leave both paths ambiguous.
Gateway models do not appear
Confirm:
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"
Restart Claude Code after changing the environment. Also verify that the intended key can see at least one Claude model.
The request path is /v1/v1/messages
Remove /v1 from ANTHROPIC_BASE_URL. The correct value is:
https://router-api.xiu.ai
A 400 response names experimental fields
Retry with:
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS="1"
This is narrower than changing the model, key, and gateway at the same time.
HTTP 200 contains HTML
Inspect the response content-type and body. A CDN, login wall, or proxy can return an HTML page with a successful transport status. The direct curl test should return Messages JSON.
Direct Messages works, but Claude Code still fails
Keep the successful curl response as evidence and narrow the remaining variables:
- Claude Code version
- selected gateway model
- active environment variables
- credential-source warning
- optional endpoint fallback
- experimental request fields
Changing one variable at a time preserves the known-good gateway result.
Roll back without leaving mixed credentials
For the CLI, unset the gateway variables and restart Claude Code:
unset ANTHROPIC_BASE_URL
unset ANTHROPIC_AUTH_TOKEN
unset CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY
unset CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS
Run /status after restart and confirm that the previous connection is active.
For the VS Code extension or Claude desktop Code, restore the previous environment or Third-Party Inference configuration, restart the application, and run the same status check.
References
These references were reviewed on August 30, 2026. Model availability can change, so use the current catalogue and an exact model ID visible to the intended key.
XiuAI and its products are operated by XiuLab Inc, a U.S. corporation.
Top comments (0)