Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Free Claude Code API Credit

Get a free API key from AgentRouter and point Claude Code (CLI, desktop app, or IDE extension) at it — no Anthropic subscription needed.

setup.js does the work: it detects Node.js, npm, and the Claude CLI, verifies your key against the live API, writes your config, and wires up the environment variables. Zero dependencies — nothing to npm install.

What AgentRouter is: a community-run ("公益站" / non-profit) gateway that speaks the Anthropic API. Requests are routed through their servers, which means your prompts and code pass through a third party. Use it for hobby projects and experiments, not for confidential work. It offers no uptime guarantee and models come and go.


Table of contents

  1. Step 1 — Create an account (GitHub sign-in)
  2. Step 2 — Get free credit
  3. Step 3 — Create an API key
  4. Step 4 — Automatic setup
  5. Manual setup
  6. Claude Desktop and IDE extensions
  7. Checking your balance
  8. Configuration reference
  9. Troubleshooting
  10. Security notes

Step 1 — Create an account (GitHub sign-in)

Register here: https://agentrouter.org/register

AgentRouter has no email/password signup. The only ways in are OAuth:

  • GitHub (recommended)
  • Linux.do community account

Tip

Refresh the page if only the form appears

How to sign in

  1. Open the registration link.
  2. Click Sign in with GitHub (使用 GitHub 登录).
  3. GitHub shows an Authorize screen listing what the app can read — normally your public profile and email. Click Authorize.
  4. You land on the AgentRouter console, already logged in. There is no email confirmation step.

GitHub account age requirement

AgentRouter runs an anti-abuse check on the GitHub account you sign in with. Brand-new throwaway accounts get rejected or receive no credit — this is standard for NewAPI-based gateways, which typically gate on account age (and sometimes public activity).


Step 2 — Get free credit

Two sources of credit:

  • Signup bonus. New accounts get a starting balance. Third-party write-ups quote figures from $100 to $200, Check your actual balance in the console, or run node setup.js --balance after setup. Whatever a promo claims, the per-key spending cap is what actually governs you.
  • Daily check-in (签到). The site announcements advertise $25 credit for checking in. Log into the console and click the check-in button — doing this daily is the main way to keep a free balance topped up.

Credit is denominated in USD. The gateway bills internally in CNY and converts.


Step 3 — Create an API key

  1. In the console sidebar open Tokens (令牌).
  2. Click Add Token (添加令牌).
  3. Give it a name. Leave the quota unlimited unless you want a per-key cap.
  4. Save, then Copy the key. It looks like sk- followed by ~48 characters.

Copy it now — some builds only show the full key once.


Step 4 — Automatic setup (recommended)

Requires Node.js 18+.

git clone https://github.com/cmalf/Free-Claude-Code-API-Credit.git
cd Free-Claude-Code-API-Credit
node setup.js
Screenshot 2026-08-03 at 23 18 25

It will:

  1. Check your environment — Node.js version, npm, Claude Code CLI, git.
  2. Ask for your API key, base URL, and default model (pressing Enter keeps the shown value).
  3. Verify the key by fetching your real balance.
  4. Write config.json (chmod 600) and agentrouter.env.sh.
  5. Merge the variables into ~/.claude/settings.json — your existing settings are kept and a timestamped .bak-* backup is made first.
  6. Optionally add one source line to your ~/.zshrc / ~/.bashrc.

Then start using it:

source ./agentrouter.env.sh
claude

Ask Claude to "reply with just OK". A reply means routing works.

Other modes

node setup.js --check      # diagnostics only, writes nothing
node setup.js --balance    # credit balance
node setup.js --env        # print the export lines — eval "$(node setup.js --env)"
node setup.js --yes        # non-interactive, uses config.json as-is
node setup.js --help

If the Claude CLI is missing, the script tells you the install command rather than installing a global npm package behind your back:

npm install -g @anthropic-ai/claude-code@latest

Manual setup

If you would rather not run the script.

1. Install the CLI

node --version                                   # must be v18 or newer
npm install -g @anthropic-ai/claude-code@latest
claude --version

2. Export the variables

macOS / Linux (zsh, bash):

export ANTHROPIC_BASE_URL="https://agentrouter.org"
export ANTHROPIC_AUTH_TOKEN="sk-*****"
export ANTHROPIC_MODEL="claude-opus-5"

# If ANTHROPIC_API_KEY is set from something else, clear it — see the note below.
unset ANTHROPIC_API_KEY

Alternate domain — use this if agentrouter.org is unreachable from your network (it is the mirror they publish for users in mainland China, functionally identical):

export ANTHROPIC_BASE_URL="https://ps.air-outer.com"

Windows PowerShell:

$env:ANTHROPIC_BASE_URL="https://agentrouter.org"
$env:ANTHROPIC_AUTH_TOKEN="sk-*****"
$env:ANTHROPIC_MODEL="claude-opus-5"
Remove-Item Env:\ANTHROPIC_API_KEY -ErrorAction SilentlyContinue

To make it permanent, put the export lines in ~/.zshrc or ~/.bashrc; on Windows use setx ANTHROPIC_BASE_URL "https://agentrouter.org".

ANTHROPIC_AUTH_TOKEN vs ANTHROPIC_API_KEY — AgentRouter's own docs use ANTHROPIC_AUTH_TOKEN (sent as Authorization: Bearer). Some tools read ANTHROPIC_API_KEY instead (sent as x-api-key). AgentRouter accepts either, so setting both is the safe default — that is what authVariable: "both" in config.json does.

