Setting a Claude Code custom base URL means telling the CLI to send its requests to a different Anthropic-compatible endpoint instead of the default one. You do it with two or three environment variables, and no code changes. This guide walks through the setup against the BangunWeb AI Router, shows how to test it, and explains how to keep token spend under control.
If you have been blocked by card requirements, see also our walkthrough on using the Claude API without a credit card. This article focuses on the Claude Code side.
Claude Code custom base URL: what you need
Claude Code speaks the Anthropic Messages format (POST /v1/messages). Any gateway that implements the same format can sit in the middle. The BangunWeb AI Router does, so you only need three things:
- Base URL:
https://router.bangunweb.com. Use it without a trailing/v1, because the Anthropic client adds the path itself. - API key: a key that starts with
bwr_live_..., created in your dashboard after signing in. - Prepaid balance: Claude models unlock after your first token purchase. New Google sign-ins get free trial tokens once per account, which is enough to test other model families first.
The router accepts either Authorization: Bearer bwr_live_... or x-api-key: bwr_live_..., so both the Anthropic SDK and generic HTTP clients work.
Step-by-step setup
- Create an account and key. Sign in with Google, then generate a
bwr_live_...key. - Top up tokens. Pick a package on the token package page. Bigger packages cost less per token, and you can pay with QRIS, Indonesian bank transfer, retail outlets or USDT. See paying for AI APIs with QRIS for the local options.
- Export the variables in your shell:
export ANTHROPIC_BASE_URL="https://router.bangunweb.com"
export ANTHROPIC_AUTH_TOKEN="bwr_live_..."
# optional: choose the default model
export ANTHROPIC_MODEL="claude-sonnet-4.6"
- Start Claude Code in your project folder with
claude. Requests now go to the router and are billed from your prepaid balance.
To make it permanent, add the exports to ~/.bashrc or ~/.zshrc. Variable names can change between Claude Code releases, so if something does not take effect, check the current Claude Code settings documentation.
Test the endpoint with curl first
Before you debug a full agent session, confirm the key and URL work with one request:
curl https://router.bangunweb.com/v1/messages \
-H "x-api-key: bwr_live_..." \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4.6",
"max_tokens": 200,
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'
A JSON reply with a content array means the connection, key and balance are fine. To see which model slugs your key can call, run GET /v1/models. The full list with live prices per 1M tokens is on the AI models and prices page, and endpoint details are in the API docs.
Common errors and quick fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| 404 on every request | Base URL includes an extra /v1 or a typo | Use https://router.bangunweb.com only |
| 401 unauthorized | Wrong or missing key | Re-copy the bwr_live_... key and re-export it |
| Claude model refused or not available | Claude is not unlocked yet | Make your first token purchase, then retry |
| Insufficient balance | Prepaid tokens used up | Top up and retry the request |
| Old settings still used | Shell not reloaded | Open a new terminal or run source ~/.zshrc |
Keep coding-agent costs under control
Coding agents re-send large chunks of context on almost every turn, so a long session can burn through tokens faster than you expect. Three habits help:
- Match the model to the task. Use a strong Claude model such as Claude Opus 5.5 for hard refactors and planning. Use a smaller or cheaper model for boilerplate, renames and docs.
- Start fresh sessions. Clear or restart the conversation when you switch tasks so old context is not billed again and again.
- Estimate before you commit. Our guide to estimating AI API cost per request shows how to turn input and output tokens into a budget.
Because the balance is prepaid with no subscription, your spend stops at what you loaded. That makes it easier to experiment without a surprise bill.
A practical workflow for a first week
If you are new to a gateway, do not move your whole workflow on day one. A short trial plan keeps risk low:
- Day one: run the curl test, then open Claude Code on a small side project and ask for a simple change, such as adding a unit test.
- Days two and three: work on a real task and watch how quickly your balance drops. Compare that with your estimate from the cost guide above.
- Rest of the week: try switching the
ANTHROPIC_MODELvariable between a premium model and a cheaper one, and note where the cheaper model is good enough.
You will quickly learn which tasks justify a top-tier model and which do not. The Top Model board also shows which models other developers used most over the last seven days, which is a useful starting point when you are unsure what to try.
Use cheaper models in other OpenAI-compatible tools
The same key also works on the OpenAI-compatible endpoint, so tools like OpenCode, Cline, Cursor or n8n can share one balance with Claude Code. Set the base URL to https://router.bangunweb.com/v1:
from openai import OpenAI
client = OpenAI(
base_url="https://router.bangunweb.com/v1",
api_key="bwr_live_...",
)
resp = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "Write a Python function that reverses a string."}],
)
print(resp.choices[0].message.content)
This is handy for routine edits where a low-cost model is good enough. Check the DeepSeek family page for live prices, and see the OpenCode setup guide for a second agent on the same key.
Is a gateway right for you?
A custom base URL is a good fit when you want one key and one balance across several model families, or when you cannot pay official providers with a card. If you already use another gateway, the OpenRouter alternative comparison and the price comparison page explain the trade-offs honestly, including when another option fits better. Always follow each model provider's terms of service, and do not share your key with others.
Next step
Create your key, load a prepaid balance and point Claude Code at the router. Start on the Claude API page to see available Claude models and live prices, or read the pay-as-you-go page to see how prepaid billing works without a credit card.