Skip to content

feat(core): add OPENCODE_DISABLE_FREE_MODELS to hide free models - #57478

Merged
thdxr merged 3 commits into
devfrom
disable-free-models
Oct 21, 2026
Merged

thdxr merged 3 commits into
devfrom
disable-free-models

Conversation

@thdxr

@thdxr thdxr commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

N/A

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds the env-only OPENCODE_DISABLE_FREE_MODELS=1 (or true). Models with no input price are removed from the opencode and opencode-go catalogs, defaults and fallbacks. Explicit selection returns the existing Model unavailable error. Signed out, opencode is absent; a Console login or API key restores its paid models. Flag-off behavior is unchanged.

The runtime diff is just +8/-1 across two files: capture the boolean at each owner's initialization, filter the final model snapshot, and skip signed-out public-key activation. Filtering after transforms prevents model config from recreating free models. preferFree stays unchanged for flag-off ordering.

Removed the server option, Model.configured, service field, helper, fixture extension and five unrelated fake-service edits. Total PR: 6 files, +173/-1, down from 15 files, +466/-203.

Go coverage costs one loop line and matters: with an API key, its zero-cost model otherwise became the default. Explicit provider config can still activate the provider; preserving that existing override avoids adding another activation policy. Free models remain filtered.

How did you verify your code works?

  • bun run check: passed (34 typecheck tasks; existing lint warnings, zero errors).
  • Relevant core tests: 158 passed across seven files. The two feature test files also passed ten randomized repetitions: 500 passed.
  • Tests cover real env values, both providers, catalog/get/default/small-model filtering, explicit-selection errors, late transforms, OAuth connection after startup and API-key activation.
  • Website typecheck, check:generated and build/link validation passed.
  • Worktree CLI opencode serve, isolated HOME/config, bundled catalog, /api/provider, /api/model and /api/model/default:
Server environment Providers OpenCode models Go models Default
Flag off, signed out opencode 10 free 0 opencode/big-pickle
Flag 1, signed out none 0 0 none
Flag true + API key opencode, opencode-go 74 paid, 0 free 26 paid, 0 free opencode-go/gemini-4-argon-contributor

The manual API key was synthetic; these checks exercise catalog activation, not paid inference.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as described, and I found no blocking issues. I ran opencode models --standalone from source while signed out. Before the change, the 10 free opencode/* models stay listed even with OPENCODE_DISABLE_FREE_MODELS=1. With the change and the flag, none are listed. With OPENCODE_API_KEY set as well, the 74 paid opencode/* models remain. run --model opencode/big-pickle fails with Model unavailable: opencode/big-pickle. The new and existing model tests pass, and typecheck passes in core, server and cli.

The filter is applied when the catalog is read, after plugin changes, so get/all/available/default all respect it and a plugin or config entry can't bring a free model back. Moving the plugin's gating to Model.isFree doesn't change behaviour.

Public API changes, all backwards compatible:

  • New environment variable OPENCODE_DISABLE_FREE_MODELS.
  • ServerOptions.models gains an optional free: boolean.
  • @opencode/core/model adds the exports Options, configured(options) and isFree. Model.node is unchanged (configured()).

Related: #55150

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant