Description
Bug Summary
Two related bugs prevent opencode run from working with OpenCode GO models.
Bug 1: ${env:VAR} substitution fails in provider apiKey
Using ${env:OPENCODE_API_KEY} in opencode.json provider options does not resolve
to the environment variable value. The raw string is sent as the API key, causing
authentication failures.
Bug 2: baseURL in opencode.json silently overrides the models catalog
If a user defines baseURL for opencode-go in opencode.json, it silently overrides
the correct URL from the models catalog with no warning.
The correct endpoint from the models catalog (https://opencode.ai/zen/go/models-api.json) is:
"opencode-go": {
"id": "opencode-go",
"env": ["OPENCODE_API_KEY"],
"npm": "@ai-sdk/openai-compatible",
"api": "https://opencode.ai/zen/go/v1"
}
A common mistake is using https://api.opencode.ai/v1 (OpenAI-compatible style),
which is incorrect and causes auth failures.
Bug 3: opencode run returns tokens=0 with OpenCode GO models
Even after resolving Bugs 1 and 2, opencode run produces no output with OpenCode GO models.
Debug log comparison:
| Provider |
SDK Package |
message.part.delta |
Result |
| Google |
@ai-sdk/google |
✅ Received |
Works |
| OpenCode GO |
@ai-sdk/openai-compatible |
❌ Empty |
Fails |
Token result from opencode run:
{
"tokens": { "input": 0, "output": 0, "reasoning": 0 },
"finish": "other"
}
Key observation: TUI mode works correctly with the same model (mimo-v2.5-pro).
This indicates opencode run uses a different code path than TUI for OpenCode GO
provider routing, and that code path fails to parse the streaming response via
@ai-sdk/openai-compatible.
Workaround (confirmed working)
Remove the opencode-go provider block from opencode.json entirely:
{
"provider": {
// Do NOT define opencode-go here
}
}
The CLI will automatically use:
- Authentication from
auth.json (registered via opencode providers login)
- URL from the models catalog (
https://opencode.ai/zen/go/v1)
This workaround restores TUI functionality but does not fix opencode run.
Plugins
No response
OpenCode version
1.15.1
Steps to reproduce
Bug 1: ${env:VAR} substitution failure
- Authenticate with OpenCode GO:
- Add the following to
opencode.json:
{
"provider": {
"opencode-go": {
"options": {
"apiKey": "${env:OPENCODE_API_KEY}"
}
}
}
}
- Set the environment variable:
$env:OPENCODE_API_KEY = "sk-..."
- Run:
opencode run -m opencode-go/mimo-v2.5-pro "test"
- Expected: Model responds normally
Actual: Error: Invalid API key — ${env:OPENCODE_API_KEY} is sent as a literal string
Bug 2: baseURL silently overrides models catalog
- Add the following to
opencode.json:
{
"provider": {
"opencode-go": {
"options": {
"baseURL": "https://api.opencode.ai/v1"
}
}
}
}
- Run:
opencode run -m opencode-go/mimo-v2.5-pro "test"
- Expected: Warning that
baseURL differs from models catalog
Actual: Incorrect URL silently overrides https://opencode.ai/zen/go/v1,
causing Error: Invalid API key with no diagnostic message
Bug 3: opencode run returns tokens=0
- Remove all
opencode-go config from opencode.json (use workaround above)
- Confirm TUI mode works:
opencode # interactive TUI → mimo-v2.5-pro responds ✅
- Run headless:
opencode run -m opencode-go/mimo-v2.5-pro "Say OK"
- Expected: Model responds with text, non-zero token count
Actual:
{ "tokens": { "input": 0, "output": 0, "reasoning": 0 }, "finish": "other" }
- Enable debug logging and compare providers:
@ai-sdk/google → message.part.delta received ✅
@ai-sdk/openai-compatible → message.part.delta empty ❌
Screenshot and/or share link
No response
Operating System
Windows 11
Terminal
Windows Terminal PowerShell 7+
Description
Bug Summary
Two related bugs prevent
opencode runfrom working with OpenCode GO models.Bug 1:
${env:VAR}substitution fails in providerapiKeyUsing
${env:OPENCODE_API_KEY}inopencode.jsonprovider options does not resolveto the environment variable value. The raw string is sent as the API key, causing
authentication failures.
Bug 2:
baseURLinopencode.jsonsilently overrides the models catalogIf a user defines
baseURLforopencode-goinopencode.json, it silently overridesthe correct URL from the models catalog with no warning.
The correct endpoint from the models catalog (
https://opencode.ai/zen/go/models-api.json) is:A common mistake is using
https://api.opencode.ai/v1(OpenAI-compatible style),which is incorrect and causes auth failures.
Bug 3:
opencode runreturnstokens=0with OpenCode GO modelsEven after resolving Bugs 1 and 2,
opencode runproduces no output with OpenCode GO models.Debug log comparison:
message.part.delta@ai-sdk/google@ai-sdk/openai-compatibleToken result from
opencode run:{ "tokens": { "input": 0, "output": 0, "reasoning": 0 }, "finish": "other" }Key observation: TUI mode works correctly with the same model (
mimo-v2.5-pro).This indicates
opencode runuses a different code path than TUI for OpenCode GOprovider routing, and that code path fails to parse the streaming response via
@ai-sdk/openai-compatible.Workaround (confirmed working)
Remove the
opencode-goprovider block fromopencode.jsonentirely:{ "provider": { // Do NOT define opencode-go here } }The CLI will automatically use:
auth.json(registered viaopencode providers login)https://opencode.ai/zen/go/v1)This workaround restores TUI functionality but does not fix
opencode run.Plugins
No response
OpenCode version
1.15.1
Steps to reproduce
Bug 1:
${env:VAR}substitution failureopencode.json:{ "provider": { "opencode-go": { "options": { "apiKey": "${env:OPENCODE_API_KEY}" } } } }Actual:
Error: Invalid API key—${env:OPENCODE_API_KEY}is sent as a literal stringBug 2:
baseURLsilently overrides models catalogopencode.json:{ "provider": { "opencode-go": { "options": { "baseURL": "https://api.opencode.ai/v1" } } } }baseURLdiffers from models catalogActual: Incorrect URL silently overrides
https://opencode.ai/zen/go/v1,causing
Error: Invalid API keywith no diagnostic messageBug 3:
opencode runreturnstokens=0opencode-goconfig fromopencode.json(use workaround above)Actual:
{ "tokens": { "input": 0, "output": 0, "reasoning": 0 }, "finish": "other" }@ai-sdk/google→message.part.deltareceived ✅@ai-sdk/openai-compatible→message.part.deltaempty ❌Screenshot and/or share link
No response
Operating System
Windows 11
Terminal
Windows Terminal PowerShell 7+