Claude Code · API key
Claude Code API key: get one and set it up in 1 minute
Claude Code can run on an API key instead of a Claude plan login. Create a key on aicodewith, add two environment variables, and every request is billed per token from your prepaid balance. This page covers where to get the key, where to put it, and how to check that it works.
Last checked
API key vs subscription login
Claude Code has two ways to authenticate. With /login it uses your Claude Pro or Max plan, and usage counts against that plan's 5-hour and weekly allowance. With an API key it sends requests to the API endpoint you configure, and you pay per token.
| Subscription login | API key (pay as you go) | |
|---|---|---|
| How you pay | Fixed monthly plan price | Per token, deducted from a prepaid balance |
| Limits | 5-hour session and weekly allowance | Rate and concurrency limits; your own spend caps per key |
| Works in CI, scripts and shared servers | Tied to one person's login | Yes, one key per job or teammate |
| Usage tracking | Settings > Usage in your Claude account | Per-key usage records in the dashboard, plus /cost |
| Setup | /login in Claude Code | Two environment variables |
When an API key is configured, Claude Code bills that key and does not use your Claude plan allowance. Remove the variables and run /login to switch back.
Where to get a key and how to top up
1. Sign up
Create an account on aicodewith.ai with email, Google or GitHub.
2. Top up your balance
Billing is prepaid. International accounts pay in USD by card through Stripe; mainland China accounts pay in CNY through Alipay. The billing region is chosen on your first top-up and the minimum amount is shown at checkout.
3. Create the key
Open API Keys in the dashboard and create a key. Optionally set a daily, monthly or total spend cap. Copy the key; you will paste it into Claude Code next.
Your balance is charged per token at the price of the model and channel you use. Credits are valid for one year, and unused balance can be refunded within 90 days of the top-up with a 10% fee deducted.
Top-up optionsPayments and refunds FAQRefund policy
| Model (USD per 1M tokens) | Anthropic list price, input / output | Cache read / 5-min cache write (list) | aicodewith Economy channel, input / output |
|---|---|---|---|
| Claude Opus 5.5 | $4.00 / $20.00 | $0.20 / $5.00 | from $0.76 / from $3.80 |
| Claude Sonnet 5.5 | $2.00 / $10.00 | $0.10 / $2.50 | from $0.38 / from $1.90 |
| Claude Haiku 5.5 | $0.10 / $0.50 | $0.01 / $0.125 | from $0.019 / from $0.095 |
"From" prices are based on the Economy channel, the lowest-priced Claude channel currently listed (about 19% of Anthropic list price). Other channels cost more; the rate depends on the channel you choose, and the models page is always the source of truth.
Where to put the key
Pick one place. settings.json is the most reliable because the Claude Code CLI and its IDE extensions all read it. Shell variables are handy for a quick test or a CI job.
1. Option A: ~/.claude/settings.json (recommended)
macOS and Linux: ~/.claude/settings.json. Windows: %USERPROFILE%\.claude\settings.json. Create the file if it does not exist, and merge the env block if it does.
~/.claude/settings.json{ "env": { "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY", "ANTHROPIC_API_KEY": "", "ANTHROPIC_BASE_URL": "https://api.aicodewith.ai" } }2. Skip the first-run sign-in screen
On a fresh install, add this field to ~/.claude.json so Claude Code does not ask you to sign in to an Anthropic account. If the file exists, add the field instead of overwriting it.
~/.claude.json{ "hasCompletedOnboarding": true }3. Option B: shell environment variables
Add these lines to ~/.zshrc or ~/.bashrc (or export them in a CI step), then open a new terminal.
bash / zshexport ANTHROPIC_BASE_URL="https://api.aicodewith.ai" export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY" export ANTHROPIC_API_KEY=""4. Option B on Windows (PowerShell)
Sets user-level variables. Open a new terminal afterwards.
PowerShell[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://api.aicodewith.ai", "User") [Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "YOUR_API_KEY", "User")
ANTHROPIC_BASE_URL is the bare domain https://api.aicodewith.ai. Do not add /v1; Claude Code appends the path itself and /v1 leads to 404 errors.
ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY?
| Variable | What Claude Code does with it | For aicodewith |
|---|---|---|
| ANTHROPIC_AUTH_TOKEN | Sends it as Authorization: Bearer <key> | Put your aicodewith key here |
| ANTHROPIC_API_KEY | Sends it as an x-api-key header; meant for Anthropic Console keys | Leave it empty |
| ANTHROPIC_BASE_URL | Where requests go | https://api.aicodewith.ai |
Setting ANTHROPIC_API_KEY to an empty string matters: if an old Anthropic key is still exported in your shell, it can be sent instead of your aicodewith key and the request fails with 401.
Check that it works, and what errors mean
- Close every Claude Code session and run claude again.
- Run /status and confirm the API endpoint shows api.aicodewith.ai.
- Send a short message. The request and its charge appear in the dashboard usage records.
- Run /cost to see the session's per-token cost.
| What you see | Likely cause | Fix |
|---|---|---|
| 401 / invalid API key | Key mistyped or deleted, or a leftover ANTHROPIC_API_KEY is sent instead | Copy the key again, set ANTHROPIC_API_KEY to empty, run echo $ANTHROPIC_API_KEY to check |
| 404 Not Found | Base URL ends in /v1 or has a typo | Use https://api.aicodewith.ai exactly, then restart |
| Still asks you to log in, or shows your plan's limit message | Config not loaded; Claude Code is still on the subscription login | Check the settings.json path and that the JSON is valid, restart, run /status |
| Insufficient balance | Prepaid balance or the key's spend cap is used up | Top up or raise the cap; nothing is charged automatically |
| 429 / rate limited | Request rate or concurrency above the rate limit | Run fewer parallel subagents and retry after a moment |
One key on several projects and machines
A key is not tied to a device or a project. Use the same key on your laptop, a dev server and CI, or create one key per project, teammate or pipeline. Separate keys give you separate usage records and separate spend caps, and you can delete one without touching the others.
- Per-key daily, monthly or total spend caps stop a runaway agent loop from draining the balance.
- Usage records show each request with its model, tokens and cost.
- Treat keys like passwords: keep them out of git, and rotate a key if it leaks.
Next steps
Use Claude Code without a subscriptionClaude Max alternative: pay per tokenClaude Code usage limits explainedClaude Code integration guideDocs
FAQ
Can I use Claude Code with an API key instead of a subscription?
Yes. Set ANTHROPIC_BASE_URL to https://api.aicodewith.ai and ANTHROPIC_AUTH_TOKEN to your key. Claude Code then bills per token from your prepaid balance instead of using a Claude plan allowance.
Should I use ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY?
Use ANTHROPIC_AUTH_TOKEN for your aicodewith key and leave ANTHROPIC_API_KEY empty, so a leftover Anthropic key in your shell is not sent instead.
Does the base URL need /v1?
No. Use https://api.aicodewith.ai only. Claude Code adds the path itself, and /v1 causes 404 errors.
How do I know Claude Code is using my key?
Run /status and check that the endpoint is api.aicodewith.ai, then send a message and look for it in your dashboard usage records. /cost shows the session cost.
Can I use one key on multiple computers?
Yes. A key works anywhere. Create extra keys when you want separate usage records or spend caps per project, teammate or CI job.
Is there a rate limit?
Yes. Rate and concurrency limits apply, and requests above them get a 429 response. You can also set your own daily, monthly or total spend cap on each key.
How do I pay, and can I get a refund?
International accounts pay in USD by card through Stripe; mainland China accounts pay in CNY through Alipay. Unused balance can be refunded within 90 days of the top-up, with a 10% fee deducted.
Is aicodewith affiliated with Anthropic?
No. aicodewith is an independent API platform. Claude and Claude Code are trademarks of Anthropic.
Ready to try it?
Billing is per token from a prepaid balance. Rate and concurrency limits apply, and you can set daily, monthly or total spend caps on each API key.
Related
Sources
Claude and Claude Code are trademarks of Anthropic PBC. aicodewith is an independent platform and is not affiliated with or endorsed by Anthropic. Prices are pulled from live pricing data; list prices are Anthropic list prices. Checked 2026-10-10.