Skip to content

# Bug: ${env:VAR} substitution in provider apiKey and baseURL override from models catalog #27853

@Ish-oota

Description

@Ish-oota

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

  1. Authenticate with OpenCode GO:
    opencode providers login
    
  2. Add the following to opencode.json:
    {
      "provider": {
        "opencode-go": {
          "options": {
            "apiKey": "${env:OPENCODE_API_KEY}"
          }
        }
      }
    }
  3. Set the environment variable:
    $env:OPENCODE_API_KEY = "sk-..."
  4. Run:
    opencode run -m opencode-go/mimo-v2.5-pro "test"
    
  5. 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

  1. Add the following to opencode.json:
    {
      "provider": {
        "opencode-go": {
          "options": {
            "baseURL": "https://api.opencode.ai/v1"
          }
        }
      }
    }
  2. Run:
    opencode run -m opencode-go/mimo-v2.5-pro "test"
    
  3. 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

  1. Remove all opencode-go config from opencode.json (use workaround above)
  2. Confirm TUI mode works:
    opencode   # interactive TUI → mimo-v2.5-pro responds ✅
    
  3. Run headless:
    opencode run -m opencode-go/mimo-v2.5-pro "Say OK"
    
  4. Expected: Model responds with text, non-zero token count
    Actual:
    { "tokens": { "input": 0, "output": 0, "reasoning": 0 }, "finish": "other" }
  5. Enable debug logging and compare providers:
    • @ai-sdk/googlemessage.part.delta received ✅
    • @ai-sdk/openai-compatiblemessage.part.delta empty ❌

Screenshot and/or share link

No response

Operating System

Windows 11

Terminal

Windows Terminal PowerShell 7+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions