查看中文版 →

Deutsche Version ansehen →

Открыть русскую версию →

Ver versión en español →

Log in
Blog · Setup guides

OpenCode “This API key has expired”: Console key reset guide

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.

Where the old key usually hides

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.

Common causes of the OpenCode API key has expired error and how to fix each one
Failure modeHow to checkExact fix
Expired or revoked Console keySign in to OpenCode Console and open Personal API keys to check status and expirationCreate a new API key, copy it immediately, and delete the expired entry
Stale credential in auth.jsonInspect ~/.local/share/opencode/auth.json for the affected providerRun opencode auth logout to clear the old token, then opencode auth login with the new key
Shell env var overriding local authRun env | grep -i opencode in the failing shell and check project .env filesUpdate or remove OPENCODE_API_KEY / OPENCODE_ZEN_API_KEY, then unset or open a new shell
Hardcoded key in opencode.json or un-restarted serviceCheck ~/.config/opencode/opencode.json, project .opencode.json, and running IDE extensionsRemove 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.

Step 1: Create a new API key in OpenCode Console

Start by issuing a fresh credential in the Console.

  1. Open https://opencode.ai/console and sign in to your account.
  2. Open the Account menu in the top right and navigate to Personal API keys (workspace admins using service keys should check workspace Settings).
  3. Click Add API key, pick the target workspace, and give the key a clear name (for example, machine name and month).
  4. Set the expiration window: choose Never or a longer TTL on a personal dev machine, or match your team's rotation schedule.
  5. Copy the generated key right away. The Console displays the full value only once.

Delete the expired key from the list while you are there so it does not cause confusion during future troubleshooting.

Step 2: Clear cached auth and log in with the new key

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 login

When 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.json

Make sure no stale token remains for that provider before testing a new request.

Step 3: Check for shell environment variable overrides

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 opencode

If an old key shows up, clean it up in three places:

  • Current shell session: run unset OPENCODE_API_KEY OPENCODE_ZEN_API_KEY
  • Shell startup files: check ~/.zshrc, ~/.bashrc, and ~/.profile, update or remove any export OPENCODE_API_KEY=... line, and reload your shell
  • Project and CI secrets: check .env, .env.local, and your CI secret store so nothing re-injects the expired key

Step 4: Inspect opencode.json and restart active sessions

Open 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.

Add CodingPass in opencode.json as a backup provider

If 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:

~/.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.

FAQ

Why does signing in again not renew an expired OpenCode API key?

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.

Where does OpenCode store API keys, and which one takes precedence?

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.

Can I keep OpenCode Zen and CodingPass configured side by side?

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.

Boarding

Add a backup provider, skip the downtime.

Keep using OpenCode as usual. Add CodingPass to opencode.json from /mo and switch providers anytime.

  • Request ID on every response
  • Full refund if you've used 5% or less
  • No surprise charges
Choose GoOpenCode guide

$10/mo until you cancel.