Tool Integration

Claude Code custom API configuration tutorial

Configure Claude Code's ANTHROPIC_BASE_URL, authentication variables and model mapping, distinguish Anthropic Messages and OpenAI Compatible protocols, and verify streaming output and tool calls with minimal tasks.

Updated on 2026-08-26Checked 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

Common configurations of Claude Code are completed through environment variables. The specific variables and authentication methods should be subject to the current Claude Code official documents and AIFast access instructions. Typical inspection items include:

ANTHROPIC_BASE_URL
ANTHROPIC_AUTH_TOKEN Or the corresponding authentication variable
Default model and small model settings

After the configuration is completed, open a new terminal and confirm whether the variable exists. Do not print the complete Key directly:

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

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

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

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

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

Close and reopen the terminal and confirm that the configuration is written to the startup file used by the current shell. Do not set conflicting addresses in multiple configuration files at the same time.

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.

Source checked

Reference and Check Sources

Next step

Test the current API before fixing, migrating, or creating a test key

Use a temporary, limited key to inspect model declarations, token fields, SSE, and tool calls. Review current models and pricing only when you need a replacement API.

Model Quality CheckModel PricingCreate Account