15% off all models 🎉 Every model at 85% of OpenRouter list price.Browse models →

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/v1

Claude Code uses ANTHROPIC_BASE_URL to connect to a gateway. Start with:

https://apiflux.ai

If you get a path-related error, try again:

https://apiflux.ai/v1

1. Install Claude Code

Windows

Open PowerShell and run:

irm https://claude.ai/install.ps1 | iex

You can also use WinGet:

winget install Anthropic.ClaudeCode

If 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 | bash

macOS users can also use Homebrew:

brew install --cask claude-code

Once the installation is complete, close the terminal and reopen it.

2. Confirm that Claude Code is installed

Run in terminal:

claude --version

If the command prints a version number, Claude Code is installed.

You can also run diagnostic commands:

claude doctor

If 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:

Create an ApiFlux API key

4. Set Claude Code environment variables

[!NOTE] Set ANTHROPIC_API_KEY to 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_KEY

To 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=1

Verify the key:

echo $ANTHROPIC_API_KEY

macOS 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 ~/.zshrc

Linux 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 ~/.bashrc

5. 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-6 is an example only. Please refer to the ApiFlux Models page 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 flag

If this error occurs, make sure you have set it before starting:

DISABLE_INTERLEAVED_THINKING=1
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1

If 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_KEY

macOS / Linux runs:

echo $ANTHROPIC_API_KEY

If 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.ai

If it still fails, try again:

https://apiflux.ai/v1

Model is not available

Please return to the ApiFlux Models page and confirm that the selected model supports the Claude / Anthropic-compatible protocol.

References