Aller au contenu principal
alexis_amzFR / EN
← Back to blog

AgentRouter: Free Claude and GPT Credits, and the OpenCode 401 Error Fixed

Free AgentRouter credits for Claude Opus 5 and GPT-6: welcome credit, $50 referral bonus, $25 a day. Plus the fix for the OpenCode 401 error.

Your AI agent does the setup for you, on your machine.

Published// agentrouter-free-credits
AgentRouter: Free Claude and GPT Credits, and the OpenCode 401 Error Fixed

TL;DR

  • What you get: a welcome credit, a $50 bonus through a referral link, then $25 a day by checking in. Details below.
  • Requirement: a GitHub account that is old enough and active (or a LinuxDO account), and a signup through my referral link for the $50 bonus.
  • The catch: OpenCode throws 401 unauthorized client detected if you plug it in directly. A 300-line local proxy with no dependencies fixes it.
  • Time: about five minutes.
  • Checked on September 24, 2026 against AgentRouter's official FAQ. The welcome credit changes often.

API credits are what makes coding with agents expensive. An agent refactoring a project on Claude Opus makes dozens of round trips, and the bill follows.

AgentRouter gives out free credits on top coding models, no credit card needed. This guide shows you how to claim them, then how to use them in OpenCode without hitting the 401 error that stops most people on their first launch.

Create my AgentRouter accountReferral link: +$50 bonus. Sign up from the page that opens.

Got Claude Code, Codex or Cursor on your machine? The Send to an agent button at the top of the page hands it the whole setup. All that's left for you is creating the account with that link.

What is AgentRouter?

An OpenAI-compatible API router. One key, one URL, and behind it, models from several providers. Any tool that can talk to the OpenAI API can talk to AgentRouter.

Four models are available right now (list checked on September 24, 2026):

  • claude-opus-5
  • claude-opus-4-8
  • gpt-6-astra
  • deepseek-v4-flash

The first three are the strongest for agentic coding, but they're handed out in limited daily batches. DeepSeek V4 Flash is the fallback when they run out (see the 402 error). The list changes now and then: once you're signed up, AgentRouter's Pricing page is the reference.

How many credits can you get?

The total varies from one person to the next, because it adds up several sources. The official FAQ puts a number on every source except the welcome credit:

  • Welcome credit, paid once at signup. It's the only amount that isn't published, and it changes often: it has been $150, then $175, and September 2026 signups report $200.
  • Referral bonus: $50, once, if you sign up through an invite link.
  • Daily check-in: $25 a day. Checking in means clicking the check-in button in the dashboard once a day. The balance only refreshes after you log out and back in.
  • Gift codes, now and then: draws for accounts with a linked email, and one-off giveaways from AgentRouter.

There's no paid top-up: you can't buy credits.

One detail matters more than the balance: Claude and GPT are handed out in limited daily batches, at 02:00 and 11:00 UTC. Having credits doesn't guarantee access at any hour.

Step 1: Create the account

Signup only works with GitHub or LinuxDO: no email. AgentRouter checks the GitHub account to block mass signups. An account that's too recent is refused with the message "github账号不符合注册要求" ("the GitHub account doesn't meet the registration requirements").

The exact rule isn't published. Accounts 4 to 5 months old were refused in September 2026, and several sources mention at least one year of age. An older account with some activity (repos, verified email) usually goes through. If your GitHub account is recent, LinuxDO is the other option, but you need an invite to join it.

Open AgentRouter with this link, and sign up right on the page that opens. If you reach AgentRouter any other way (home page, Google, another article), the referral bonus isn't applied.

Open AgentRouter with my linkagentrouter.org/register?aff=FOY1

  1. The site often shows in Chinese. Click the "文A" translate icon at the top right to switch it to English
  2. On the same page, click "Continue with GitHub" ("使用 GitHub 继续" in Chinese), or "Continue with LinuxDO"
  3. Authorize access to your account
  4. The welcome credit and the referral bonus land automatically
  5. Create an API key from the dashboard
  6. Remember to check in every day for the $25

Keep the key handy for the next step, and never commit it to a Git repository.

One rule worth knowing: use a supported coding client: OpenCode, Claude Code, Codex, Cursor, Cline, Roo Code… Non-coding use or an unsupported client puts you in a group where everything costs twice as much.

Disclosure: this is my referral link. It gives you the $50 bonus, and gives me the same. It costs you nothing and supports this guide.

Step 2: Start the proxy

Plugging OpenCode straight into AgentRouter doesn't work (you'll see why further down). A small Python script sits between the two and fixes it.

You need Python 3.10 or newer:

python3 --version

Download the script and put it anywhere you like:

↓agentrouter-proxy.pyPython script · 306 lines · no dependencies

Open a terminal in that folder, hand your key to the proxy, then start it.

macOS / Linux

export AGENTROUTER_API_KEY="your_agentrouter_key"
python3 agentrouter-proxy.py

Windows (PowerShell)

$env:AGENTROUTER_API_KEY="your_agentrouter_key"
python agentrouter-proxy.py

The terminal should print:

agentrouter-proxy :4182 -> https://agentrouter.org

Leave that terminal open. The proxy has to keep running while you use OpenCode. Almost every "it worked yesterday" comes from a closed terminal.

Two practical details:

  • The key only lives in that terminal. To stop retyping it, add the export line to your ~/.zshrc or ~/.bashrc (on Windows: setx AGENTROUTER_API_KEY "your_key").
  • Port 4182 already taken? Use another one: python3 agentrouter-proxy.py 4300, and carry it over to step 3.

Step 3: Connect OpenCode

Open OpenCode's global config, ~/.config/opencode/opencode.json (or an opencode.json at your project root), and add the AgentRouter provider:

