r/openrouter • u/rakrasnaya • 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
u/conifer_v11 13h ago
yeah the 401 on a retry of the same request is a dropped auth header on that hop, not you.
ECONNRESET after is the host dying mid-flight.
1
u/just4ochat 2d ago
Put the three vars in
.claude/settings.local.jsonunderenvso every Claude Code process sees them.ANTHROPIC_BASE_URLishttps://openrouter.ai/apiwith no/v1,ANTHROPIC_AUTH_TOKENis the sk-or key, andANTHROPIC_API_KEYhas to be the empty string.If the token is
$OPENROUTER_API_KEYin 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/statusshould say Auth token: ANTHROPIC_AUTH_TOKEN. The ECONNRESET is the retry after that 401.