opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(opencode): add auto model detection for OpenAI-compatible providers

Open tomzhu1024 opened this issue 2 days ago • 15 comments

What does this PR do?

This PR adds automatic model detection/discovery for providers that use npm: @ai-sdk/openai-compatible. It allows OpenCode to utilize the GET /v1/models API to populate the model list.

Models may come from 3 sources now: Models.dev, config file, and detected via API. The "filtering" logic is: the model will be visible, if it's detected via API or declared in config file; if it is visible, its metadata will be merged from API -> config -> Models.dev (with prescedence from high to low).

Fixes #6231 Fixes #4232 Fixes #2456

Note: I understand it may be by design to rely entirely on Models.dev for providers and models, but having OpenCode core automatically populate the model list would be a major improvement for users running LM Studio or other local providers.

How did you verify your code works?

  1. I ran an LM Studio server locally and downloaded two models (openai/gpt-oss-20b and zai-org/glm-4.6v-flash).
  2. I configured my ~/.config/opencode/opencode.json with two LM Studio providers and two models. One of the models does not exist in LM Studio, but should still appear later. (File attached: opencode.json).
  3. I used a debugger and breakpoints to inspect the providers value at packages/opencode/src/provider/provider.ts#958, and it looked correct to me.
  4. I ran bun dev -- models, and the output looked correct.
  5. I launched the TUI with bun dev, ran /models, and the output also looked correct.
  6. From the TUI, I was able to use both local models in LM Studio and cloud models I had previously configured.
  7. I shut down the LM Studio server and repeated steps 3–6; everything behaved as expected.

tomzhu1024 avatar Jan 14 '26 05:01 tomzhu1024