[PR #8359] feat(opencode): add auto model detection for OpenAI-compatible providers #12716

Closed
opened 2026-02-16 18:17:36 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8359

State: closed
Merged: Yes


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.
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8359 **State:** closed **Merged:** Yes --- ### 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](https://github.com/user-attachments/files/24605320/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.
yindo added the pull-request label 2026-02-16 18:17:36 -05:00
yindo closed this issue 2026-02-16 18:17:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12716