ANSWERS / ENGLISH

Configure Claude Code with a third-party relay

The environment variables, a verification step, and the errors you will hit first.

Reviewed 2026-11-12 · Chinese detail: 完整中文页

What you need

A relay that exposes an Anthropic-compatible endpoint, a key for that relay, and the relay's base URL. Claude Code reads its endpoint and credential from environment variables, so no source code changes are required.

Configure

Set the base URL and the auth token in the environment that launches Claude Code. Keep the official login flow separate; do not overwrite a working official configuration until the relay is verified.

A typical setup uses ANTHROPIC_BASE_URL for the relay endpoint and ANTHROPIC_AUTH_TOKEN for the key. Check your Claude Code version's documentation for the exact variable names before changing a production shell profile.

Verify

Start a new shell, run a single short prompt, and confirm the response arrives. Then check the relay dashboard to see which model was actually billed. If the dashboard shows a different model than you requested, stop and fix the mapping before using it for real work.

First errors

401: the token is missing, has whitespace, or the variable name is wrong.

404: the base URL is missing a path segment or points at an OpenAI-style endpoint.

Model not found: the relay uses different model IDs; copy the ID from its model list.

Keep it reversible

Put the relay configuration in a shell function or a project-specific environment file, not in your global profile. That way you can switch back to the official endpoint by closing the shell.

This page is general guidance, not a statement about any specific provider. For measured data, see the relay directory and method.