Connect Claude Code to a crypto-paid API
Learn how to configure Claude Code to use a crypto-paid API aggregator that supports the Anthropic API format. This guide covers setting the ANTHROPIC_BASE_URL environment variable, obtaining a USDC-funded API key, and verifying the setup. You'll also understand the pricing model: users pay official price ×1.3, and contributors earn credits at official price ×1.1 (premium ×1.2) in USDC.
Why Use an Aggregator with Claude Code?
Claude Code is Anthropic's official CLI tool for interacting with Claude models. By default, it connects to Anthropic's API. However, you can redirect it to any compatible endpoint by setting the ANTHROPICBASEURL environment variable. This allows you to use alternative providers that may offer different payment methods, such as cryptocurrency.
An LLM API aggregator that supports the Anthropic format lets you access multiple models (e.g., Claude, GPT, DeepSeek, Qwen, GLM, Kimi) through a single API key. You top up with USDC on Base, with no KYC required, and pay per usage.
Prerequisites
Before you begin, ensure you have:
- Claude Code installed (follow the official installation instructions).
- A crypto wallet that supports USDC on the Base network.
- An API key from the aggregator (you'll generate this after funding your account).
Step 1: Obtain a USDC-Funded API Key
- Visit the aggregator's website and create an account.
- Navigate to the billing or top-up section.
- Send USDC on Base to the provided address. The amount will be credited to your account balance.
- Generate an API key from the dashboard. This key will be used to authenticate your requests.
Note: The aggregator does not require KYC, so you can start using the service immediately after the transaction confirms.
Step 2: Set the ANTHROPICBASEURL Environment Variable
You need to point Claude Code to the aggregator's Anthropic-compatible endpoint. The exact URL is provided in the aggregator's documentation (commonly something like https://api.example.com).
Set the environment variable in your shell:
export ANTHROPIC_BASE_URL="https://api.your-aggregator.com"
To make this persistent, add the line to your shell profile (e.g., ~/.bashrc, ~/.zshrc).
Step 3: Configure the API Key
Claude Code reads the API key from the ANTHROPICAPIKEY environment variable. Set it to your aggregator API key:
export ANTHROPIC_API_KEY="your-aggregator-api-key"
Again, add this to your shell profile for persistence.
Step 4: Verify the Setup
Run a simple command to test the connection. For example, ask Claude Code to list files or perform a basic task:
claude "what is 2+2?"
If everything is configured correctly, you'll receive a response from the aggregator's service. If you encounter errors, double-check the base URL and API key.
Understanding the Pricing Model
The aggregator uses a transparent pricing structure:
- You pay the official model price multiplied by 1.3.
- If you contribute to the aggregator (e.g., by providing compute or other resources), you earn credits at the official price multiplied by 1.1 (or 1.2 for premium contributions) in USDC.
This means your net cost depends on your usage and contributions. The aggregator does not claim that net costs drop to a fraction of official price; the multipliers are as stated.
Supported Models
The aggregator provides access to multiple models, including Claude, GPT, DeepSeek, Qwen, GLM, and Kimi. You can switch between models by specifying them in your requests, depending on how Claude Code allows model selection. Check the aggregator's documentation for the exact model identifiers.
Troubleshooting
- Authentication errors: Ensure your API key is correct and has sufficient balance.
- Connection issues: Verify the base URL is correct and that your network allows outbound requests.
- Model not found: Confirm the model name is supported by the aggregator.
Conclusion
By setting ANTHROPICBASEURL and ANTHROPICAPIKEY, you can seamlessly use Claude Code with a crypto-paid aggregator. This setup offers flexibility in payment methods and access to a variety of models, all while maintaining compatibility with the Anthropic API format. Remember to monitor your balance and top up as needed.