A quick setup for running Claude Code through AgentRouter's free API credits on macOS, Linux, or Windows.
Your normal Claude Code setup stays untouched. These instructions route only the terminal session where you set the AgentRouter variables.
- An AgentRouter account with free credits
- An AgentRouter API token
- Claude Code installed on your computer
AgentRouter expects requests from a supported coding agent. Use Claude Code for this setup rather than a regular chat client.
- Open agentrouter.org and sign in.
- Open API Token from the dashboard sidebar.
- Create a new token and give it a clear name such as
claude-code. - Choose an expiration date, or select no expiration if this is a disposable token.
- Give the token enough quota for your available credits. If the dashboard offers Unlimited quota, enable it so the token can use the full account balance.
- Copy the token when it appears. It starts with
sk-.
Check the model list in your AgentRouter account before continuing. The examples below use claude-opus-5, but you should replace it if your dashboard shows a different model name.
curl -fsSL https://claude.ai/install.sh | bashirm https://claude.ai/install.ps1 | iexYou can also use npm on any supported platform:
npm install -g @anthropic-ai/claude-codeThe npm method currently requires Node.js 22 or newer.
Confirm the installation:
claude --versionOpen a new terminal and run:
export ANTHROPIC_BASE_URL="https://agentrouter.org/"
export ANTHROPIC_AUTH_TOKEN="YOUR_AGENTROUTER_TOKEN"
unset ANTHROPIC_API_KEY
claude --model claude-opus-5$env:ANTHROPIC_BASE_URL = "https://agentrouter.org/"
$env:ANTHROPIC_AUTH_TOKEN = "YOUR_AGENTROUTER_TOKEN"
Remove-Item Env:ANTHROPIC_API_KEY -ErrorAction SilentlyContinue
claude --model claude-opus-5Replace YOUR_AGENTROUTER_TOKEN with the token you copied. Do not include quotation marks inside the token itself.
The base URL should stay at the domain root. Do not add /v1.
This repository includes small launch scripts that ask for your token without saving it to a config file.
chmod +x scripts/start-agentrouter.sh
./scripts/start-agentrouter.shChoose another available model when needed:
AGENTROUTER_MODEL="your-model-name" ./scripts/start-agentrouter.sh.\scripts\Start-AgentRouter.ps1Or choose another model:
.\scripts\Start-AgentRouter.ps1 -Model "your-model-name"Inside Claude Code, run:
/status
Check that the API endpoint points to agentrouter.org. If it shows Anthropic's normal API endpoint, quit Claude Code and launch it again from the terminal where you set the variables.
Open a disposable folder and start Claude Code:
mkdir agentrouter-test
cd agentrouter-test
claude --model claude-opus-5Then ask:
Create a small Python script that prints the current time, run it, and fix any errors.
If Claude creates and runs the script, the setup works. Check AgentRouter's Usage log to confirm that the request used your credits.
Run Claude Code from the project you want it to work on:
cd path/to/your/project
claude --model claude-opus-5Claude Code can build projects, fix bugs, edit documents, analyze local data, and automate repetitive file work. Remember that prompts, file contents, and command output sent to the model pass through AgentRouter.
Close that terminal, or remove the variables from the current shell.
unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN ANTHROPIC_MODELRemove-Item Env:ANTHROPIC_BASE_URL -ErrorAction SilentlyContinue
Remove-Item Env:ANTHROPIC_AUTH_TOKEN -ErrorAction SilentlyContinue
Remove-Item Env:ANTHROPIC_MODEL -ErrorAction SilentlyContinueThe next normal Claude Code session will use your usual login or provider again.
Launch the request through Claude Code. AgentRouter may reject ordinary chat clients or unsupported request formats.
The variables were not applied to the Claude Code process. Quit it, set the variables again in the same terminal, and relaunch.
If ANTHROPIC_API_KEY is already set, remove it for the AgentRouter session because it can override the custom token.
Copy the exact model name shown in your AgentRouter dashboard. Available models can change between accounts.
Check the token's own quota. A token-level cap can stop requests even when the account still has credits.
The $env: commands affect only the current PowerShell window. Run Claude Code in that window, or use the included PowerShell helper.
- AgentRouter is a third-party relay. Avoid sending private repositories, credentials, client data, or anything you would not share with that service.
- AgentRouter's dashboard is the source of truth for remaining credits and usage.
- Free-credit offers, available models, pricing, and access rules can change.
- Use a separate AgentRouter token so you can revoke it without affecting anything else.
MIT