Run Claude Code on a Custom API Endpoint (2026)
Point Claude Code at cloudgpu.app with a custom base URL and a cgw-sk key, map the Haiku slot, check it with one curl and /status, then save it in settings.json.

Claude Code is a terminal agent: it reads your repository, edits files, runs commands and loops until the task is done. That loop is also why it gets expensive on a pay-per-token key. Every step re-sends a large slice of your codebase as input, so a long session can use millions of input tokens before you notice.
Claude Code sends its requests to whatever base URL you give it, as long as the endpoint speaks a supported API format. cloudgpu.app serves the Claude Messages API at /v1/messages under the base URL https://cloudgpu.app (API docs). Point Claude Code there and the tool behaves the same; only where the tokens are billed changes. This guide sets that up with four environment variables, checks it with one request, and then makes it permanent.
What it costs
The per-token rate for every Claude model is on cloudgpu.app/api. That live table is the one that applies to your bill; rates can change, so this guide does not repeat them.
Step 0: install Claude Code
Install Claude Code with the native installer or with Homebrew:
curl -fsSL https://claude.ai/install.sh | bash
# or
brew install --cask claude-code
Step 1: create an account, add balance, get a key
- Sign up at cloudgpu.app with an email address or a Google account.
- Top up on the billing page. Visa and Mastercard, Alipay (offered in most countries) and Google Pay / Apple Pay share one checkout; USDT on TRC-20 is accepted; business customers can pay by bank transfer against an invoice (payments). API calls are then charged per token from that prepaid balance, with no monthly minimum.
- In the API console, create a key and copy the
cgw-sk-...value. It is shown once and only a hash is stored, so a lost key cannot be recovered; create a new one instead (API docs).
Step 2: point Claude Code at the endpoint
Set four environment variables in the shell you launch Claude Code from:
export ANTHROPIC_BASE_URL=https://cloudgpu.app
export ANTHROPIC_AUTH_TOKEN=cgw-sk-...
export ANTHROPIC_MODEL=claude-sonnet-5-5 # or claude-opus-5-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-sonnet-5-5
claude
What each one does:
ANTHROPIC_BASE_URLis the bare host. Claude Code appends/v1/messagesitself, so do not add/v1.ANTHROPIC_AUTH_TOKENis sent asAuthorization: Bearer, which is the header cloudgpu.app expects (Authorization: Bearer cgw-sk-<your_key>).ANTHROPIC_MODELsets the main model for the session. Use a model ID exactly as it appears on /api. Sonnet 5.5 is a sensible default; Opus 5.5 costs more per token and is worth it for hard refactors and long agentic tasks.ANTHROPIC_DEFAULT_HAIKU_MODELis the one people skip and then wonder why things break. It controls what thehaikualias resolves to, and Claude Code uses that slot for small background jobs. The cloudgpu.app model list has no Haiku model, so map the slot to a model that is listed. Those background calls are then billed at that model’s rate; they are small, but they are not free.
If you switch models mid-session with /model, pin the other aliases too, so they resolve to IDs the endpoint serves:
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-5-5
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5-5
Step 3: check it works
The Claude Code docs recommend one direct request before you open Claude Code, so a failure points at the endpoint rather than your configuration:
curl -sS -w '\n%{http_code}\n' -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-sonnet-5-5", "max_tokens": 1, "messages": [{"role": "user", "content": "."}]}'
A JSON body that starts with {"id":"msg_ means the URL and key work. Then start claude from the same shell and run a one-shot prompt:
claude -p "Reply with the single word: ok"
Inside an interactive session, /status should show https://cloudgpu.app as the base URL and name ANTHROPIC_AUTH_TOKEN as the credential. Finally, open the API console: successful calls show there with token counts and cost.
Step 4: make it permanent in settings.json
Claude Code reads an env block from ~/.claude/settings.json and applies it to every project. When a shell export and the settings file disagree, the settings file wins:
{
"env": {
"ANTHROPIC_BASE_URL": "https://cloudgpu.app",
"ANTHROPIC_AUTH_TOKEN": "cgw-sk-...",
"ANTHROPIC_MODEL": "claude-sonnet-5-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-5-5"
}
}
If the file already exists, merge these keys into it rather than replacing it. Never put the key in a project’s .claude/settings.json: that file is committed and shared with everyone who clones the repository.
Errors you may hit
| What you see | What it means |
|---|---|
404 on every request |
The base URL ends in /v1. Use the bare host https://cloudgpu.app. |
401 on the verify request |
The key is in the wrong variable or header. ANTHROPIC_AUTH_TOKEN sends Authorization: Bearer. If you were signed in to Claude Code with another account, run /logout and start a new session. |
| Errors only on background tasks | ANTHROPIC_DEFAULT_HAIKU_MODEL is missing. |
400 model_not_found |
The model ID is not in the catalog. List the IDs with GET /v1/models. |
402 insufficient_balance |
The balance has run out. Top up. |
429 rate_limit_exceeded |
Default limits are 100 requests per minute per key and 10,000 per day per account; they can be raised on request. |
How to keep the bill small
Claude Code spends most of its tokens on input, so the habits that cut input matter most:
- Default to Sonnet. Run most work on
claude-sonnet-5-5and switch to Opus with/modelonly for the task that needs it. - Clear context between tasks. Use
/clearwhen you move to something unrelated, instead of dragging a long history into the next task. - Scope the work. Point Claude Code at the directory or files that matter. A smaller working set means fewer tokens on every step.
- Watch the first day. Top up a small amount, look at the usage in the console after a normal day of work, and only then decide how large a balance makes sense. The balance is prepaid and does not expire.
Trade-offs to know first
- Not official. cloudgpu.app is independent and not affiliated with the model vendor. You get API access billed from a prepaid balance, not a first-party account.
- No automatic failover, no SLA. CloudGPU is in public beta. If the upstream for a model has an outage, your sessions stop until it recovers, so keep a second way to run Claude Code configured if an outage would block you.
- Privacy. Prompt and completion content is not logged; token counts, model, response times and error codes are kept for billing.
- Prices move. The /api page always shows the current ones.
FAQ
Is this an official Claude Code plan? No. cloudgpu.app is an independent service with no partnership with, authorization from, or endorsement by the model vendor. You pay per token from a prepaid balance.
What happens to my claude.ai subscription while the variables are set? While a gateway credential variable is active, requests carry that credential instead of your claude.ai login, and the subscription’s usage limits do not apply to them. The login stays saved and is used again when you unset the variable.
Should the base URL end in /v1?
No. Use the bare host, https://cloudgpu.app. Claude Code adds /v1/messages; a base URL ending in /v1 produces a doubled path and a 404.
Why do I have to map the Haiku slot?
Claude Code uses the Haiku slot for background tasks, and there is no Haiku model on cloudgpu.app. Mapping the slot to claude-sonnet-5-5 makes those calls work; they are billed at Sonnet rates.
Does the same key work with the OpenAI SDK?
Yes. For OpenAI-format calls, set the SDK’s base URL to https://cloudgpu.app/v1.
If you mostly want Claude in an editor rather than a terminal agent, see Claude in Cursor, Cline and Continue. Create your key at cloudgpu.app/api.
Sources
All read on 24 October 2026 (Beijing time, UTC+8).
- cloudgpu.app payment methods: https://cloudgpu.app/payments (12:30)
- cloudgpu.app model list, prices, rate limits, logging, failover, disclaimer: https://cloudgpu.app/api (12:30)
- cloudgpu.app API reference (base URL, auth header, keys, error codes): https://cloudgpu.app/api/docs (12:30)
Try cloudgpu.app — no credit card required
No credit card required. Per-minute billing, deploy in about 2 minutes.