fix(provider): discover models from openai-compatible endpoints - #48549
fix(provider): discover models from openai-compatible endpoints#48549yeager1977 wants to merge 1 commit into
Conversation
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.
(cherry picked from commit 67b44e0)
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found several related PRs that are worth noting: Potentially Related PRs:
These PRs all involve model discovery from OpenAI-compatible endpoints, which is the core functionality your PR #48549 is implementing. I recommend checking these (especially #27554 and #32731) to ensure your fix doesn't duplicate work or conflict with existing implementations. |
|
Checked all four related PRs the bot flagged. Keeping this PR's focused implementation rather than folding them in — rationale:
This change is the minimal fix for the stale model list in #27553 and is green/mergeable today. Happy to follow up with the useful refinements from #32731 (e.g. a |
Issue for this PR
Closes #27553
Type of change
What does this PR do?
Custom
openai-compatibleproviders configured inopencode.jsonshow a stale model list afteroptions.baseURLchanges. opencode never fetches/modelsfrom the endpoint; the list is assembled from staticmodelsconfig and the models.dev catalog, both keyed by provider ID. ChangingbaseURLonly changes the request target, not the displayed list. Reproduced with an Ollama server moved between hosts: the old host's models kept showing.When building provider state, for config providers with
npm: "@ai-sdk/openai-compatible", this fetchesGET {baseURL}/modelsand uses the server response as the model list:options.baseURL->apiprecedence matchingresolveSDK,${VAR}env interpolation, stored auth keys, and filters embedding/rerank entries.How did you verify your code works?
packages/opencode/test/provider/provider.test.tswith a mock OpenAI-compatible server on a random port: discovery replaces the configured list, and discovery failure keeps the configured models. Verified failing before the fix, passing after.test/provider/: 716 pass, 0 fail.bun typecheckclean inpackages/opencode.Screenshots / recordings
N/A (non-UI).
Checklist