Troubleshooting · opencode
opencode AI_APICallError — Causes and Fixes
opencode surfaces provider failures as AI_APICallError from the Vercel AI SDK. How to read the wrapped status code and fix the baseURL, key or model underneath.
What you see
AI_APICallErrorWhy it happens
- AI_APICallError is a wrapper, not a diagnosis: the AI SDK throws it for any non-success HTTP response, and the real cause is the wrapped status and body.
- 401 inside it — the provider's apiKey option is wrong, or the {env:...} placeholder names a variable that is not set.
- 404 inside it — the baseURL is wrong for the provider's protocol: missing /v1, doubled /v1/v1, or a model id the endpoint does not serve.
- 429 or 529 inside it — throughput or upstream capacity; nothing in your config is wrong.
How to fix it
- Read the statusCode and responseBody fields of the error first — they carry the provider's actual answer.
- Verify the provider block: baseURL exact, apiKey resolving from an environment variable that exists in the shell that launched opencode.
- Restart opencode after any opencode.json change — the config is read at startup.
Provider block for this gateway
{
"provider": {
"apitoken": {
"npm": "@ai-sdk/openai-compatible",
"name": "apiToken.sale",
"options": {
"baseURL": "https://openai.api.apitoken.sale/v1",
"apiKey": "{env:APITOKEN_API_KEY}"
}
}
}
}Related searches
opencode AI_APICallErroropencode api call error
FAQ
Is AI_APICallError an opencode bug?+
No — it is the AI SDK reporting that the provider returned a non-success response. The wrapped status code identifies the real problem.
Where does opencode read my API key from?+
From the provider's options.apiKey. With an {env:NAME} placeholder, the variable must exist in the environment opencode was launched from.
I fixed opencode.json and nothing changed — why?+
opencode reads its config at startup. Restart it after every change.