fix(provider): discover models from openai-compatible endpoints - #48510
fix(provider): discover models from openai-compatible endpoints#48510yeager1977 wants to merge 35 commits into
Conversation
…ing, XDG, confirm)
…uplicate guard, scoping)
…ft, localized scope, atomic cache, single-flight cold fetch)
…ft, localized scope, atomic cache, single-flight cold fetch)
…atches loadMcpQuery)
…t malformed status
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.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
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. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: I found several potentially related PRs: Closely Related (Same/Similar Feature):
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). |
|
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. |
Problem
Custom
openai-compatibleproviders defined inopencode.jsonshow a stale model list afteroptions.baseURLchanges. opencode never fetches/modelsfrom the provider's endpoint — the list is assembled from the staticmodelsconfig map and the models.dev catalog, both keyed by provider ID. ChangingbaseURLonly 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 frombaseURLexisted at all.Fix
At provider state build, for config providers with
npm: "@ai-sdk/openai-compatible", fetchGET {baseURL}/modelsand use the server's response as the model list:options.baseURL→apiprecedence matchingresolveSDK,${VAR}env interpolation, stored auth keys, and filters embedding/rerank entries.Testing
packages/opencode/test/provider/provider.test.ts:test/provider/suite: 716 pass, 0 fail (one pre-existing test that pointed at a livelocalhost:11434was made deterministic with a dead port since discovery now actually contacts the endpoint)test/config/230 pass,test/server/297 pass,test/plugin/passtsgo --noEmitclean inpackages/opencodeandpackages/core