Do not add /v1 to the base URL. Claude Code appends the Anthropic path itself. The https://agentrouter.org/v1 form is the OpenAI-compatible endpoint, for Codex-style clients.

3. Or use settings.json instead

Environment variables are per-shell. To make it apply everywhere, put them in ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://agentrouter.org",
    "ANTHROPIC_AUTH_TOKEN": "sk-*****",
    "ANTHROPIC_MODEL": "claude-opus-5"
  }
}

Use .claude/settings.json inside a project to scope it to that project only.

Precedence: real shell variables override settings.json. If you set both and they disagree, the shell wins.

4. Verify

claude

At the first prompt, Claude Code asks you to confirm it is using an API key from the environment. Accept, then send a trivial message. Check node setup.js --balance — the used amount should have gone up.


Claude Desktop and IDE extensions

The Claude Desktop chat signs in with your Anthropic account, not an API key, so a third-party gateway cannot be plugged into the chat UI.

What does work: Claude Code inside the desktop app reads ~/.claude/settings.json. Run node setup.js, let it write that file, then fully quit and reopen the desktop app — the Claude Code panel routes through AgentRouter.

Same for the VS Code / JetBrains extensions: they read ~/.claude/settings.json. Restart the editor after setup.


Checking your balance

node setup.js --balance
  ✓ Credit  $-- left of $-- — used $-- (-.--%), valid until no expiry

The number comes from the gateway's live billing endpoints, so it reflects real usage, not a cached figure.


Configuration reference

Copy config.example.json to config.json and edit it, or just run node setup.js.

{
  "baseUrl": "https://agentrouter.org",
  "fallbackUrl": "https://ps.air-outer.com",
  "apiKey": "sk-REPLACE_WITH_YOUR_AGENTROUTER_KEY",
  "model": "claude-opus-5",
  "smallFastModel": "",
  "authVariable": "ANTHROPIC_AUTH_TOKEN",
  "targets": {
    "claudeCode": true
  },
  "writeShellProfile": false
}
Key Purpose
baseUrl Primary endpoint. No /v1 suffix.
fallbackUrl Tried automatically if baseUrl is unreachable; on success it is saved as the new baseUrl.
apiKey Your sk-... token.
model Value for ANTHROPIC_MODEL.
smallFastModel Optional ANTHROPIC_SMALL_FAST_MODEL, used for cheap background tasks. Empty = omit.
authVariable "both", "ANTHROPIC_AUTH_TOKEN", or "ANTHROPIC_API_KEY".
targets.claudeCode Merge into ~/.claude/settings.json.
writeShellProfile Add one source line to ~/.zshrc / ~/.bashrc, between # >>> agentrouter >>> markers. Re-running replaces the block instead of duplicating it.

Models

Model availability changes often on a free gateway. Query the live list:

curl -s https://agentrouter.org/v1/models \
  -H "Authorization: Bearer $ANTHROPIC_API_KEY" \
  -H "User-Agent: claude-cli/2.0.0 (external, cli)" | jq -r '.data[].id'

The User-Agent header is required — see troubleshooting below. If your configured model disappears from that list, pick another one from it.


Troubleshooting

unauthorized client detected / HTTP 401 on a working key

AgentRouter fingerprints the client User-Agent and rejects anything it does not recognise as a supported CLI. Your key is fine; your curl is the problem. Add:

-H "User-Agent: claude-cli/2.0.0 (external, cli)"

Claude Code sends an accepted UA on its own, so this only bites manual curl calls. Note this is a client allowlist, not a security feature — don't read it as permission to hammer the API from scripts; the operators ban for bulk automated use.

无效的令牌 / "invalid token" — the key is wrong, revoked, or missing its sk- prefix. Recreate it in the console.

Response is HTML instead of JSON — you hit a front-end route rather than an API path, or a captive portal intercepted the request.

Claude Code still uses my Pro/Max subscription — these variables override a subscription login, but only in shells where they are set. Conversely, to get your subscription back:

unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN ANTHROPIC_API_KEY ANTHROPIC_MODEL

and remove the env block from ~/.claude/settings.json. Restart claude.

Nothing changed after running setup — a shell variable is shadowing settings.json. The script warns when it detects this. Run node setup.js --check, then either unset the old ones or re-source ./agentrouter.env.sh.

Network unreachable — try the alternate domain https://ps.air-outer.com. The script does this automatically.

404s, timeouts, model gone — the gateway is a free service with real downtime; announcements have mentioned upstream failures and Claude models being pulled. Check their Discord before debugging your own setup.


Security notes

  • Everything you send through the gateway is visible to whoever operates it. Do not point it at a private or client codebase.
  • setup.js backs up ~/.claude/settings.json and your shell profile before editing (.bak-<timestamp>), and never installs anything globally without telling you.

Sources

The balance endpoints and the User-Agent requirement were verified against the live API. Credit amounts and the GitHub account-age threshold are not officially documented — verify in the console.

License

MIT. Not affiliated with Anthropic or AgentRouter.

About

Get Free $100 - $200 Claude Code API Credit,and point Claude Code (CLI, desktop app, or IDE extension) at it — no Anthropic subscription needed.

Topics

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages