OpenCode Zen(现 Console)旧 API Key 批量过期核对:401 api_key_expired 成因、时间线与三步修复(2026-10)
一、现象:旧 key 返回 401 api_key_expired
2026-10-18 本机实测:一把旧格式 API key 对 GET https://opencode.ai/inference/v1/models 返回 HTTP 401,原文:
{"error":{"type":"authentication_error","code":"api_key_expired","message":"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."}}

同批对照:占位无效 key → 401 / server_error / Invalid credential;当前格式 key(oc_sk_ 开头)→ 200。api_key_expired 是独立的“过期”状态,区别于“凭证无效”。
官方文案三点:① 过期是硬状态;② 修复 = 去 Console 新建 key 并替换;③ 重新登录不续期(“Signing in again will not renew this key”)。
二、报错对照:别把“过期”当“限流”
| 状态码 | 错误码 / 文案 | 含义 | 处置 |
|---|---|---|---|
| 401 | api_key_expired |
key 已过期 | 换 key(等待 / 换网络无效;重登按官方口径不续期) |
| 401 | server_error / Invalid credential |
凭证无效或不存在 | 检查 key 是否写对 |
| 429 | Rate limit exceeded | 限流(以按模型独立计数为主) | 换模型或稍后重试 |
三、接口变更:/zen/v1 → /inference/...
| 用途 | 旧 | 新 |
|---|---|---|
| OpenAI Chat Completions | /zen/v1/... |
/inference/openai/v1/chat/completions |
| OpenAI Responses | — | /inference/openai/v1/responses |
| Anthropic Messages | — | /inference/anthropic/v1/messages |
| Gemini | — | /inference/google/v1beta/models/<model>:generateContent |
| 模型目录 | /zen/v1/models |
/inference/v1/models |
| 认证 | — | Authorization: Bearer <token>(付费必需) |
旧端点 /zen/v1 今日仍返回 200,输出与新端点一致(别名 / 镜像),未见官方下线时间表;官方文档 /docs/zen 已 302 到 Console Models 文档,全面切到新结构。
四、三步修复
1. 新建 key
-
打开 opencode 登录页(支持 Google / GitHub / email): https://opencode.ai/auth
-
进 Settings → Service accounts,点对应账户(或先 Add Service Account 新建),进去点 Add API Key。

-
填 Key name、选择 Permissions,Expiry date 个人账户可设为 never(永不过期),点 Create。
-
新 key 以
oc_sk_开头(示例:oc_sk_xxxxxxxxxx)。
2. 换 key(顺手把接口地址也换了)
两条路,挑一条:
- 走
/connect(省事):在 opencode 里跑/connect,选 OpenCode 的 provider,把新 key 粘进去(官方文档推荐)。 - 手改配置:打开
opencode.json/opencode.jsonc,改这两处:
{
"provider": {
"opencode": {
"npm": "@ai-sdk/openai-compatible",
"baseURL": "https://opencode.ai/inference/v1", // 接口变更:旧 /zen/v1 → 新 /inference/v1
"apiKey": "oc_sk_xxxxxxxxxx" // 换成第 1 步的新 key
}
}
}
baseURL 那行不是顺手加的——opencode 的推理端点已从旧结构 /zen/v1 迁到 /inference/...:模型目录是 /inference/v1/models,chat 请求走 /inference/openai/v1/chat/completions。旧地址目前仍是可用别名,但官方文档已全面切到新结构;配置里还写着 /zen/v1 的,趁这次一并改掉。
改完重启 opencode(或重连 provider),让新 key 和地址生效。
3. 验证
回到 opencode,切到用这把 key 的模型,发一句「say hello」——能正常回话即生效;还报 401 api_key_expired,就是 key 没换对。
五、背景:一场无公告的静默迁移
| 时间 | 事件 |
|---|---|
| 10-01 | 端点仍在 /zen/v1(知识库基线) |
| 10-13 前后 | 端点开始切 /inference/...(配置层面漂移;时点推断,非官方公告) |
| 10-13 ~ 17 | /docs/zen 静默 302 → Console Models 文档;品牌 Zen→Console |
| 10-17 | 官方 PR「expired-key response change」(服务端做过期相关改动) |
| 10-18 | 本机旧 key 实测 401 api_key_expired |
官方 changelog 无 Zen 迁移、无 key 过期公告 → 迁移与到期均为静默执行。

关注微信公众号
扫码关注,第一时间获取软件更新动态与选型建议。