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.