GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(opencode): auto-discover models from OpenAI-compatible providers by sethjones · Pull Request #32731 · anomalyco/opencode

Conversation

@sethjones

@sethjones sethjones commented Jun 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #6231

Type of change

  • New feature

What does this PR do?

Auto-discovers available models from OpenAI-compatible providers that have a baseURL configured in opencode.json. Instead of requiring users to list every model manually, opencode now calls GET /v1/models at startup and populates the model list.

Models come from three sources: Models.dev (metadata), config file (overrides), and the provider API (actual availability). A model is visible only if the provider API returns it or it is declared in config. Metadata is merged with API > config > Models.dev precedence.

This means providers like LM Studio, Ollama, and self-hosted OpenAI-compatible servers automatically show their loaded models without any per-model configuration.

New in this iteration:

discoverModels: false opt-out — Set discoverModels: false at the provider top level to skip discovery entirely. Useful when you want to manage models exclusively through config or Models.dev.

{
  "provider": {
    "my-local": {
      "npm": "@ai-sdk/openai-compatible",
      "discoverModels": false,
      "options": { "baseURL": "http://localhost:8080/v1" }
    }
  }
}

Context & output limits from API — Discovery now parses context_length (or max_context_length) and max_output_tokens from the provider API response and applies them to discovered models. Config-defined limits always take precedence.

Warning logs — Discovery failures (timeout, network error, non-2xx status, JSON parse failure) now emit Effect.logWarning with provider ID and reason. Additionally, when config-defined limits exceed the discovered limits, a warning is logged so users know their config may cause runtime failures.

How did you verify your code works?

  • Built a standalone binary and ran it with a llama.cpp server configured via baseURL
  • Confirmed models appear in the TUI /models list without manual per-model config
  • Confirmed models not returned by the provider API are hidden, even if listed in Models.dev
  • Confirmed startup completes without hanging or displaying discovery output to the terminal
  • Ran bun typecheck from packages/opencode — passes
  • Ran provider tests — 97 tests pass

Checklist

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kevincox, spacelatte, johnnyasantoss, Invizory, Run1e, SuperSandro2000, and xcvrlv reacted with thumbs up emoji
All reactions
  • 👍 7 reactions
sethjones added 5 commits June 14, 2026 15:17
@sethjones
feat(provider): auto-discover models from custom OpenAI-compatible pr…
1d7ceba
…oviders
@sethjones
feat(opencode): add custom provider model discovery
f765cdd
- Fetch models from OpenAI-compatible providers with baseURL in config
- Support plugin-registered discovery loaders (e.g., GitLab)
- Discovery runs synchronously during bootstrap init
- Remove providers with no models after successful discovery
- Add tests for discovery and model registration
@sethjones
fix(opencode): resolve code review issues in provider model discovery
552be5c
- Extract discoverProviderModels() helper from inline 110-line Effect.gen
- Replace globalThis.fetch with HttpClient layer (FetchHttpClient)
- Add Effect.timeout(10s) to HTTP discovery requests
- Replace Exit._tag with Exit.isSuccess/IsFailure
- Remove redundant config.get() in init() (use captured s.cfg)
- Remove unnecessary 'as any' casts
- Fix indentation to consistent 2-space
- Set family: 'discovered' on discovered models
- Update discovery tests to use HttpClient layer mocks
@sethjones
refactor: format fixes
63738c0
@sethjones
Merge branch 'dev' into custom-model-discovery
51dc086
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate PRs Found

