Status: implemented and verified (packed package on OpenCode 1.4.0, 1.19.0, 2.0.28); reviewed by Codex. Target release: 1.3.0 (no breaking change for V1).
One npm package that works on OpenCode 1.x (≥ 1.4.0) and OpenCode 2.x:
- On V1, the plugin behaves exactly as it does today.
- On V2, it registers the
coreinfralogin (API key orCOREINFRA_API_KEY) and thecoreinfraprovider with every model the Hub lists. Each model gets its correct protocol and endpoint and keeps its thinking/effort variants. - After login, logout or an account switch, the model list refreshes without restarting OpenCode.
| Area | V1 (today) | V2 |
|---|---|---|
| Entry | default { id, server() → hooks } |
default { id, setup(ctx) }. V1 plugins don't load. |
| Models | config hook edits config.provider.coreinfra.models |
ctx.provider.transform(editor => editor.add(...)). Must be sync and replayable. |
| Login | auth hook + loader → { apiKey } |
ctx.integration.transform registers key and env methods. Core adds apiKey itself. |
| Key storage | auth.json |
Database. auth.json is imported once, so new logins never reach it. |
| Model shape | provider{npm,api}, tool_call, modalities, cost{cache_read}, interleaved |
package, settings.baseURL, capabilities, cost[{cache{read,write}}], compatibility, variants[], time, status, enabled |
| Logging | client.app.log |
none; use console |
| CLI | opencode plugin -g, opencode providers login |
opencode plugin add, opencode auth login coreinfra |
Compatibility is checked in the source: the V2 loader ignores the extra server key (core/src/plugin/module.ts:78). The V1 1.4.0 loader ignores the extra setup key (readV1Plugin).
- Entry:
export default { id, server: v1, setup: v2 }. Import V2 types only (import type), because@opencode/plugindoesn't exist at runtime under V1. src/models.ts(shared): Hub fetch takes an explicitapiKeyand has noauth.jsonfallback. Also holdsPROVIDERS(protocol → base URL, headers), lookups and helpers.src/v1.ts: today'sconfig/authhooks moved here unchanged, including theauth.json/env key lookup.src/v2.tssetup(ctx):- Integration
coreinfra("CoreInfra AI Hub"), with methods{type:"key"}and{type:"env", names:["COREINFRA_API_KEY"]}. Always registered, even if discovery fails. - Key comes from
integration.connection.active("coreinfra")→resolve()only. V2 ranks a saved key above env. refresh()fetches the Hub list and stores a snapshot bound to the connection. Refreshes are serialized, results for a stale connection are dropped, and the last good data is kept only for the same connection.provider.transform(sync) doeseditor.add({ info: { id:"coreinfra", integrationID:"coreinfra", activation:"auto", package:"" }, models, sourceConnection }).event.subscribereacts tocredential.switchedforcoreinfraby callingrefresh()and thenctx.provider.reload(). Cleanup aborts it.
- Integration
- V2 model mapping: the Hub list decides which models exist. For each Hub model, look up the built-in upstream record (
openai/anthropic/deepseek/…) inside each transform replay, never cached insetup.- Package:
@opencode/ai/providers/{openai|anthropic|openai-compatible}, explicit native packages, notaisdk:. - Copy only allowlisted fields from upstream: capabilities, limit, cost, family, time, status. Replace ids, providerID, package,
settings.baseURL, headers andenabled. - Variants: deep-clone only the reviewed thinking/effort fields, and only when
upstream.package ?? record.provider.packageequals our package. Otherwise usevariants: []. This is an accepted limitation for DeepSeek, ZAI and Moonshot. compatibility.reasoningFieldcomes from the upstream model on chat routes only. No syntheticreasoning_contentfor Anthropic.- If the upstream record is missing, fall back to the Hub name plus defaults and log a warning. V2 no longer fetches models.dev itself.
- Package:
- Packaging: devDependencies
@opencode-ai/plugin,@opencode-ai/sdk,@opencode/plugin. All host peers marked optional. - Docs: README install and login steps for both majors; note that a saved key takes priority over env on V2.
- Unit: V1 behaviour unchanged. V2 mapper covers inherited package, matching and mismatched package, missing record and variant field isolation.
- V2 lifecycle with a fake
ctx:- discovery fails at first, then login succeeds
- env only, and env + saved key together
- switch account and logout
- a stale refresh finishes late
- transform replay after a catalog reload
- cleanup
auth.jsonis never read
- Manual release gate: install the packed package (no devDependencies) on OpenCode 1.4.0, 1.19.0 and 2.0.28. Log in, list models, then do a reasoning + tool-call round trip on the openai, anthropic and deepseek routes.
- Thinking variants for models whose upstream uses a different package (DeepSeek/ZAI/Moonshot).
- A key changed without a switch event doesn't refresh until restart.
- Hub prices: OpenCode still supports USD only.
- Hub models that models.dev marks deprecated are missing from OpenCode 2's built-in catalog, so on V2 they get default metadata (and a warning).
- 2.x support is verified on 2.0.28. Older 2.x releases are unverified.