OpenCode setup guide
Provider config in opencode.json, model IDs per plan, and how to check common errors.
Signing in again will not renew an expired OpenCode Console key. Create a new key in the Console, clear stale local credentials, and check shell environment overrides to get back to work.
Fastest fix: Open OpenCode Console, go to Personal API keys, create and copy a new key, run opencode auth logout followed by opencode auth login to save it, check env | grep -i opencode for stale shell variables, and restart your OpenCode session or IDE extension.
When calling OpenCode Zen or OpenCode Go models, you may hit this exact error:
This API key has expired. Create a new API key in OpenCode Console and replace it in your client or secret store. Signing in again will not renew this key.The last sentence is the detail most people miss: signing back in will not renew the expired key. Once a Console key hits its expiration date (TTL) or gets rotated or revoked in your workspace, the server rejects every request carrying that credential. You have to generate a fresh key in OpenCode Console and replace every local copy of the old one.
A common frustration is generating a new key in the Console and still seeing the exact same expiration error in the terminal. That almost always means an older copy of the key is still stored locally and taking precedence over the new one.
| Failure mode | How to check | Exact fix |
|---|---|---|
| Expired or revoked Console key | Sign in to OpenCode Console and open Personal API keys to check status and expiration | Create a new API key, copy it immediately, and delete the expired entry |
Stale credential in auth.json | Inspect ~/.local/share/opencode/auth.json for the affected provider | Run opencode auth logout to clear the old token, then opencode auth login with the new key |
| Shell env var overriding local auth | Run env | grep -i opencode in the failing shell and check project .env files | Update or remove OPENCODE_API_KEY / OPENCODE_ZEN_API_KEY, then unset or open a new shell |
Hardcoded key in opencode.json or un-restarted service | Check ~/.config/opencode/opencode.json, project .opencode.json, and running IDE extensions | Remove hardcoded old keys or reference an env var, then restart the OpenCode background service and editor |
Walking through the four steps below clears both the server-side key and every local cache.
Start by issuing a fresh credential in the Console.
https://opencode.ai/console and sign in to your account.Delete the expired key from the list while you are there so it does not cause confusion during future troubleshooting.
The OpenCode CLI stores provider credentials in ~/.local/share/opencode/auth.json. Clear the stale entry first, then save the new key:
opencode auth logoutopencode auth loginWhen prompted by opencode auth logout, select the provider whose key expired (such as OpenCode Zen). Then run opencode auth login, pick the same provider, and paste the new key from the Console.
If you want to verify that the local credential file was updated cleanly, check it directly:
ls -la ~/.local/share/opencode/auth.jsonMake sure no stale token remains for that provider before testing a new request.
If OpenCode still returns This API key has expired right after opencode auth login, check your shell environment. An exported OPENCODE_API_KEY or OPENCODE_ZEN_API_KEY in your shell profile or project .env can override the newly saved auth.json entry.
Run this check in the same terminal window where OpenCode failed:
env | grep -i opencodeIf an old key shows up, clean it up in three places:
unset OPENCODE_API_KEY OPENCODE_ZEN_API_KEY~/.zshrc, ~/.bashrc, and ~/.profile, update or remove any export OPENCODE_API_KEY=... line, and reload your shell.env, .env.local, and your CI secret store so nothing re-injects the expired keyopencode.json and restart active sessionsOpen your global ~/.config/opencode/opencode.json and any workspace-level ./.opencode.json to make sure an expired key is not hardcoded inside a provider or providers block.
Finally, restart any running OpenCode TUI session, background service, desktop app, or IDE extension (such as VS Code). Long-lived processes can keep an older credential in memory until restarted.
opencode.json as a backup providerIf you rely on OpenCode every day and want a second provider ready whenever a workspace key expires or gets rotated, you can configure CodingPass alongside your existing setup in ~/.config/opencode/opencode.json and switch in seconds via /models.
CodingPass gives you access to all 25 models (including Claude Sonnet 5.5, Opus 5.5, DeepSeek, and Kimi) under one monthly allowance: Go starts at $10/mo (about 2,050 requests on Sonnet 5.5), and Plus is $30/mo. See the full model catalog and pricing for tier details.
Following the OpenCode setup guide, add the codingpass provider block to ~/.config/opencode/opencode.json:
{ "$schema": "https://opencode.ai/config.json", "model": "codingpass/claude-sonnet-5-5", "providers": { "codingpass": { "name": "CodingPass", "env": ["CODINGPASS_API_KEY"], "package": "@opencode/ai/providers/anthropic", "settings": { "baseURL": "https://codingpass.ai/v1" }, "models": { "claude-sonnet-5-5": { "name": "Claude Sonnet 5.5" }, "claude-opus-5-5": { "name": "Claude Opus 5.5" }, "deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash" } } } }}Then store your CodingPass API key in the OpenCode service environment:
opencode service set env CODINGPASS_API_KEY cp-live-...Start opencode, type /models, and pick any configured CodingPass model. The desktop app reads the same config automatically.
The error applies to the API key created in OpenCode Console, not your browser login session. As the message states (Signing in again will not renew this key), an expired or revoked key stays permanently invalid on the server until you create a replacement in the Console and update your local client.
Credentials can live in three places: ~/.local/share/opencode/auth.json (written by opencode auth login or /connect), environment variables such as OPENCODE_API_KEY or OPENCODE_ZEN_API_KEY, and ~/.config/opencode/opencode.json (or project ./.opencode.json). A stale environment variable frequently overrides a fresh auth.json entry, which is why running env | grep -i opencode is the quickest sanity check.
Yes. OpenCode supports multiple providers in the same opencode.json file. Keep your existing OpenCode Zen or Go setup, add the codingpass provider block, and switch between them anytime with /models. Full instructions are in the OpenCode setup guide.
Keep using OpenCode as usual. Add CodingPass to opencode.json from