Claude Code

Point Anthropic's terminal coding assistant Claude Code at AI Nexus and call models through the Claude-native Messages endpoint.

Claude Code is Anthropic's terminal coding assistant. It understands your codebase, edits across files and runs commands. It uses the Anthropic Messages format (POST /v1/messages), so you only need to point it at AI Nexus with environment variables.

Verification status

The Claude Code client itself has not been tested hands-on against AI Nexus; the settings below follow its official documentation. Only two values matter: ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN.

Official site: https://www.anthropic.com/claude-code

Prerequisites

  • An API key from AI Nexus; see API Keys. If you restricted the key to certain models, include the models you want to use, otherwise you get model_not_found. Use GET /v1/models to check which models the key can use; see Quickstart.
  • The base URL has no /v1: Claude Code appends /v1/messages itself. See Anthropic format.
  • Pick a model that supports /v1/messages. Pick a model on the model square that supports /v1/messages and use its model ID. Models without that endpoint can't be used in Claude Code; for a terminal tool that uses the Responses API, see Codex CLI.

Install Claude Code

curl -fsSL https://claude.ai/install.sh | bash

If the installer says claude is not on your PATH, add ~/.local/bin as instructed:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc

Run claude --version afterwards; if it prints a version number, the install worked.

Set environment variables

export ANTHROPIC_BASE_URL="https://ai.myaiexp.com"
export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxx"
claude

To make it permanent, add the first two lines to ~/.zshrc or ~/.bashrc.

ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer sk-..., which the AI Nexus /v1/messages endpoint accepts.

Or use settings.json

Edit ~/.claude/settings.json (on Windows, %USERPROFILE%\.claude\settings.json) and put the variables under env so you don't have to export them every time:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.myaiexp.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-xxxxxxxx"
  }
}

If the file already has other settings, merge just the env block instead of overwriting the file.

Choose models

Claude Code picks models by tier (Opus / Sonnet / Haiku). If the default model names are not in your available list, pick a model on the model square that supports /v1/messages and set these variables to its model ID:

VariablePurpose
ANTHROPIC_MODELMain model used at startup
ANTHROPIC_DEFAULT_OPUS_MODELModel behind the Opus tier in /model
ANTHROPIC_DEFAULT_SONNET_MODELModel behind the Sonnet tier
ANTHROPIC_DEFAULT_HAIKU_MODELModel for the Haiku tier and lightweight background tasks
ANTHROPIC_SMALL_FAST_MODELLightweight-model variable used by older versions

Replace your-model-id and your-fast-model-id in the samples with model IDs from the model square that support /v1/messages (or call GET /v1/models).

export ANTHROPIC_MODEL="your-model-id"  # replace with a model ID from the model square that supports /v1/messages
export ANTHROPIC_DEFAULT_OPUS_MODEL="your-model-id"
export ANTHROPIC_DEFAULT_SONNET_MODEL="your-model-id"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="your-fast-model-id"
export ANTHROPIC_SMALL_FAST_MODEL="your-fast-model-id"

The same works in settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.myaiexp.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-xxxxxxxx",
    "ANTHROPIC_MODEL": "your-model-id",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "your-model-id",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "your-model-id",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "your-fast-model-id"
  }
}

You can also type /model inside Claude Code to pick a model. For the full model list, see the model square or GET /v1/models.

Once ANTHROPIC_BASE_URL is set, every model request (including Claude Code's built-in model names) goes to AI Nexus and is charged to your AI Nexus balance at AI Nexus prices, not to your Anthropic account. See the model square.

Verify

Start claude, ask anything, then check the console's Usage Logs for the matching entry.

  • model_not_found: check that the model name matches GET /v1/models, that the model supports /v1/messages, and whether the key has model restrictions.
  • 401: check that the key is correct and not expired or disabled.
  • Requests going to /v1/v1/messages: the base URL has an extra /v1; remove it.

See Errors for more troubleshooting.

This service is provided for learning and research purposes only. Please follow each model provider's usage policies.

On this page