Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[Command Code](https://commandcode.ai) API provider for [opencode](https://opencode.ai). Use Claude, GPT, Gemini, DeepSeek, Qwen, Kimi, GLM, MiniMax, Step, and other models through a single API key.

This plugin is for Command Code accounts with Provider API access. GOAT is the live-tested baseline; other API-enabled plans can use models their account is entitled to. The $1 Go plan has no Provider API access. The catalog follows the provider-wide model list, so a model appearing in OpenCode does not imply that every account can call it. See [GOAT plan details](https://commandcode.ai/docs/plans/goat) and [Provider API docs](https://commandcode.ai/docs/provider).
This plugin is for Command Code accounts with Provider API access. GOAT is the live-tested baseline; other accounts can use models they're entitled to. The $1 Go plan's monthly allowance does not cover Provider API requests, but Go users can call the API with eligible free or purchased credits. The catalog follows the provider-wide model list, so a model appearing in OpenCode does not imply that every account can call it. See the [Go plan's API support](https://commandcode.ai/docs/plans/go#api-support) and [Provider API docs](https://commandcode.ai/docs/provider).

This package keeps a **bundled** model catalog current via CI. You do **not** need a local `command-code` CLI. Catalog patches publish automatically after a green PR merges to `main`.

Expand All @@ -22,10 +22,10 @@ This package is based on **[FanFan4204/opencode-commandcode-provider](https://gi
- V1 and V2 use their native plugin and provider surfaces. V1 `server()` fills `provider.commandcode` and registers API-key auth; V2 `setup()` registers provider/model transforms and a key/env integration for `/connect` and `opencode auth login`.
- Validation at the boundaries via `src/schemas.ts` (zod): bundled `models.json` / `manifest.json` reads, provider availability payloads, and the plugin config file.
- CLI cost extraction can fail without dropping models; official docs fill missing costs, remaining paid gaps use [models.dev](https://models.dev) as a reference price at sync time. Command Code free SKUs stay `$0`.
- Vision vs text-only comes from the Command Code CLI catalog (`inputModalities` on every SKU). [models.dev](https://models.dev) only adds extra inputs (video/audio/pdf) when it matches.
- The Provider API accepts text and images only. The bundled catalog advertises image input only when the CLI catalog or a matching [models.dev](https://models.dev) entry lists it. It does not advertise audio, video, PDF, or other file inputs.
- Reasoning effort **variants** on models that declare `reasoningEfforts`.
- Release date, family, input limits, model status, vendor context limits, and matched context-price tiers flow through the bundled catalog. V2 gets native release, family, input, status, and tier fields; V1 keeps its supported fields and base prices, with `context_over_200k` where representable.
- The provider's `supported_endpoints` metadata chooses each model's API route. Messages is preferred when advertised; otherwise Chat Completions is preferred, and Responses is used only when it is the sole advertised route. This avoids the malformed Responses function-call start event observed on DeepSeek V4.1 Flash `#max` in OpenCode V2.0.18: `response.output_item.added` contained a `function_call` item without its required `arguments` string. That exact tool-call flow now passes through Chat Completions on V1 and V2. Responses mappings remain available for response-only models, but the current catalog has none. Claude Sonnet 4.6 returned `MODEL_NOT_IN_PLAN` with the message “available in Pro and above plans or extra on-demand usage”; entitled Claude access has not been live-verified. If a model fails on an account entitled to use it, please [open an issue](https://github.com/BrainerVirus/opencode-commandcode/issues) with the model ID and OpenCode version, or submit a PR with a reproducible fix.
- Routing uses each model's `supported_endpoints`. Claude uses Anthropic Messages when advertised. Other models use Chat Completions whenever advertised, even if they also advertise Messages or Responses. Outside the Claude preference, Chat Completions is preferred whenever advertised; if only Messages and/or Responses are advertised, Messages is preferred when available, otherwise Responses. Without endpoint metadata, Claude defaults to Messages and other models default to Chat Completions. This keeps DeepSeek V4.1 Flash `#max` on the previously verified Chat Completions tool-call path on V1 and V2. Claude Sonnet 4.6 returned `MODEL_NOT_IN_PLAN` on the tested GOAT account; entitled Claude access has not been live-verified. If an entitled model fails, please [open an issue](https://github.com/BrainerVirus/opencode-commandcode/issues) with the model ID and OpenCode version.
- Quiet OpenCode startup (diagnostics go to `startup.json`, not stdout).
- Free models show `(Free)` after their display name on V1 and V2 when all catalog prices are zero. Model IDs and routing stay unchanged; this is a name suffix, not a native desktop badge. Names that already end in `Free` or `(Free)` keep their existing label.
- Zero data retention on request: `CMD_ZDR=1` or `zdr: true` in the plugin config adds `x-cmd-zdr: 1` to every Command Code Provider API (`/provider/v1/*`) request on both OpenCode generations.
Expand All @@ -35,7 +35,7 @@ This package is based on **[FanFan4204/opencode-commandcode-provider](https://gi
For published plugin versions, the six-hour CI schedule extracts the latest `command-code` npm bundle and refreshes callable models plus endpoint metadata, even when the CLI version is unchanged. It opens a catalog PR only when generated artifacts change; at startup the plugin loads those artifacts and registers them with OpenCode — never the other way around.

- **Extract + filter** — model entries (ids, names, reasoning, `inputModalities`, limits) are evaluated out of the minified CLI bundle (`src/catalog.ts`), then intersected with the callable IDs reported by the provider API.
- **Metadata + costs merge** — vendor context length tightens only a fallback context limit, while `supported_endpoints` selects Messages, Chat Completions, or Responses per model in that preference order; missing endpoint metadata preserves the last known route data. models.dev contributes release date, family, input limit, status, modalities, and cost tiers when present. Tier rows are accepted only when their base prices match this Command Code catalog. Base costs use CLI bundle → official Command Code docs → free SKUs (`$0`) → [models.dev](https://models.dev) reference prices → unmatched placeholder. Anything still unmatched marks the catalog `degraded`. This runs at sync time only; runtime never fetches metadata or prices.
- **Metadata + costs merge** — vendor context length tightens only a fallback context limit, and missing endpoint metadata preserves the last known route data. models.dev contributes release date, family, input limit, status, vision metadata, and cost tiers when present. Tier rows are accepted only when their base prices match this Command Code catalog. Base costs use CLI bundle → official Command Code docs → free SKUs (`$0`) → [models.dev](https://models.dev) reference prices → unmatched placeholder. Anything still unmatched marks the catalog `degraded`. This runs at sync time only; runtime never fetches metadata or prices.
- **Artifacts** — `models.json` (the catalog), `_version.txt` (upstream version), `manifest.json` (counts, per-source cost stats, `healthy`/`degraded`/`broken` status).
- **Version-specific registration** — V1 uses the `plugin` config key, direct AI SDK packages, the `server()` provider map, and its auth callback. V2 uses `plugins`, OpenCode's native provider runtimes, provider/model transforms, and a `commandcode` integration with key and `COMMANDCODE_API_KEY` environment methods. Both retain the Command Code wire model ID. V2 exposes tiered context pricing; V1 emits its supported `context_over_200k` field and keeps flat pricing for other tiers.
- **Degraded/cache fallbacks** — a `degraded`/`broken` manifest sets the degraded flag with a reason; an unreadable bundled `models.json` falls back to the last-good cache; auth/connect still registers even with an empty catalog.
Expand Down Expand Up @@ -107,7 +107,8 @@ Header names are matched case-insensitively, and the plugin collapses any spelli
`x-cmd-zdr` key, so a request never carries two ZDR headers. Custom npm transports keep owning their options.

Behavior to expect from the API: when set, requests route only through ZDR-capable upstreams, and a model without one
**fails with `422 cmd_zdr_no_providers`** instead of falling back to a non-ZDR provider. ZDR can change which upstream
**fails with `422 cmd_zdr_no_providers`** instead of falling back to a non-ZDR provider. Free models are not ZDR-routed;
choose a model with ZDR coverage rather than relying on a `(Free)` SKU for ZDR. ZDR can change which upstream
serves a request, so it may cost more. The header is sent on the Chat Completions, Messages, and Responses routes alike;
live verification so far covers Chat Completions only.

Expand Down
63 changes: 31 additions & 32 deletions docs/specs/2026-09-28-v2-parity.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ features when V1 has no equivalent; do not weaken or remove the V1 path.
The provider catalog is global, while Command Code enforces account entitlements
at request time. GOAT is the live-tested baseline. Other plans with Provider API
access are in scope for models they entitle, but plan-specific access is not
claimed as live-verified. The $1 Go plan is unsupported because Command Code
documents that it does not include Provider API access; this is an API
availability limit, not a claim about its Terms of Service. See the official
claimed as live-verified. The $1 Go plan's monthly allowance does not pay for
Provider API requests; Go accounts can use the API with eligible free or
purchased credits. See the official
[GOAT plan](https://commandcode.ai/docs/plans/goat), [Go plan](https://commandcode.ai/docs/plans/go),
and [Provider API](https://commandcode.ai/docs/provider) documentation.

Expand All @@ -33,31 +33,29 @@ and [Provider API](https://commandcode.ai/docs/provider) documentation.

## A — Endpoint-aware model routing

The provider's live `/models` metadata is the route authority when
`supported_endpoints` is present. Prefer Anthropic Messages when advertised,
then Chat Completions, and use Responses when it is the only advertised route.
This is a shared endpoint policy, not a DeepSeek-specific model override. The
actual OpenCode V2.0.18 session error was a `response.output_item.added` event
whose `function_call` item omitted its required `arguments` string during a
DeepSeek V4.1 Flash `#max` shell-tool request. The earlier annotation-event
diagnosis was incorrect. Current Command Code metadata advertises Chat on all
74 non-Messages-only models, so the policy sends those models through Chat;
Messages-only models keep Anthropic Messages. The 0.10.2 Responses mappings
remain for future models that advertise Responses without another route, but
the current catalog has no such entry. Other models' Responses tool-call streams
were not individually live-tested.
The shared V1/V2 policy uses Command Code's `/models` `supported_endpoints`
metadata. Claude uses Anthropic Messages when advertised. Other models use
Chat Completions whenever advertised, even when they also list Messages or
Responses. Outside the Claude preference, Chat Completions is preferred whenever
advertised; if only Messages and/or Responses are advertised, Messages is
preferred when available, otherwise Responses. With no usable route
selection, the default is Messages for Claude and Chat Completions otherwise.
In particular, DeepSeek V4 Flash, DeepSeek V4.1 Flash, Kimi K3, GLM-5.3 Flash,
and Ergo 1.0 keep the default Chat transport despite advertising Messages.
This preserves the path verified for the DeepSeek V4.1 Flash `#max` shell-tool
request. The prior Responses failure on V2.0.18 was a
`response.output_item.added` event whose `function_call` item omitted its
required `arguments` string.

V1 uses `@ai-sdk/openai` for Responses and the Anthropic SDK for Messages. V2
uses OpenCode's native `@opencode/ai/providers/openai-compatible`,
`@opencode/ai/providers/openai/responses`, and
`@opencode/ai/providers/anthropic` runtimes. The legacy `aisdk:` adapter did
not reliably carry provider settings into model requests: image requests and
an existing image-bearing session returned `Invalid input` until a manual
provider base URL was supplied. The native runtime preserves the plugin's base
URL and requires no manual provider block. If an older catalog
lacks route metadata, Claude retains the Messages fallback and other models
retain Chat Completions. The current 84-model catalog has 66 models advertising
both Chat Completions and Responses, 10 Messages-only, and 8 Chat-only; it has
no Responses-only model.
URL and requires no manual provider block. A Responses-only model is covered
by mapping tests, not live inference.

The isolated GOAT-key probes for Claude Sonnet and Haiku returned
`MODEL_NOT_IN_PLAN`. Claude Sonnet 4.6 reported that it is available on Pro and
Expand Down Expand Up @@ -86,12 +84,9 @@ The strict catalog pipeline carries:
Qwen 3.6 Plus, and MiniMax M2.7 to 200K.
3. models.dev `limit.input`, `family`, and `beta`/`deprecated` status when
present. Missing status remains active.
4. Existing modalities and costs without clearing known values when a metadata
source is partial.

The current 84-model catalog has release dates for 82 entries, family for 78,
input limits for 13, one beta model, and one deprecated model. These are
generated-data counts, not fixed schema expectations.
4. Sync-time inputs limited to text and, when the CLI or a matching models.dev
row lists it, image. PDF, video, audio, and file inputs are not supported by
the Provider API. The runtime schema still accepts older catalog modalities.

## C — V2 integration and auth

Expand All @@ -115,8 +110,7 @@ temporary container environment, the eligible DeepSeek smoke test succeeded.
The sync pipeline preserves models.dev context tiers and `context_over_200k`.
Tier aliases are accepted only when their base input and output prices match
the Command Code catalog, preventing another provider's rates from entering
this catalog. The current sync has tiers for 23 models, with boundaries at
32K, 128K, 200K, 200001, 256K, 262144, 272K, and 512K tokens.
this catalog.

V2 emits native `cost[]` tiers. V1 emits `context_over_200k` when an exact
200K tier is available and keeps its flat base price for other tiers that its
Expand All @@ -127,15 +121,20 @@ model schema cannot express.
README examples use the bare unpinned npm package with `plugin` for V1 and
`plugins` for V2. They explain that V2 checks for package updates at startup but
does not silently replace its cache, describe both auth surfaces and their
distinct cost support, and state the plan/test limits. The stable-model-identity
distinct cost support, state the plan/test limits, and note that free models
are not ZDR-routed. The stable-model-identity
spec describes the 0.9.1 baseline historically and links here for current V2
auth and metadata behavior.

## Verification

- Unit tests cover strict schema validation, source merging, vendor context
clamps, tier alias price matching, V1/V2 metadata and cost mappings, Claude
package selection, and V2 integration registration.
clamps, tier alias price matching, V1/V2 metadata and cost mappings, route
selection (including the five non-Claude models with both Chat and Messages),
sync-time input filtering, and V2 integration registration.

Earlier live and release-candidate verification:

- `bun run check` passed: lint, formatting, typecheck, and 235 unit tests
(668 expectations).
- `bun run build` passed and produced `dist/plugin.js` (0.73 MB).
Expand Down
Loading