json19 lines
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "agentrouter": {
      "name": "AgentRouter",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:4182/v1",
        "apiKey": "{env:AGENTROUTER_API_KEY}"
      },
      "models": {
        "claude-opus-5": { "name": "Claude Opus 5" },
        "claude-opus-4-8": { "name": "Claude Opus 4.8" },
        "gpt-6-astra": { "name": "GPT 6 Astra" },
        "deepseek-v4-flash": { "name": "DeepSeek V4 Flash" }
      }
    }
  }
}

The line that matters: baseURL points to your local proxy, http://127.0.0.1:4182/v1, never to https://agentrouter.org/v1. The proxy adds your real key to each request, so no secret needs to be written in this file.

Restart OpenCode, pick an AgentRouter model, and you're set.

If it doesn't work

Always start with the proxy's terminal. Every OpenCode request shows up there, along with the real error returned by AgentRouter, which says far more than OpenCode's message:

[ar] POST /v1/chat/completions HTTP/1.1
[ar] ERROR 401: unauthorized client detected

To see everything, restart the proxy in debug mode:

AGENTROUTER_DEBUG=1 python3 agentrouter-proxy.py

401 "unauthorized client detected"

OpenCode isn't going through the proxy. Check that the proxy is running and that baseURL is exactly http://127.0.0.1:4182/v1.

If the error persists while everything goes through the proxy, AgentRouter may have raised the OpenCode version it accepts. In the script, set USER_AGENT to opencode/ followed by your version (opencode --version).

"JSON parsing failed" or "Unexpected non-whitespace character after JSON"

Same cause: AgentRouter's response reaches OpenCode without going through the proxy, which is what cleans it up. Fix baseURL.

"Connection refused" on 127.0.0.1:4182

The proxy isn't running, or it was closed. Start it again. If another program holds the port, change the port on both sides.

"ERROR: set AGENTROUTER_API_KEY first"

The proxy can't find your key. Run the export again in the same terminal that starts the proxy.

402 "Budget pool quota has been exhausted"

Today's Claude and GPT batch is used up. It has nothing to do with your account. Wait for the next batch (02:00 or 11:00 UTC), or switch to deepseek-v4-flash, which isn't limited.

"400 content blocked"

AgentRouter only accepts requests in Chinese, English, French, German or Russian. Rephrase your prompt in one of those.

"sensitive words detected"

That's AgentRouter's anti-abuse filter. Start a new session in OpenCode and it goes away.

The AI doesn't answer

If requests show up in the proxy's terminal but nothing comes back, the issue is on AgentRouter's side or with the model. Try another model.

If agentrouter.org is unreachable, AgentRouter runs a backup domain with the same API: start the proxy with AGENTROUTER_UPSTREAM=https://ps.air-outer.com.

The credits don't show up, or the balance reads $0

Log out and back in: the balance only refreshes at login. A $0 balance is also a known display glitch that fixes itself.

If the referral bonus is missing, the signup happened without an invite link.

"github账号不符合注册要求" at signup

Your GitHub account doesn't pass AgentRouter's check, most often because it's too recent. There's no automatic appeal: try an older GitHub account, or LinuxDO. You can also ask for a manual unlock on the official repo, with no guarantee of an answer.

"返回值非法,用户字段为空" after authorizing GitHub

The handoff from GitHub back to AgentRouter failed. Users report it with a VPN on: turn it off and try again.

Why OpenCode needs a proxy

AgentRouter and the SDK OpenCode uses have three incompatibilities. None of them comes from your config.

1. The User-Agent header. AgentRouter only accepts requests that identify as opencode/<version>. The SDK sends something else and gets rejected with a 401, even with a valid key. That's the number one cause of "invalid key" messages when the key is fine.

2. null fields. The SDK sends empty fields such as response_format: null. AgentRouter rejects them with expected object, received null.

3. Billing objects in the response. AgentRouter slips billing.summary and data: null events into the middle of the response stream. The SDK can't read them and parsing breaks.

So the proxy does three things and nothing else: it rewrites the header, strips null fields from requests and filters out those stray events. The code is short and commented, read it before running it if you want to know exactly what runs on your machine.

Using AgentRouter without OpenCode

The proxy is only for OpenCode. In your own code, you can call AgentRouter directly with any OpenAI client. Just send the same User-Agent as the proxy to avoid the 401.

With curl

curl https://agentrouter.org/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $AGENTROUTER_API_KEY" \
  -H "User-Agent: opencode/1.17.12" \
  -d '{
    "model": "claude-opus-5",
    "messages": [
      {"role": "user", "content": "Explain closures in JavaScript"}
    ]
  }'

With Python

python17 lines
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["AGENTROUTER_API_KEY"],
    base_url="https://agentrouter.org/v1",
    default_headers={"User-Agent": "opencode/1.17.12"},
)

response = client.chat.completions.create(
    model="claude-opus-5",
    messages=[
        {"role": "user", "content": "Explain closures in JavaScript"}
    ],
)

print(response.choices[0].message.content)

With JavaScript / TypeScript

javascript16 lines
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.AGENTROUTER_API_KEY,
  baseURL: "https://agentrouter.org/v1",
  defaultHeaders: { "User-Agent": "opencode/1.17.12" },
});

const response = await client.chat.completions.create({
  model: "gpt-6-astra",
  messages: [
    { role: "user", content: "Explain closures in JavaScript" },
  ],
});

console.log(response.choices[0].message.content);

To switch models, change the model string. Nothing else moves.

Wrapping up

Five minutes for free credits on Claude Opus 5, GPT-6 Astra and DeepSeek V4, plus $25 every day you check in. Create the account, start the proxy, point OpenCode at it. And leave the proxy's terminal open.

> Got a project in mind?

Website, photo shoot or video.
Let's talk.

Contact me →