Based on my search, I found several related PRs that may be addressing similar or overlapping functionality:

  1. PR feat(opencode): local LAN provider discovery + auto-discover models #27554 - feat(opencode): local LAN provider discovery + auto-discover models

    • Appears to address local LAN provider discovery combined with auto-discovery of models
  2. PR feat(core): add OmniRoute custom provider support #32170 - feat(core): add OmniRoute custom provider support

    • May be related to custom provider configuration and model discovery
  3. PR feat(opencode): add local server provider with auto model discovery #19959 - feat(opencode): add local server provider with auto model discovery

    • Directly addresses auto model discovery for local servers
  4. PR feat(provider): add Requesty model discovery from /v1/models #28973 - feat(provider): add Requesty model discovery from /v1/models

    • Specifically implements /v1/models endpoint discovery (same approach as current PR)
  5. PR feat(provider): add endpoint-based custom providers and model discovery #29392 - feat(provider): add endpoint-based custom providers and model discovery

    • Addresses endpoint-based custom providers with model discovery functionality

These PRs should be reviewed to determine if they:

  • Are already closed/merged solutions to the same issue
  • Address overlapping functionality that needs to be consolidated
  • Have different scopes that complement each other

I recommend checking PR #27554, #19959, #28973, and #29392 in particular, as they appear most directly related to auto-discovering models from providers.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sethjones added 3 commits June 17, 2026 18:14
@sethjones
feat(opencode): add discoverModels opt-out for provider model discovery
f257e88
@sethjones
feat(opencode): parse context_length and max_output_tokens from disco…
d9add28
…vered models
@sethjones
feat(opencode): log warnings for discovery failures and config limits…
52b7184
… exceeding discovered
@sethjones
sethjones marked this pull request as ready for review June 17, 2026 22:17
@sethjones
Merge branch 'dev' into custom-model-discovery
7d28dac
@sethjones

sethjones commented Jun 18, 2026

Copy link
Copy Markdown
Author

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate PRs Found

Based on my search, I found several related PRs that may be addressing similar or overlapping functionality:

