OpenCode "Upstream request failed: Invalid credential": the fix
OpenCode's own gateway refusing a stored Console (Zen) or Go key, often one retired in the console migration. How to replace it, on a server too.
“Upstream request failed: Invalid credential” is OpenCode’s own service refusing the OpenCode key or sign-in that OpenCode has stored, the one for OpenCode Console (Zen) or OpenCode Go, not a key for Anthropic, OpenAI or another provider. A maintainer’s explanation on the tracker: “This happens when your stored OpenCode API key has expired. Several older keys stopped working after the console migration.” The fix is to replace what is stored: run opencode auth login (or /connect) and sign in to OpenCode again, or create a new API key in the OpenCode Console and connect that one. The key is the problem, not the install, so reinstalling or switching models does not help.
Which credential it means
OpenCode sends requests for its own models, the opencode/… and opencode-go/… ones, through OpenCode’s gateway, and “upstream” is that gateway. When it does not accept the key, OpenCode prints the gateway’s answer:
Error: Upstream request failed: Invalid credentialCopiedOn a report where a key failed the same way inside Docker and outside it, the maintainer put it plainly: “Invalid credential means the gateway doesn’t recognize the key itself, so it isn’t the container.” The causes named there were a revoked key, a key copied incompletely, and a deleted workspace or service account, and the issue was closed as “key-specific rather than an OpenCode bug”. A key from Anthropic or OpenRouter that has gone bad produces that provider’s own error, not this one.
As of November 17, 2026, a search of OpenCode’s issue tracker for “Invalid credential” returned 47 issues and pull requests, from October 12 to November 16, several of them from people who had just paid for Go or topped up the Console and found nothing worked.
Replace the stored key
Start by seeing what OpenCode holds:
opencode auth listCopiedThen sign in again, and from the list choose OpenCode (the Console, Zen) or OpenCode Go, pasting a key from the Console for Go:
opencode auth loginCopiedIn the TUI, /connect does the same: OpenCode’s Go docs say “Run /connect in the TUI, select OpenCode Go, and paste your API key.” Choosing a provider you have already connected opens its list of saved accounts, where the old one can be deleted, and per the providers docs “The newest account becomes active” either way. To remove the old entry from the command line, opencode auth logout opens a picker.
Where signing in is not enough, make a new key. The maintainer’s steps: in the Console, Account, then Personal API keys, create a key in the workspace that holds your credit or your Go subscription, and copy it at once, because “it’s only shown once.” Connect it as above. If a new key from that workspace still fails, OpenCode’s maintainers ask for an email to help@anoma.ly with your account email and workspace name.
On a server
- The login is interactive. “API-key entry and provider forms require an interactive terminal,” so run
opencode auth loginin an SSH session, not from a cron job or a script. A report from a headless server over SSH in tmux got working again this way. - The background service reads the same store. “Saved API keys and OAuth tokens live in the server’s SQLite database,” so a key replaced from the command line is the one the background service and
opencode runuse next. - An old key came along with the upgrade. Version 1 kept keys in
~/.local/share/opencode/auth.json, and “V2 imports supported credentials from the legacyauth.json” when it first runs. A key saved months ago on version 1 can be the one that stopped working, even on a fresh version 2 install; moving from OpenCode 1 to 2 covers what else the upgrade carries over.
The week it hit everyone
From October 12 to 14, 2026, the message also reached people with no key at all, on the free models. OpenCode’s triage bot, on the main issue, said OpenCode’s model list had moved its provider to a new endpoint that rejected signed-out requests, and some users pointed the opencode provider back at https://opencode.ai/zen/v1 in opencode.json to get going. Users then reported the service side fixed and the override itself breaking the free models. If your config still has that baseURL line, remove it; the free-tier refusal’s guide covers the message it now tends to cause.
Messages that sit next to it
- “This API key has expired. Create a new API key in OpenCode Console and replace it in your client or secret store.” The same cause, said outright, followed by “Signing in again will not renew this key.” Make a new key as above. The open issue about its wording was filed by someone for whom reconnecting OpenCode with
/connectworked anyway. - “Upstream request failed: Insufficient account funds” after a new Go key: in the report above, the model in use was not a Go model. Pick one whose name starts
opencode-go/in/models; a Console model draws on the pay-as-you-go balance, which OpenCode’s pricing sets out beside Go. - “Free usage limit reached” or today’s free messages used up: a daily allowance, not a key, covered in OpenCode’s free usage limit.