Skip to content

fix(provider): discover models from openai-compatible endpoints - #48510

Closed
yeager1977 wants to merge 35 commits into
anomalyco:devfrom
yeager1977:fix/openai-compatible-model-discovery
Closed

fix(provider): discover models from openai-compatible endpoints#48510
yeager1977 wants to merge 35 commits into
anomalyco:devfrom
yeager1977:fix/openai-compatible-model-discovery

Conversation

@yeager1977

Copy link
Copy Markdown

Problem

Custom openai-compatible providers defined in opencode.json show a stale model list after options.baseURL changes. opencode never fetches /models from the provider's endpoint — the list is assembled from the static models config map and the models.dev catalog, both keyed by provider ID. Changing baseURL only changes the request target (resolveSDK), never the displayed list. Reproduced with an Ollama server moved between hosts: the old host's models kept showing until a manual cache refresh, and even then the list stayed wrong because no discovery from baseURL existed at all.

Fix

At provider state build, for config providers with npm: "@ai-sdk/openai-compatible", fetch GET {baseURL}/models and use the server's response as the model list:

  • Server-served models replace the stored list; config-declared entries the server still serves are kept (their options/variants/limits are preserved as templates).
  • Discovery failure (endpoint down, non-OpenAI shape, timeout) falls back to the configured list — no behavior change for unreachable endpoints.
  • Honors options.baseURLapi precedence matching resolveSDK, ${VAR} env interpolation, stored auth keys, and filters embedding/rerank entries.
  • Skips discovery when the provider ID matches a models.dev entry with the same api URL (the catalog is authoritative there).

Testing

  • New tests in packages/opencode/test/provider/provider.test.ts:
    • discovery replaces the configured list with the live server list (mock OpenAI-compatible server on a random port)
    • discovery failure keeps the configured models
    • both verified failing before the fix, passing after
  • Full test/provider/ suite: 716 pass, 0 fail (one pre-existing test that pointed at a live localhost:11434 was made deterministic with a dead port since discovery now actually contacts the endpoint)
  • test/config/ 230 pass, test/server/ 297 pass, test/plugin/ pass
  • tsgo --noEmit clean in packages/opencode and packages/core

…ft, localized scope, atomic cache, single-flight cold fetch)
…ft, localized scope, atomic cache, single-flight cold fetch)
Custom openai-compatible providers showed stale model lists because
nothing fetched /models from the configured baseURL: the list came from
static config entries and the models.dev catalog keyed by provider ID,
so changing options.baseURL only changed the request target.

Discover GET {baseURL}/models at provider state build for config
providers with npm @ai-sdk/openai-compatible. Server-served models
replace the stored list (keeping config-declared entries the server
still serves); discovery failures keep the configured list. Honors
options.baseURL/api precedence, ${VAR} env interpolation, stored auth
keys, and skips embedding/rerank entries.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

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

I found several potentially related PRs:

Closely Related (Same/Similar Feature):

  1. PR feat(opencode): auto-discover models from OpenAI-compatible providers #32731 - feat(opencode): auto-discover models from OpenAI-compatible providers

    • Appears to be an earlier/related feature for auto-discovering models from OpenAI-compatible providers
  2. PR feat(provider): add dynamic model discovery for custom providers #42660 - feat(provider): add dynamic model discovery for custom providers

    • Related to dynamic model discovery for custom providers
  3. PR feat(opencode): local LAN provider discovery + auto-discover models #27554 - feat(opencode): local LAN provider discovery + auto-discover models

    • Related to provider discovery and auto-discovering models

Potentially Related:

The most likely duplicate candidates are #32731 and #42660, which appear to address similar model discovery functionality for custom providers. You may want to check if those PRs are already merged or if this PR supersedes them with a different implementation approach (this PR appears to be fixing a specific baseURL stale model issue).

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 11, 2026
@github-actions github-actions Bot closed this Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant