Connect Claude Code to ApiFlux
Install Claude Code, connect it to the ApiFlux Anthropic-compatible endpoint, and verify a request.
This guide connects Claude Code to the Anthropic-compatible ApiFlux endpoint. After setup, you can review Claude Code usage and logs in the ApiFlux console.
Who this guide is for
Use this guide if you want to manage Claude Code model access, usage, and logs through ApiFlux.
If you have not set up a terminal, start here:
Prepare your terminal and development environment
[!NOTE] Claude Code's installation script does not require Node.js. Install Node.js LTS if you also plan to use Codex CLI or OpenCode.
Before you start
Before you start, make sure you have:
- An ApiFlux API key
- An ApiFlux model ID that supports the Claude or Anthropic-compatible protocol
ApiFlux website:
https://apiflux.ai/ApiFlux OpenAI-compatible Base URL:
https://apiflux.ai/v1Claude Code uses ANTHROPIC_BASE_URL to connect to a gateway. Start with:
https://apiflux.aiIf you get a path-related error, try again:
https://apiflux.ai/v11. Install Claude Code
Windows
Open PowerShell and run:
irm https://claude.ai/install.ps1 | iexYou can also use WinGet:
winget install Anthropic.ClaudeCodeIf using WSL, install using the macOS/Linux command in the WSL terminal.
macOS/Linux
Open a terminal and run:
curl -fsSL https://claude.ai/install.sh | bashmacOS users can also use Homebrew:
brew install --cask claude-codeOnce the installation is complete, close the terminal and reopen it.
2. Confirm that Claude Code is installed
Run in terminal:
claude --versionIf the command prints a version number, Claude Code is installed.
You can also run diagnostic commands:
claude doctorIf you see command not found or “not recognized as an internal or external command,” reopen the terminal. If the error remains, run the installation command again.
3. Prepare ApiFlux API key
Enter the ApiFlux console, open the API keys page, and copy the API key to be used for Claude Code.
If you have not created an API key yet, follow:
4. Set Claude Code environment variables
[!NOTE] Set
ANTHROPIC_API_KEYto your ApiFlux API key, not an Anthropic API key.
Windows PowerShell
For the current terminal session:
$env:ANTHROPIC_BASE_URL="https://apiflux.ai"
$env:ANTHROPIC_API_KEY="YOUR_APIFLUX_API_KEY"
$env:DISABLE_INTERLEAVED_THINKING="1"
$env:CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS="1"Verify the key:
echo $env:ANTHROPIC_API_KEYTo persist these variables for future sessions, run:
[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL","https://apiflux.ai","User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY","YOUR_APIFLUX_API_KEY","User")
[Environment]::SetEnvironmentVariable("DISABLE_INTERLEAVED_THINKING","1","User")
[Environment]::SetEnvironmentVariable("CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS","1","User")After setting persistent environment variables, close PowerShell and reopen it.
macOS/Linux
For the current terminal session:
export ANTHROPIC_BASE_URL="https://apiflux.ai"
export ANTHROPIC_API_KEY="YOUR_APIFLUX_API_KEY"
export DISABLE_INTERLEAVED_THINKING=1
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1Verify the key:
echo $ANTHROPIC_API_KEYmacOS usually uses zsh. To persist the variable, add it to ~/.zshrc:
echo 'export ANTHROPIC_BASE_URL="https://apiflux.ai"' >> ~/.zshrc
echo 'export ANTHROPIC_API_KEY="YOUR_APIFLUX_API_KEY"' >> ~/.zshrc
echo 'export DISABLE_INTERLEAVED_THINKING=1' >> ~/.zshrc
echo 'export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1' >> ~/.zshrc
source ~/.zshrcLinux usually uses bash. To persist the variable, add it to ~/.bashrc:
echo 'export ANTHROPIC_BASE_URL="https://apiflux.ai"' >> ~/.bashrc
echo 'export ANTHROPIC_API_KEY="YOUR_APIFLUX_API_KEY"' >> ~/.bashrc
echo 'export DISABLE_INTERLEAVED_THINKING=1' >> ~/.bashrc
echo 'export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1' >> ~/.bashrc
source ~/.bashrc5. Select model
Claude Code's model ID should be based on the ApiFlux Models page.
If the current Claude Code version supports specifying the model through startup parameters, you can use:
claude --model "YOUR_MODEL_ID"Example:
claude --model "claude-sonnet-4-6"[!NOTE]
claude-sonnet-4-6is an example only. Please refer to the ApiFluxModelspage for the actual available models.
6. Initiate a test request
Start Claude Code:
claude --model "YOUR_MODEL_ID"Enter a simple request in Claude Code:
Describe ApiFlux in three sentences and explain who it is for.After Claude Code returns a response, open Logs in the ApiFlux console and confirm that the request appears.
Compatibility Notes
Some versions of Claude Code will send beta headers by default. Third-party gateways or some Claude routes may not accept these beta headers, returning:
invalid beta flagIf this error occurs, make sure you have set it before starting:
DISABLE_INTERLEAVED_THINKING=1
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1If https://apiflux.ai reports a path error, you can use:
ANTHROPIC_BASE_URL="https://apiflux.ai/v1"FAQ
401 Unauthorized
Usually caused by:
- The API key is incorrect
- The key was deleted or expired
- The current terminal session does not have the environment variable
- The copied key contains extra spaces
Windows PowerShell can run:
echo $env:ANTHROPIC_API_KEYmacOS / Linux runs:
echo $ANTHROPIC_API_KEYIf there is no output, reset the environment variables.
404 or Not Found
Usually the Base URL path does not match.
You can try:
https://apiflux.aiIf it still fails, try again:
https://apiflux.ai/v1Model is not available
Please return to the ApiFlux Models page and confirm that the selected model supports the Claude / Anthropic-compatible protocol.