claude-code-env-auth · EN · 2026-10-13

Configuring Claude Code to Authenticate Against the Aggregator Instead of Anthropic

Configure Claude Code to use an LLM API aggregator instead of Anthropic's API by setting environment variables. This guide explains how to point Claude Code to the aggregator's base URL and API key, and what to unset to avoid conflicts. The aggregator supports USDC payments on Base with no KYC, one key for multiple models (Claude, GPT, DeepSeek, Qwen, GLM, Kimi) at official price ×1.3.

Why Use an Aggregator with Claude Code?

Claude Code is Anthropic's official CLI tool for interacting with Claude models. By default, it authenticates directly with Anthropic's API. However, you can redirect it to use an aggregator that provides a unified API for multiple models. This aggregator allows you to pay with USDC on Base (no KYC), calls the official API on your behalf, and charges official price ×1.3. You get one API key for many models, simplifying billing and access.

How Claude Code Authentication Works

Claude Code reads configuration from environment variables. The two critical variables are:

  • ANTHROPICBASEURL: The base URL for the Anthropic-compatible API.
  • ANTHROPICAPIKEY: The API key used for authentication.

When these are not set, Claude Code defaults to Anthropic's official endpoint and expects an Anthropic API key. By pointing ANTHROPICBASEURL to the aggregator and setting ANTHROPICAPIKEY to your aggregator key, you redirect all requests through the aggregator.

Step-by-Step Configuration

1. Obtain Your Aggregator API Key

Sign up or log in to the aggregator dashboard. Top up your balance with USDC on Base (no KYC required). Generate an API key. This key will be used for all models.

2. Set Environment Variables

In your shell configuration file (e.g., ~/.bashrc, ~/.zshrc, or ~/.profile), add:

export ANTHROPIC_BASE_URL="https://api.aggregator.example.com"  # Replace with actual aggregator URL
export ANTHROPIC_API_KEY="your-aggregator-api-key"

Replace the URL with the aggregator's actual base URL (check their docs). Then reload your shell:

source ~/.bashrc  # or ~/.zshrc

3. Unset Conflicting Variables

If you previously used Claude Code with Anthropic directly, you might have other variables set. Ensure the following are unset to avoid confusion:

  • ANTHROPICAUTHTOKEN (if you used OAuth or a different token)
  • ANTHROPIC_MODEL (unless you want to override the model)
  • Any proxy variables like HTTPPROXY/HTTPSPROXY that might interfere.

In your shell config, you can explicitly unset them:

unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_MODEL

4. Verify the Configuration

Run a simple Claude Code command, such as:

claude --version
claude "Hello, world"

If configured correctly, the response will come from the aggregator. You can check the aggregator dashboard to see the request logged and your balance deducted.

Important Considerations

  • Model Names: The aggregator may use the same model names as Anthropic (e.g., claude-3-5-sonnet). Ensure you use the correct model identifier as per the aggregator's documentation.
  • Pricing: You pay the official Anthropic price ×1.3 for Claude models. This covers the aggregator's service and payment processing.
  • Contributor Credits: If you contribute to the aggregator (e.g., by providing compute or models), you may earn credits at official price ×1.1 (or ×1.2 for premium) in USDC.
  • Security: Keep your API key secure. Do not commit it to version control.
  • Fallback: If you need to switch back to Anthropic directly, simply unset ANTHROPICBASEURL and ANTHROPICAPIKEY, and set your Anthropic key.

Troubleshooting

  • Authentication Errors: Double-check that your API key is correct and has sufficient balance.
  • Connection Issues: Verify the base URL is correct and that your network allows outbound HTTPS.
  • Unexpected Model: If Claude Code uses a different model than expected, check if ANTHROPIC_MODEL is set and unset it if necessary.

By following these steps, you can seamlessly use Claude Code with the aggregator, gaining access to multiple models with a single key and paying with USDC.