Tool Integration

Claude Code custom API configuration tutorial

Claude Code custom API setup with a complete Bash/Zsh example. Check ANTHROPIC_BASE_URL, credentials, model ID and /status; diagnose /v1/v1, 401 and stale settings.

Updated on 2026-11-02Checked 2026-08-26Estimated 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.
Special topic: AI development tool custom API access center

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 the gateway provides both OpenAI and Anthropic protocols, they should be accepted separately. The successful response of the OpenAI SDK cannot be used in place of the Claude Code test:

Check before you start

  • Confirm the protocol and private address currently used by Claude Code in the AIFast API documentation or customer service.
  • 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

1. Configure an isolated CLI session

This Bash/Zsh example requires Claude Code to be installed. Securely set AIFAST_API_KEY and AIFAST_MODEL_ID locally using a temporary limited HK key and a full model ID available to that account. Do not send another provider's key to HK or commit credentials.

The subshell configuration affects only this CLI process, leaving the parent shell credentials and login files unchanged after exit. This example uses Bearer authentication. If the current provider instructions require x-api-key, use its matching variable instead of setting both credentials.

(
  set -eu
  : "${AIFAST_API_KEY:?First set HK temporary limited Key}"
  : "${AIFAST_MODEL_ID:?First set HK model available to the account ID}"
  export ANTHROPIC_BASE_URL="https://www.aifast.hk"
  export ANTHROPIC_AUTH_TOKEN="$AIFAST_API_KEY"
  unset ANTHROPIC_API_KEY
  claude --model "$AIFAST_MODEL_ID"
)

2. Check the path, credential source and a real task

Run /status after launch to check the host and credential source, then verify the actual request reaches /v1/messages without a duplicate /v1. Correct variables establish configuration only, not working models, streaming or tools. This example has syntax and isolation tests; it is not evidence of a successful paid API call.

Run a short task in a test directory without sensitive code. Generation requests may incur charges:

Read in the current directory README,and summarized in three key points,Do not modify the file。

Validate a read-only task before testing file writes and commands with the checklist. Do not disable tool approvals, TLS verification or project security restrictions to connect a gateway.

3. Check configuration precedence when settings do not apply

Inspect the effective values in /status, then check user or project settings. The current official gateway guide notes that settings-file env values can override shell exports; an already-open editor will not inherit new terminal variables. This section covers the CLI only. VS Code and desktop apps have their own configuration entry points.

Decide whether to persist the settings after testing. Do not commit project configuration containing a key, or delete an existing account login just to switch gateways.

FAQ

Returns 404 or API format error

The most common reason is to put OpenAI's /v1/chat/completions The address is given to clients that require the Anthropic Messages format. Check the dedicated Base URL and protocol, and do not change the Key repeatedly.

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

Temporary exports apply only to the current terminal and its child processes; they are lost in a new terminal. Launch the CLI from the same terminal and check /status. For persistent settings, check for conflicts between the shell profile and Claude Code settings.

Next step

After the basic configuration, continue with theClaude Code gateway API acceptance and troubleshooting checklistto 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.

FAQ

Should the Claude Code Base URL include /v1?

This HK example uses https://www.aifast.hk and targets /v1/messages. The OpenAI SDK value https://www.aifast.hk/v1 is a different setting. Check the current integration instructions and actual request; do not construct /v1/v1/messages.

How do ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY differ?

The former sends Authorization Bearer; the latter sends x-api-key. Choose according to the gateway requirements and never mix in another provider's key. A set variable does not prove successful authentication; verify with an actual short task.

Why does Claude Code still use the old URL after setting terminal variables?

Check that the CLI started from the same terminal, whether settings files override the values, and the Base URL and credential source shown in /status. New terminal variables do not automatically reach already-open editors or desktop apps. Do not delete existing login configuration.

Source checked

Reference and Check Sources

Next step

After setup, validate actual Claude Code tasks

Check Messages, stream completion events and tool calls separately. A passing Chat Completions test does not validate Claude Code.

Review the Claude Code checklistModel PricingCreate Account