OpenCode
OpenCode "API key has expired": re-login will not renew
If OpenCode says "This API key has expired", that Console key cannot be renewed. Create a new key in OpenCode Console, then save it in the client with /connect or opencode auth login. Signing in again does not renew the old key. A 401 that does not say the key expired is a different problem. The last check below applies only when the key is an AI Code With key.
Start with these checks
Replace an expired OpenCode Console key first. A 401 is not always an expired key.
- "This API key has expired" cannot be renewed. Signing in again does not replace the old key.
- Create a new key in Account › Personal API keys, or under Settings › Service accounts. Paste it with /connect (OpenCode Go) or opencode auth login. Do not edit the credential database.
- Copy a fresh API Key from AI Code With
401Unauthorized01
Expired Console key, then a separate 401
Case 1 is the expired Console key. An expired key cannot be renewed, so create a new one. Add a personal key from Account › Personal API keys, or a service-account key from Settings › Service accounts, and copy it when it is shown (https://opencode.ai/docs/console/api). In OpenCode, replace the saved key with /connect (select OpenCode Go and paste the key) or with opencode auth login (https://opencode.ai/docs/providers/ and https://opencode.ai/docs/cli/providers). Those docs store the credential as a provider account and say not to edit the credential database. Signing in again does not renew the old key. If a new key is still rejected, run opencode auth list. A saved account overrides an environment variable; unset the variable to remove an environment credential. Revoked keys also return HTTP 401, so a 401 that does not say the key has expired is not this case. Case 2: the AI Code With proxy rejected the key. With Accept-Language: en, a missing key is code missing_api_key, "Please provide a valid API key in the request." A key that was sent but does not match is code invalid_api_key, "The API key is invalid. Check that it was entered correctly." Create a new key in the AI Code With console and paste it into options.apiKey. If you see "Not Found: 不支持的请求路径", the address is missing /v1. Save, reopen OpenCode, run /models and send a test message. A 401 or Unauthorized response means the request arrived at the service, so check the API Key and Provider before changing the model. Switching to AI Code With is optional and is not how an expired Console key is repaired. The setup guide is at /integrations/opencode.
02
OpenCode invalid credential: check the credential and Provider
An invalid credential (401 / Unauthorized) means the request reached the service but the key was rejected. Common causes: the API Key is incomplete or expired, apiKey is outside the provider options, or the Provider and Base URL do not belong to the same setup. Fix: copy a fresh API Key from AI Code With into options.apiKey, confirm apiKey is inside the provider options, and make sure the Provider ID exactly matches the value generated on this page.
- 1Copy a fresh API Key from AI Code With
- 2Replace the placeholder with the complete key
03
Verify again
Save, reopen OpenCode, run /models, and send a short message. No 401 means the credential path is working.
- 1Replace the placeholder with the complete key
- 2Confirm the Provider ID matches the generated config
If it is still not fixed
Sources
Reconfigure
Return to the integration center and continue the setup steps.
Return to the related setup stepRelated problems
Model missing from /models or Model Not Found · Model is listed but the request does not complete · Wrong Base URL, 404, or connection failure · opencode command not found · Rate limit or 429 · Usage is recorded but OpenCode shows no reply · reasoning part/text part not found or summaryParts parsing error · Invalid opencode.json · 403 Forbidden · BunInstallFailedError or models.dev download failure