Tool Integration

Claude Code API setup: custom Base URL and Anthropic Messages

Configure ANTHROPIC_BASE_URL, authentication variables and model mappings for the Claude Code API. Distinguish Anthropic Messages from OpenAI Compatible and verify streaming and tool calls with a minimal task.

Updated November 4, 2026Checked on 2026-10-08Estimated reading time: 7 minutesFor Claude Code third-party gateway
Configuration fields were checked against public documentation. Models, prices, and capabilities can change; verify current values in the console and live API responses.
Topic: What Is an OpenAI-Compatible API? Scope and Limits

Ready to connect to AIFast Link? Create an account and an API key, then follow the setup and verification steps below.

Check costs first: Specific-group price comparison · Usage and monthly-plan terms. The price example does not cover every model. GPT/Claude monthly plans and the separate Gemini group are billed separately.

Create an account to get started Already registered? Open the console

Claude Code natively uses Anthropic API semantics. OpenAI Compatible is not equivalent to Anthropic Compatible. Before configuring, you must confirm that the current service clearly provides a Claude Code or Anthropic protocol compatible entry; you cannot directly fill in the OpenAI Base URL with Claude Code just because the model name contains Claude.

Quick conclusion

Before routing Claude Code through a third-party gateway, confirm that the service explicitly supports Anthropic Messages, continuous streaming events, and tool calls. After setting ANTHROPIC_BASE_URL and the authentication variable, use a read-only task to verify the final host and Messages path. Then test file writes, command execution, and long-running tasks. A successful chat response does not prove full Agent workflow compatibility.

Can Claude Code use OpenAI Compatible Base URL directly?

Usually, no. Claude Code requires Anthropic Messages semantics, continuous streaming events, and tool calls. The OpenAI-style chat endpoint is /v1/chat/completions, but support for this endpoint alone does not prove Claude Code compatibility. Configure the corresponding URL only when the service explicitly documents a Claude Code or Anthropic-compatible endpoint. Set it in ANTHROPIC_BASE_URL. Authentication variables and model mappings must also be configured according to the service's instructions.

If a gateway offers both OpenAI and Anthropic protocols, test them independently. A successful OpenAI SDK response does not replace a Claude Code test:

Check before you start

  • Confirm the supported Claude Code protocol and gateway endpoint in the Link API documentation or with support.
  • Confirm that the service provides an Anthropic-compatible API, not just an OpenAI Compatible API.
  • Create an independent Key for Claude Code and do not share it with the production service.

Configuration steps

This template applies to the current terminal without changing global configuration. First confirm Anthropic Messages access for your Link account and model; the template alone does not prove tool-call compatibility. Find the model ID in the Link model catalog; copy the model ID rather than the display name.

export ANTHROPIC_BASE_URL="https://www.aifast.link"
export ANTHROPIC_AUTH_TOKEN="YOUR_LINK_API_KEY"
export ANTHROPIC_MODEL="YOUR_CLAUDE_MODEL_ID"
claude --version
claude --model "$ANTHROPIC_MODEL"

Replace both placeholders with your Link key and an available model ID. This template uses Bearer authentication. Follow your account instructions if they require another method, and remove conflicting authentication variables.

client Example Base URL Expected request path
Claude Code / Anthropic Messages https://www.aifast.link /v1/messages
OpenAI Compatible SDK https://www.aifast.link/v1 Append the protocol-specific path /chat/completions or /responses

For this Claude Code example, do not append /v1 or the full endpoint /v1/messages. If logs show /v1/v1/messages, fix the URL construction first. Rotating keys will not fix an incorrect path.

Check the variables in the same terminal without printing the full key. These exports do not automatically carry over to another terminal:

test -n "$ANTHROPIC_BASE_URL" && echo "Base URL Already set"
test -n "$ANTHROPIC_AUTH_TOKEN" && echo "Authentication variables are set"

Why does Claude Code still use the old endpoint after setting ANTHROPIC_BASE_URL?

An exported variable only establishes the shell configuration. After starting Claude Code, run /status to check the active Base URL and credential source. A settings-file env block can override shell variables, and an editor launched from the desktop may not inherit your terminal environment. Identify and resolve conflicts before restarting the client; do not overwrite the entire settings file.

Where to check What to verify Investigate first
Claude Code /status Link Base URL and active credential source Settings files, launch terminal or managed configuration
Final request path /v1/messages A duplicated /v1 or an incorrectly entered OpenAI chat path
Credential field For Bearer, use ANTHROPIC_AUTH_TOKEN; x-api-key Use ANTHROPIC_API_KEY Follow the gateway requirements and avoid conflicting credentials
Current account Model ID, API key group and monthly-plan scope Account access and billing selection; funding cannot fix a path error

Messages request templates and checks in the separate Link GitHub repository provide downloadable JSON and failure categories. Templates contain no keys and are not completed request records; real requests may incur charges.

Start with the usage and monthly-plan guidance to verify the group, then use the cost calculator to compare actual usage days and overages. A Claude Code subscription and a Link API monthly plan are different products.

Then enter a test directory that does not contain sensitive code and perform a short task:

Read the README in the current directory and summarize it in three points.
Do not modify any files.

Verify read-only tasks first, then verify writing files and executing commands.

FAQ

Symptom Check first Next step
401 or authentication failure Whether the current terminal uses a Link key and has conflicting authentication variables Follow your account's setup instructions; never expose the full key
404 or /v1/v1/messages Whether the Base URL duplicates /v1 Correct the URL using the table above, then send a short request
Text works but tools fail Whether streaming events, tool arguments and tool results are complete Save redacted errors and the client version, then retest with the gateway checklist
Request rejected with plan allowance remaining Model eligibility, remaining daily allowance and billing preferences Check plan eligibility before retrying and consuming more allowance

Returns 404 or API format error

Check whether an OpenAI chat endpoint was used by mistake. Claude Code requires Anthropic Messages. Verify the Base URL and final request path; rotating keys cannot fix a protocol or URL error.

Can chat but the tool call is abnormal

An intermediate compatibility layer may only convert text requests, without fully converting tool calls, streaming events, or usage fields. Reading files, changing files, executing commands and long tasks must be tested before production use.

Environment variables do not take effect after modification

If you use temporary export commands as shown here, rerun them and start Claude Code in the same terminal. A new terminal will not inherit these temporary variables. If you saved them in a shell startup file, reload that file before starting the client. Avoid conflicting addresses across configuration files.

Next step

Before running long tasks on a Claude monthly plan, check its eligible group and remaining daily allowance. A 30-day validity period does not mean unlimited usage. See Link monthly plans and pay-as-you-go billing. This guide checks configuration fields and URL construction; streaming, tool calls and long tasks still need model-specific testing.

After setup, follow the Claude Code gateway API acceptance and troubleshooting checklist to verify the Messages path, continuous streaming, real tool calls, long context, caching, and error forwarding. Do not treat one successful chat response as proof of complete Agent capability.

After confirming protocol compatibility, set independent usage limits and project-level security rules for Claude Code. Private repositories, key files, and customer data should be explicitly excluded.

Source checked

Reference and Check Sources

Next step

Create an API key and complete your first integration

After registering, create an API key in the console and choose a model that supports your required protocol. Verify a short request before testing streaming and tool calls.

Create Account Open the consoleView integration checks