The $5 Claude Code Setup Uses Two Environment Variables
01 / A two-variable Claude Code setup for a tiny budget
Claude Code can use a compatible API relay instead of a direct provider account. For a beginner, the useful part is simple: CheapRelay gives you one API key, charges per real token, and has no monthly fee or subscription. You can start with a small amount of money and stop when the balance reaches your limit.
The setup below is for macOS or Linux shells. It uses the Claude Code environment variables for a custom API endpoint and authentication. You do not need to change project files or install another SDK.
02 / Create the relay key before opening Claude Code
Sign up for CheapRelay, open the API key area, and copy a key. Treat it like a password. Do not paste it into a public repository, a screenshot, or a shared shell history. If the dashboard supports key rotation, replace a key immediately after accidental exposure.
CheapRelay's API base is https://api.cheapapirelay.com. Claude Code uses its Anthropic-compatible request path, so use that base URL directly for this setup. Do not append /v1 to the Claude Code variable. The /v1 path is relevant to OpenAI-compatible clients; Gemini-native requests use /v1beta.
03 / Set exactly two environment variables
Open a terminal and replace the placeholder with your actual CheapRelay key:
export ANTHROPIC_BASE_URL="https://api.cheapapirelay.com"
export ANTHROPIC_AUTH_TOKEN="your_cheaprelay_key"
These variables apply to commands started from this terminal window. If you open a new terminal later, set them again, or add the two export lines to your shell profile after you are comfortable with the arrangement. A shell profile makes the variables persistent, but it also means every future terminal session can access the key.
04 / Launch Claude Code and make one small request
Start Claude Code in a test project:
claude
Use a narrow request first, such as asking it to explain one file or identify one failing test. The first request confirms three things at once: the key is valid, the base URL is correct, and the relay is receiving Claude Code traffic.
For a low-cost first run, choose a lighter model from inside Claude Code if your account exposes model selection. Claude Haiku 4.5 is one available option. You can change models later without creating another relay key or changing the two environment variables.
05 / Keep the first bill predictable
CheapRelay bills by actual token usage, including cache reads and cache writes. That means a short prompt is not the only cost factor. Large project context, repeated file analysis, and long generated patches can all increase usage. A tiny balance is therefore best treated as a test budget, not as an unlimited development fund.
- ■ Start with a small balance that you are comfortable spending.
- ■ Ask for inspection before asking for broad edits.
- ■ Keep the first session focused on one file or one task.
- ■ Check the usage or billing view after the first request.
- ■ Stop the session when the remaining balance reaches your personal limit.
06 / Fix the three common setup mistakes
If Claude Code reports an authentication error, check that the key is complete and that no spaces or quotation marks were copied into its value. If it behaves as though the relay was ignored, run printenv ANTHROPIC_BASE_URL and confirm that the terminal contains the expected URL. If a new terminal loses the configuration, repeat the exports or add them to the appropriate shell profile.
Do not add a third model variable until the basic connection works. Once the two-variable setup succeeds, model selection and spending decisions can be tested separately. This keeps troubleshooting cheap and makes it clear whether a problem comes from the endpoint, the key, or the Claude Code session.
Sign up Try the prices yourself, sign-up credit included.
More reading
| Date | Aisle | Written in | Title |
|---|---|---|---|
| 2026-10-27 | Coding agents, cheaply | EN | $2 a Day for Claude Code: A Budget, Not a Promise A beginner’s walkthrough for keeping Claude Code spending predictable with small tasks, token checks and a $2 daily planning limit. |
| 2026-10-27 | Coding agents, cheaply | EN | $1.00 for a $0.50 Coding Job An illustrative coding-assistant receipt shows how repeated context, noisy logs, long answers and blind retries turn a $0.50 task into $1.00. |
| 2026-10-27 | Coding agents, cheaply | EN | $0.18 for a CI Agent Run, With a $0.50 Ceiling A receipt-style CI agent budget: token costs, retry limits, request reservations, and a practical way to enforce a $0.50 run ceiling. |
| 2026-10-27 | Coding agents, cheaply | EN | Your Input Bill: 90,000 Tokens From One File A troubleshooting FAQ for coding agents: cut repeated files, noisy tool output and stale history without starving the agent of useful context. |
| 2026-10-27 | Coding agents, cheaply | EN | $0.192 for a coding session, not $0.480 A worked API receipt for cheap-first pair programming, with explicit assumptions, escalation limits, and a fair cost comparison. |
| 2026-10-27 | Coding agents, cheaply | EN | $0.18 for a Codex Task, $0.62 for a Wandering Session An illustrative Codex receipt shows how narrow tasks, smaller context and fewer retries can cut token costs without hiding cache charges. |