Claude Code installed
Install Claude Code from the official source and confirm it runs with claude --version in your terminal. If that command errors, fix the install before setting any API keys.
Claude Code reads two environment variables to route requests anywhere: ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY. Point them at RunAPI and run every Claude model at half the official rate. This guide shows the exact commands for Mac, Linux, and Windows.
Claude Code uses two environment variables to decide where requests go and how they authenticate. Set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY to RunAPI values and every request routes through RunAPI at 50% off. Want to use a different provider entirely? RunAPI also works as a drop-in gateway so you can run Claude models without a direct Anthropic account.
ANTHROPIC_BASE_URL sets the endpoint. ANTHROPIC_API_KEY sets the key. That is the whole config — two variables, no other changes.
Set ANTHROPIC_BASE_URL to https://api.runapi.ai so Claude Code routes through RunAPI.
Add both exports to your shell profile (.zshrc or .bashrc) so you do not re-set them each session. Windows users set them in PowerShell and open a new window.
Every Claude model bills at half the official Anthropic rate. No subscription, no cap.
The setup takes a few minutes. You need Claude Code installed, a RunAPI account, and a terminal. Run claude --version first to confirm Claude Code is working before touching any API key config.
Install Claude Code from the official source and confirm it runs with claude --version in your terminal. If that command errors, fix the install before setting any API keys.
Sign up at runapi.ai. The free tier includes credits to test any Claude model before you fund a balance.
Create a key from Dashboard → API Keys. Copy it once — it is shown in full only at creation time. Do not paste it into public repos or share it in screenshots.
You need a shell to set environment variables. macOS and Linux use .zshrc or .bashrc. Windows users can use PowerShell — set the variable, then open a new terminal window for it to take effect.
Run these commands in order. They set the endpoint and key, persist them to your shell profile, and confirm Claude Code picks them up. Replace the placeholder with your real RunAPI key. Use ANTHROPIC_API_KEY (not CLAUDE_API_KEY) — that is the variable Claude Code actually reads.
This tells Claude Code to send requests to RunAPI instead of the default Anthropic endpoint.
export ANTHROPIC_BASE_URL=https://api.runapi.ai
Paste your RunAPI key in place of the placeholder. Claude Code uses it to authenticate every request.
export ANTHROPIC_API_KEY=sk-your-runapi-key
Append both exports to ~/.zshrc (or ~/.bashrc) so they survive new terminal sessions. Reload with source ~/.zshrc. On Windows, set them in PowerShell and open a new terminal window for the change to take effect.
echo 'export ANTHROPIC_BASE_URL=https://api.runapi.ai' >> ~/.zshrc
Confirm the variable prints the RunAPI URL. If it is empty, reload your shell profile or open a new terminal — variables set in one session do not automatically carry over.
echo $ANTHROPIC_BASE_URL
Launch Claude Code in your project. It now routes through RunAPI at 50% off the official rate.
claude
Claude Code reads a small set of variables to control endpoint, auth, model, and output length. The table lists the ones that matter for a custom endpoint setup and what each does. Note: use ANTHROPIC_API_KEY (not CLAUDE_API_KEY) — that is the variable Claude Code actually reads.
| Variable | Purpose | Example value |
|---|---|---|
| ANTHROPIC_BASE_URL | Custom endpoint Claude Code sends requests to | https://api.runapi.ai |
| ANTHROPIC_API_KEY | Key used to authenticate requests | sk-your-runapi-key |
| ANTHROPIC_MODEL | Default model for new sessions | claude-sonnet-4-6 |
| CLAUDE_CODE_MAX_OUTPUT_TOKENS | Cap on tokens returned per response | 8192 |
You can also store these in a .claude.json config file in your home or project directory instead of exporting them each session.
Claude Code accepts any Claude model ID through RunAPI. Pick by task: a fast cheap model for routine edits, a balanced one for daily coding, or the strongest for hard problems. Set ANTHROPIC_MODEL to change the default, or switch models inside Claude Code — billing follows whichever model you actually call.
Fastest and cheapest at $1/M input and $5/M output through RunAPI. Best for routine edits and quick lookups.
Balanced default for daily coding at $3/M input and $15/M output through RunAPI. Most developers run this.
Strongest for hard problems at $5/M input and $25/M output through RunAPI. Use it for complex refactors and reviews.
Set ANTHROPIC_MODEL or change the model inside Claude Code any time. Billing follows the model you actually call, all at 50% off.
Most setup problems come from one of three things: the wrong env var name (use ANTHROPIC_API_KEY, not CLAUDE_API_KEY), a stale shell session that has not picked up your profile changes, or a typo in the key. The table lists the common errors and the fix for each.
| Error or symptom | Likely cause | Fix |
|---|---|---|
| 401 Unauthorized | Wrong or expired API key | Recheck ANTHROPIC_API_KEY and create a new key in the RunAPI dashboard if needed |
| Requests still hit Anthropic | ANTHROPIC_BASE_URL not set in this shell | Run echo $ANTHROPIC_BASE_URL; if empty, reload your profile or open a new terminal |
| 404 Not Found | Trailing slash or wrong path in base URL | Set the base URL to exactly https://api.runapi.ai with no trailing path |
| Model not found | Invalid or misspelled model ID | Use a valid ID like claude-sonnet-4-6 or claude-opus-4-7 |
| Variables lost on restart | Exports not written to shell profile | Append both exports to ~/.zshrc or ~/.bashrc and reload |
Export ANTHROPIC_BASE_URL=https://api.runapi.ai to route requests through RunAPI.
Export ANTHROPIC_API_KEY with your RunAPI key from Dashboard → API Keys.
Append both exports to ~/.zshrc or ~/.bashrc and reload with source ~/.zshrc so they survive new sessions. On Windows, set them in PowerShell and open a new terminal window.
Run claude --version to confirm install, then launch claude in your project. Requests now route through RunAPI at 50% off the official rate.
Set two environment variables. Export ANTHROPIC_BASE_URL to https://api.runapi.ai and ANTHROPIC_API_KEY to your RunAPI key. Append both to your shell profile (.zshrc or .bashrc) so they persist across sessions. Claude Code reads them on startup and routes every request through RunAPI.
Create one at runapi.ai. Sign up, open Dashboard → API Keys, and generate a key. Copy it immediately — the full key is shown only at creation. The free tier includes credits to test any Claude model before you fund a balance.
It tells Claude Code which endpoint to send requests to. By default Claude Code calls Anthropic directly. Setting it to https://api.runapi.ai routes every request through RunAPI instead, which bills the same models at 50% of the official rate.
Is there a way to use Claude Code with other API providers like OpenAI? Yes — Claude Code supports any OpenAI-compatible endpoint via ANTHROPIC_BASE_URL. RunAPI exposes a compatible gateway so you can swap providers without changing your code, using one key across Claude, GPT, and other models.
Run echo $ANTHROPIC_BASE_URL in your terminal. If it prints nothing, the export did not persist. Append both exports to ~/.zshrc or ~/.bashrc, run source ~/.zshrc, then open a new terminal and check again. Windows users need to open a new PowerShell window after setting env vars.
Yes. Place the values in a .claude.json file in your home or project directory rather than exporting them each session. Both approaches work — the file is handy for per-project keys, while exports are simpler for a single global setup.
Open the RunAPI dashboard. It shows spend per key and per request in real time. To cap output cost, set CLAUDE_CODE_MAX_OUTPUT_TOKENS so each response is limited, and use claude-haiku-4-5 for routine edits.
No. RunAPI proxies requests directly to the underlying Claude models. Output, tool use, and behavior are identical to calling Anthropic directly. You only change where requests go and how they are billed — the coding experience stays the same.
What Claude Code costs with API billing vs Max subscription.
Connect Cursor to RunAPI in two minutes for 50% off API rates.
Use RunAPI models in VS Code Copilot Chat and extensions.
Run any model from your terminal with a single command.
Create a free RunAPI account, set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY in your shell profile, and run every Claude model in Claude Code at 50% off official Anthropic pricing.