Skip to content

provider: "Cannot find package '@opencode/ai'" for anthropic-compatible / openai-compatible responses packages #53842

Closed

Description

@zx2021210538

Description

Custom providers/models that reference a documented @opencode/ai/providers/* package which is not part of the bundled package registry fail at model initialization:

Cannot initialize <provider>/<model>: Cannot find package '@opencode/ai' imported from B:\~BUN\root\chunk-x66j8jdp.js

Affected (100% reproducible on v2.0.24, Windows): @opencode/ai/providers/anthropic-compatible, @opencode/ai/providers/openai-compatible/responses, @opencode/ai/providers/openai-compatible-responses.
Not affected: @opencode/ai/providers/anthropic, @opencode/ai/providers/openai, @opencode/ai/providers/openai-compatible.

The modules exist in the npm package @opencode/[email protected] and their code is present in the compiled binary, so this looks like a resolution gap in the bundled registry used by Provider.loadPackage, not a missing package.

Plugins

none

OpenCode version

2.0.24

Steps to reproduce

  1. In opencode.json, configure a custom provider (a model-level "package" override reproduces identically):
{
  "providers": {
    "acme": {
      "package": "@opencode/ai/providers/anthropic-compatible",
      "settings": {
        "baseURL": "https://gateway.example.com/anthropic/v1",
        "apiKey": "{env:ACME_KEY}"
      },
      "models": {
        "anthropic/claude-sonnet-4.5": { "name": "Claude" }
      }
    }
  }
}
  1. Run opencode reload.
  2. Run opencode run --model "acme/anthropic/claude-sonnet-4.5" "hello".

Screenshot and/or share link

N/A (CLI reproduction)

Operating System

Windows 10 (10.0.19045), x86_64

Terminal

Git Bash (MINGW64), TERM=xterm-256color

Additional context

From the compiled bundle, Provider.loadPackage first checks a static package-to-chunk map, then falls back:

let s = ED.get(i);
if (s) return importPackage(i, i, s);
let a = (() => {
  if (i.startsWith("file://") || i.startsWith("@opencode/ai/")) return i; // bare specifier
  try { return import.meta.resolve(i) } catch { return; }
})();
if (a) return importPackage(i, a); // import("@opencode/ai/...") fails in the compiled binary
// npm-install fallback below is unreachable for @opencode/ai/* because of the early return
  • The static map has 52 entries and includes anthropic, openai, openai/chat, openai/responses, openai-compatible, but not anthropic-compatible or openai-compatible/responses.
  • Other code in the same bundle explicitly references @opencode/ai/providers/anthropic-compatible (native-route check and credential mapping), so the registry appears to be missing entries.
  • Placing @opencode/ai in the working directory or next to the executable does not help. Importing the module through a file:// URL loads it, but its own bare dependencies then fail, so only the bundled path works.

Possible fixes: add the missing subpaths to the bundled registry, or remove the @opencode/ai/ early-return so the npm install fallback can run. In dev/source runs the same config resolves normally, which is likely why this only shows up in release builds.

Activity

  1. opencode-agent commented on Oct 8, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report! I could reproduce this on 2.0.24, and on Linux too, so it isn't specific to Windows.

    With a custom provider whose package is @opencode/ai/providers/anthropic-compatible, @opencode/ai/providers/openai-compatible/responses or @opencode/ai/providers/openai-compatible-responses, opencode run --model acme/m1 hello fails with Cannot initialize acme/m1: Cannot find package '@opencode/ai' imported from /$bunfs/root/chunk-….js. With @opencode/ai/providers/openai-compatible or @opencode/ai/providers/anthropic, the same config loads fine.

    It still happens with a binary built from the latest v2 commit (3b684acd8d). Your diagnosis matches the code: these three packages are missing from the built-in package list that release builds use.

    Related:

  2. rekram1-node commented on Oct 8, 2026

    @rekram1-node
    Collaborator

    dumb bug... apologies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions