Repository navigation
# Bug: ${env:VAR} substitution in provider apiKey and baseURL override from models catalog #27853
Description
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 |
|---|---|---|---|
@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 viaopencode 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:
opencode providers login - 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
baseURLdiffers from models catalog
Actual: Incorrect URL silently overrideshttps://opencode.ai/zen/go/v1,
causingError: Invalid API keywith no diagnostic message
Bug 3: opencode run returns tokens=0
- Remove all
opencode-goconfig fromopencode.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.deltareceived ✅@ai-sdk/openai-compatible→message.part.deltaempty ❌
Screenshot and/or share link
No response
Operating System
Windows 11
Terminal
Windows Terminal PowerShell 7+
Activity
github-actions commentedon May 16, 2026
This issue might be a duplicate of existing issues. Please check:
{env:...}substitution not working forapiKeyin custom provider options —{file:...}works #19946:{env:...}substitution not working forapiKeyin custom provider options — same bug as your Bug 1, where environment variable substitution in providerapiKeydoes not resolve correctly.Ish-oota commentedon May 17, 2026
Thanks for the detailed report and cross-references — very helpful for triaging.
Bug 1 (
${env:VAR}substitution):This appears to be a duplicate of #19946. The syntax differs slightly, but the root cause is the same: env-var substitution fails to resolve inside custom provider
options. Happy to close this in favour of #19946.Bug 2 (
baseURLsilently overriding catalog URL):I couldn't find an existing duplicate for this. Unlike #5674 where options aren't applied at all, here the user-defined
baseURLis applied but silently overrides the correct catalog URL, producing a misleadingInvalid API keyerror. I think this is worth tracking as a separate issue.Bug 3 (
opencode runreturningtokens=0):This looks like a match for #5210. The debug logs show
message.part.deltais empty and the stream ends withfinish: "other"rather than"stop"— consistent withtext-deltaevents being dropped inprocessor.tswhentext-startis missing. The fact that TUI works correctly on the same machine confirms this is isolated to theopencode runheadless code path.I'd suggest keeping this issue open to track Bug 2 and Bug 3 (linked to #5210), while closing Bug 1 as a duplicate of #19946. Happy to provide additional logs if needed.
github-actions commentedon Jul 17, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.