---
title: "OpenCode “This API key has expired”: Console key reset guide"
description: "Fix “This API key has expired. Create a new API key in OpenCode Console” in minutes: generate a new Console key, clear auth.json, check OPENCODE_API_KEY overrides, and optionally add a backup provider."
url: https://codingpass.ai/blog/opencode-api-key-has-expired-fix
language: en
updated: 2026-11-30
---
# 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.

[CodingPass team](https://codingpass.ai/about) Published Nov 30, 2026 Updated Nov 30, 2026 5 min read

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

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

## 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 logout
opencode 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](https://codingpass.ai/models) and [pricing](https://codingpass.ai/pricing) for tier details.

Following the [OpenCode setup guide](https://codingpass.ai/tools/opencode), 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](https://codingpass.ai/tools/opencode).

Written by CodingPass team

We run CodingPass and test each guide against the latest stable release of the tool before we publish it. Spotted something out of date? Write to [support@codingpass.ai](mailto:support@codingpass.ai).

## Related reading.

Guide

### [OpenCode setup guide](https://codingpass.ai/tools/opencode)

Provider config in opencode.json, model IDs per plan, and how to check common errors.

Models

### [All models](https://codingpass.ai/models)

Model IDs, required tiers, and monthly allowances.

Pricing

### [Plans and pricing](https://codingpass.ai/pricing)

Monthly allowances, caps, and pricing across Go, Plus, and Pro.
