AICredits logo
Guides

Claude Code with AICredits

Route Claude Code (Anthropic's CLI coding agent) through AICredits so all requests bill to your INR wallet instead of a direct Anthropic account.

Use this page with an AI assistant

Opens a new chat with this docs URL and the correct AICredits base URLs.

Route Claude Code through AICredits to pay in INR, set per-key budget caps, and see every agentic request in your usage dashboard — all in a two-minute setup.

Prerequisites

  • An AICredits account with credits — top up here
  • Claude Code installed (npm install -g @anthropic-ai/claude-code)
  • Node.js 18+

Setup

1. Create an API Key

Go to Dashboard → API Keys and create a new key. Optionally set a budget limit (e.g. ₹500) to cap what a single Claude Code session can spend.

Copy the key immediately — it starts with sk- and is shown only once.

The most reliable method is to set the env vars inside Claude Code's own settings file. They apply to every session automatically — no shell restarts required.

~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.aicredits.in",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-aicredits-key-here",
    "ANTHROPIC_MODEL": "anthropic/claude-sonnet-4.6"
  }
}

Base URL: with or without /v1?

AICredits has two base URL forms depending on the client:

ClientBase URLWhy
Claude Code / Anthropic SDKhttps://api.aicredits.inThe SDK appends /v1/messages internally — adding /v1 yourself causes a /v1/v1/messages 404
OpenAI SDK, LangChain, cURLhttps://api.aicredits.in/v1These clients append only /chat/completions

Claude Code uses the Anthropic SDK internally, so always use https://api.aicredits.in (no /v1).

Why ANTHROPIC_AUTH_TOKEN and not ANTHROPIC_API_KEY?

When a custom ANTHROPIC_BASE_URL is set, Claude Code uses ANTHROPIC_AUTH_TOKEN as the raw Bearer token. ANTHROPIC_API_KEY is reserved for talking to Anthropic's servers directly. Setting both causes duplicate requests — the gateway gets hit twice per prompt.

3. Verify there are no conflicting variables

If you've ever set ANTHROPIC_API_KEY in your shell profile, it will conflict:

grep -n "ANTHROPIC" ~/.zshrc ~/.bashrc 2>/dev/null

If you see ANTHROPIC_API_KEY, remove or comment it out, then open a new terminal before running claude.

Shell Export Method (alternative)

If you prefer shell env vars instead of settings.json:

~/.zshrc
export ANTHROPIC_BASE_URL=https://api.aicredits.in
export ANTHROPIC_AUTH_TOKEN=sk-your-aicredits-key-here
export ANTHROPIC_MODEL=anthropic/claude-sonnet-4.6
source ~/.zshrc

Env vars are read once at process startup. If you change ~/.zshrc, you must open a new terminal — running source ~/.zshrc in an existing terminal does not affect an already-running Claude Code session.

Verify It Works

Before starting a session, confirm the env is clean:

echo $ANTHROPIC_BASE_URL    # → https://api.aicredits.in
echo $ANTHROPIC_AUTH_TOKEN  # → sk-your-key
echo $ANTHROPIC_API_KEY     # → (should be empty)

Then launch Claude Code and run /status inside the session to confirm the auth method and endpoint.

After your first prompt, check Dashboard → Usage — the request and INR cost should appear within a few seconds.

Supported Models

ModelBest for
anthropic/claude-opus-4.5Complex reasoning, large refactors
anthropic/claude-sonnet-4.6Everyday coding tasks (default)
anthropic/claude-haiku-4.5Fast, lightweight edits

Override the model for a single session:

ANTHROPIC_MODEL=anthropic/claude-opus-4.5 claude

Troubleshooting

401 Unauthorized Your ANTHROPIC_AUTH_TOKEN is missing or invalid. Confirm it's set and that it's an AICredits key (from Dashboard → API Keys), not an Anthropic key.

402 Payment Required Wallet balance is zero or the key has hit its budget cap. Add credits at Dashboard → Billing or raise the key's budget limit.

Requests seem to hit the API twice / usage counts double You have both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN set. Claude Code tries both. Remove ANTHROPIC_API_KEY entirely:

grep -n "ANTHROPIC_API_KEY" ~/.zshrc ~/.bashrc 2>/dev/null
# unset or delete any lines found, then open a new terminal

ANTHROPIC_BASE_URL looks right but billing still goes to Anthropic The env var was set after Claude Code started. Env vars are frozen at process startup — open a new terminal and relaunch claude.

Check balance via API

curl https://api.aicredits.in/v1/credits \
  -H "Authorization: Bearer sk-your-key"
{
  "balance": 842.50,
  "currency": "INR"
}

On this page