Claude Code installed
Install Claude Code from the official source and confirm it runs with the claude command in your terminal.
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.
Claude Code uses two environment variables to decide where requests go and how they authenticate. Set them to RunAPI values and every request routes through RunAPI at 50% off. The cards below cover the essentials before the full walkthrough.
ANTHROPIC_BASE_URL sets the endpoint. ANTHROPIC_API_KEY sets the key. That is the whole config.
Set ANTHROPIC_BASE_URL to https://api.runapi.ai so Claude Code routes through RunAPI.
Add both exports to your shell profile or .claude.json so you do not re-set them each session.
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. The list below covers everything required before the first command.
Install Claude Code from the official source and confirm it runs with the claude command in your terminal.
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.
You need a shell to set environment variables. macOS, Linux, and WSL on Windows all work the same way.
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.
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.
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.
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.
| 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.
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. Billing follows the model you actually call, all at 50% off.
Most setup problems come from an unset variable, a stale shell, 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 so they survive new sessions.
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 so they persist. 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, since 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.
The base URL is probably not set in your current shell. Run echo $ANTHROPIC_BASE_URL — if it is empty, the export did not persist. Append it to ~/.zshrc or ~/.bashrc, reload with source, then open a new terminal and check again.
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 handier 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 choose a cheaper model like Haiku for routine edits.
No. RunAPI proxies requests directly to the underlying Claude models. Output, tool use, and behavior are identical to the default setup. You only change where requests go and how they are billed — the coding experience stays the same.
Most developers set ANTHROPIC_MODEL to claude-sonnet-4-6 for daily coding. Use claude-haiku-4-5 for fast cheap edits or claude-opus-4-7 for hard refactors. You can switch models inside Claude Code at any time, and billing follows the model you call.
Create a free RunAPI account, set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, and run every Claude model in Claude Code at 50% off official Anthropic pricing.