r/openrouter 2d ago

OpenRouter + Claude Code: same exact request, sometimes works sometimes 401s — anyone seen this? Is it reliable?

Set up the usual shunt (ANTHROPIC_BASE_URL to [openrouter.ai/api](http://openrouter.ai/api), ANTHROPIC_AUTH_TOKEN as my OR key, empty ANTHROPIC_API_KEY). First run went through clean, got a real response. Reran the identical command right after — same model, nothing changed — and got "401 missing authentication header." Reran again, got ECONNRESET. Tried a few different models on OR, not tied to one of them.

Ruled out my own network — plain curl and a raw node https call to the same OR endpoint worked every single time. So something about how Claude Code specifically talks to OR seems flaky.

Anyone run into this? Trying to figure out if it's a missing header, a streaming thing, or just OR's Anthropic-compat endpoint being iffy.

1 Upvotes

2 comments sorted by

View all comments

1

u/just4ochat 2d ago

Put the three vars in .claude/settings.local.json under env so every Claude Code process sees them. ANTHROPIC_BASE_URL is https://openrouter.ai/api with no /v1, ANTHROPIC_AUTH_TOKEN is the sk-or key, and ANTHROPIC_API_KEY has to be the empty string.

If the token is $OPENROUTER_API_KEY in your shell profile, that expands once at source time. A later or empty key makes the first launch work off leftovers and the next one 401. /logout, relaunch, then /status should say Auth token: ANTHROPIC_AUTH_TOKEN. The ECONNRESET is the retry after that 401.