1. **PR [feat(opencode): local LAN provider discovery + auto-discover models #27554](https://github.com/anomalyco/opencode/pull/27554)** - `feat(opencode): local LAN provider discovery + auto-discover models`
   
   * Appears to address local LAN provider discovery combined with auto-discovery of models

2. **PR [feat(core): add OmniRoute custom provider support #32170](https://github.com/anomalyco/opencode/pull/32170)** - `feat(core): add OmniRoute custom provider support`
   
   * May be related to custom provider configuration and model discovery

3. **PR [feat(opencode): add local server provider with auto model discovery #19959](https://github.com/anomalyco/opencode/pull/19959)** - `feat(opencode): add local server provider with auto model discovery`
   
   * Directly addresses auto model discovery for local servers

4. **PR [feat(provider): add Requesty model discovery from /v1/models #28973](https://github.com/anomalyco/opencode/pull/28973)** - `feat(provider): add Requesty model discovery from /v1/models`
   
   * Specifically implements `/v1/models` endpoint discovery (same approach as current PR)

5. **PR [feat(provider): add endpoint-based custom providers and model discovery #29392](https://github.com/anomalyco/opencode/pull/29392)** - `feat(provider): add endpoint-based custom providers and model discovery`
   
   * Addresses endpoint-based custom providers with model discovery functionality

These PRs should be reviewed to determine if they:

* Are already closed/merged solutions to the same issue

* Address overlapping functionality that needs to be consolidated

* Have different scopes that complement each other

I recommend checking PR #27554, #19959, #28973, and #29392 in particular, as they appear most directly related to auto-discovering models from providers.

Here's how this PR differs from each referenced PR:

#27554 (#27554) (androidand) — Solves a broader problem: LAN-level provider discovery (mDNS, subnet scanning, TCP probing) plus model discovery. This PR is scoped specifically to config-file-driven model discovery for already-configured providers, using the Effect HttpClient layer instead of raw Promise.all/fetch. The discoverModels: false opt-out and warning logs for config-vs-discovered limit mismatches are not present in that PR.

#32170 (#32170) (MohammadMD1383) — Adds a single hardcoded OmniRoute provider with its own auth plugin. It doesn't apply to arbitrary user-configured OpenAI-compatible endpoints, doesn't parse context/output limits, and has no opt-out mechanism.

#19959 (#19959) (hmblair) — A ~50-line proof-of-concept for a single hardcoded "local" provider with an autoload boolean return. Doesn't support multiple providers, doesn't parse limits, doesn't filter Models.dev, and has no opt-out or warning logs.

#28973 (#28973) (Thibaultjaigu) — Specific to Requesty only (hardcoded URL). Solves the user-specific routing policies problem, not general OpenAI-compatible endpoint discovery.

#29392 (#29392) (dasdkslkd) — Closest in concept but orthogonal: adds a runtime UI flow for adding/removing custom providers through the app. Doesn't parse limits, doesn't filter Models.dev, has no opt-out, and doesn't use the Effect HttpClient layer.

This PR's differentiating aspects are:

  • Works for any provider configured with baseURL in opencode.json (not hardcoded to a single provider)
  • Discovers context_length and max_output_tokens from the API
  • Filters out Models.dev models not actually returned by the provider
  • discoverModels: false per-provider opt-out
  • Warning logs for discovery failures and config limits exceeding discovered limits
  • Uses the Effect HttpClient layer (FetchHttpClient) with 10s timeout (10s might be too long. I've considered 5s, but would love some feedback.)
  • Atomic result application via init() instead of mutation during layer construction
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sethjones
fix(opencode): handle TOCTOU race in discovery apply and sanitize ope…
082b2c7
…nai-compatible schemas

- Log warning and continue when provider disappears between discovery snapshot and apply
- Add @ai-sdk/openai-compatible to schema sanitization check
- Add test case for openai-compatible schema sanitization
This was referenced Jun 18, 2026
📊 AI CLI 工具社区动态日报 2026-06-18 zx0828/big_model_radar#141
Open
📊 AI CLI 工具社区动态日报 2026-06-18 litang9/big_model_radar#80
Open
feat(core): support localhosting setting api link and key in connect #33103
Closed
@sethjones
Merge branch 'dev' into custom-model-discovery
450ac37
@Thibaultjaigu

Thibaultjaigu commented Jun 23, 2026

Copy link
Copy Markdown

@sethjones anyway we can add this?

We have now had over 445 users complain about this issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sethjones

sethjones commented Jun 23, 2026

Copy link
Copy Markdown
Author

@sethjones anyway we can add this?

We have now had over 445 users complain about this issue.

I'm not sure how to get the team to prioritize / respond versus what I've done already with making sure it's ready and linked.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ProjectInitiative added a commit to ProjectInitiative/opencode that referenced this pull request Jun 28, 2026
@ProjectInitiative
feat(opencode): auto-discover models from OpenAI-compatible providers (…
aad7116
…anomalyco#32731)

Merge PR anomalyco#32731 by sethjones into dev branch.

Auto-discovers available models from OpenAI-compatible providers that
have a baseURL configured. opencode now calls GET /v1/models at startup
and populates the model list from the provider API.

Features:
- discoverModels: false opt-out per-provider
- Parses context_length and max_output_tokens from API
- Warning logs for discovery failures and config limits exceeding discovered limits
ProjectInitiative added a commit to ProjectInitiative/opencode that referenced this pull request Jun 28, 2026
@ProjectInitiative
Revert "feat(opencode): auto-discover models from OpenAI-compatible p…
686e4d6
…roviders (anomalyco#32731)"

This reverts commit aad7116, reversing
changes made to dfeb1b5.
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
Refactors existing commits from issue https://github.com/anomalyco/op… #36790
Closed
6 tasks
This was referenced Jul 27, 2026
feat: discover Modal models #39066
Merged
Feat #6231 - automatic discovery of models from providers #39176
Closed
@github-actions github-actions Bot mentioned this pull request Aug 7, 2026
feat(provider): discover local model context limits #41104
Closed
3 of 6 tasks
@github-actions github-actions Bot mentioned this pull request Aug 14, 2026
feat(provider): add dynamic model discovery for custom providers #42660
Closed
3 of 6 tasks
This was referenced Sep 11, 2026
feat(provider): discover models for openai-compatible providers #48486
Closed
fix(provider): discover models from openai-compatible endpoints #48510
Closed
fix(provider): discover models from openai-compatible endpoints #48549
Closed
@el-AI-wei el-AI-wei mentioned this pull request Sep 14, 2026
[FEATURE]: Add LiteLLM as a provider #48938
Closed
1 task done
hunterchristian added a commit to chipp-ai/opencode that referenced this pull request Sep 23, 2026
@hunterchristian @claude
feat(core): add opt-in model auto-discovery for OpenAI-compatible pro…
41685be
…viders

A configured provider can opt in (discover: true, or the v1 config's
discoverModels: true) to have opencode call GET {baseURL}/models and
add whatever the endpoint reports to the catalog, instead of
requiring every model to be hand-listed -- useful for LM Studio,
vLLM, llama.cpp/llama-swap, or any generic OpenAI-compatible
self-hosted endpoint.

Ported from upstream anomalyco#6231 (247 reactions/57
comments -- the second-highest reaction count found across a full
survey of this repo's open issues). Three substantial PRs sat open
and unmerged for 3+ months despite that reaction count. PR anomalyco#32731 (8
files, tightly scoped) is the primary source: this fork reuses its
discoverModels field name, which limit fields to read from the
response, the discovered-model shape, and the "configured/models.dev
wins" merge rule. Deliberately changed from anomalyco#32731: discovery is
opt-in per provider here, not automatic for every provider with a
baseURL -- always-on would fire a startup network request at every
existing custom provider. Unknown limits are left at 0 rather than
anomalyco#32731's guessed 128k default. PR anomalyco#42660's URL-with-existing-path
handling was reused, rewritten with this repo's own HttpClient/Schema
idioms instead of raw fetch in a try/catch; its UI and endpoint
weren't ported. PR anomalyco#27554 (100+ files) had nothing usable beyond
confirming scope overlap. New, since none of the three PRs target it:
a v2 Catalog.Service plugin (this repo didn't have a plugin/catalog
system when those PRs were written).

Runs in both of this repo's provider surfaces: the legacy provider
service (inline before the filter pass, what the TUI model picker
reads) and a new v2 Catalog plugin (packages/core/src/config/plugin/
provider-discovery.ts, once at startup then hourly, same schedule as
the models.dev refresh).

Known gaps: the legacy provider service has no periodic refresh (a
newly-loaded local model appears only after restart/reload); stale
models aren't hidden; discovered capabilities are guesses (no
vision/reasoning detection); only the standard OpenAI models response
shape is understood, not Ollama's native /api/tags; no settings UI or
HTTP endpoint; legacy auth only checks a stored credential or
options.apiKey, not plugin OAuth loaders.

New packages/core/test/provider-discovery.test.ts + config/
provider-discovery.test.ts (unit-level) and packages/opencode/test/
provider/discovery.test.ts (against a real local Bun.serve server,
not a mock). Verified against this fork's current dev, not just the
agent's own stale worktree base: bun typecheck clean across all 30
packages; packages/core 1187 pass (only the pre-existing pty flake);
packages/opencode 3617 pass, only the 4 pre-existing cf-ai-gateway
failures. bun run generate from packages/client correctly produced
no changes -- this is a config-only field, not a Protocol/HttpApi
schema change.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@JLor08 JLor08 mentioned this pull request Sep 30, 2026
No current opencode discovers a gateway model's context size, though the docs say it reads /api/v0/models: opencode v2 asks for /api/v1/models, which 404s here, and /v1/models has no context_length JLor08/op-ai-gateway#171
Closed
@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr thdxr closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Auto-discover models from OpenAI-compatible provider endpoints

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@sethjones @Thibaultjaigu @thdxr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.