Auto-discover models from OpenAI-compatible provider endpoints #3901

Open
opened 2026-02-16 17:41:53 -05:00 by yindo · 3 comments
Owner

Originally created by @ochsec on GitHub (Dec 26, 2025).

Originally assigned to: @thdxr on GitHub.

Description

For OpenAI-compatible local providers (LM Studio, Ollama, llama.cpp, etc.), users currently need to manually list all available models in their opencode.json configuration. This is tedious and error-prone, especially for local providers where models change frequently as they are loaded/unloaded.

Most OpenAI-compatible providers expose a standard /v1/models endpoint that lists all available models. OpenCode should automatically query this endpoint and discover available models, eliminating the need for manual configuration.

Proposed Solution

When a provider uses @ai-sdk/openai-compatible, OpenCode should:

  1. Make a GET request to {baseURL}/models (e.g., http://localhost:1234/v1/models)
  2. Parse the response to extract available models
  3. Automatically populate the model list, merging with any manually configured models
  4. Optionally refresh this list periodically or on-demand

Benefits

  • Better UX: No manual model configuration needed
  • Dynamic updates: Automatically reflects models as they're loaded/unloaded in local servers
  • Fewer errors: Eliminates misconfiguration issues
  • Consistency: Works the same way across all OpenAI-compatible providers

Current Workaround

Users can:

  1. Manually query http://localhost:1234/v1/models to see available models
  2. Manually add each model to opencode.json
  3. Use the community plugin opencode-lmstudio for LM Studio

Example: Current Manual Configuration

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "lmstudio": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "LM Studio (local)",
      "options": {
        "baseURL": "http://127.0.0.1:1234/v1"
      },
      "models": {
        "google/gemma-3n-e4b": {
          "name": "Gemma 3n-e4b (local)"
        },
        "qwen/qwen3-coder-30b": {
          "name": "Qwen 3 Coder 30B"
        }
      }
    }
  }
}

Example: Proposed Auto-Discovery

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "lmstudio": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "LM Studio (local)",
      "options": {
        "baseURL": "http://127.0.0.1:1234/v1"
      }
      // models automatically discovered!
    }
  }
}

Related

OpenCode Version

1.0.58+

Additional Context

The opencode-lmstudio plugin already implements this functionality successfully for LM Studio. Consider integrating similar logic into core OpenCode for all @ai-sdk/openai-compatible providers.

Originally created by @ochsec on GitHub (Dec 26, 2025). Originally assigned to: @thdxr on GitHub. ### Description For OpenAI-compatible local providers (LM Studio, Ollama, llama.cpp, etc.), users currently need to manually list all available models in their `opencode.json` configuration. This is tedious and error-prone, especially for local providers where models change frequently as they are loaded/unloaded. Most OpenAI-compatible providers expose a standard `/v1/models` endpoint that lists all available models. OpenCode should automatically query this endpoint and discover available models, eliminating the need for manual configuration. ### Proposed Solution When a provider uses `@ai-sdk/openai-compatible`, OpenCode should: 1. Make a `GET` request to `{baseURL}/models` (e.g., `http://localhost:1234/v1/models`) 2. Parse the response to extract available models 3. Automatically populate the model list, merging with any manually configured models 4. Optionally refresh this list periodically or on-demand ### Benefits - **Better UX**: No manual model configuration needed - **Dynamic updates**: Automatically reflects models as they're loaded/unloaded in local servers - **Fewer errors**: Eliminates misconfiguration issues - **Consistency**: Works the same way across all OpenAI-compatible providers ### Current Workaround Users can: 1. Manually query `http://localhost:1234/v1/models` to see available models 2. Manually add each model to `opencode.json` 3. Use the community plugin [`opencode-lmstudio`](https://github.com/agustif/opencode-lmstudio) for LM Studio ### Example: Current Manual Configuration ```json { "$schema": "https://opencode.ai/config.json", "provider": { "lmstudio": { "npm": "@ai-sdk/openai-compatible", "name": "LM Studio (local)", "options": { "baseURL": "http://127.0.0.1:1234/v1" }, "models": { "google/gemma-3n-e4b": { "name": "Gemma 3n-e4b (local)" }, "qwen/qwen3-coder-30b": { "name": "Qwen 3 Coder 30B" } } } } } ``` ### Example: Proposed Auto-Discovery ```json { "$schema": "https://opencode.ai/config.json", "provider": { "lmstudio": { "npm": "@ai-sdk/openai-compatible", "name": "LM Studio (local)", "options": { "baseURL": "http://127.0.0.1:1234/v1" } // models automatically discovered! } } } ``` ### Related - #4232 - OpenCode displays models which aren't configured & don't exist in LM Studio - Community plugin: https://github.com/agustif/opencode-lmstudio (implements this for LM Studio) ### OpenCode Version 1.0.58+ ### Additional Context The `opencode-lmstudio` plugin already implements this functionality successfully for LM Studio. Consider integrating similar logic into core OpenCode for all `@ai-sdk/openai-compatible` providers.
Author
Owner

@github-actions[bot] commented on GitHub (Dec 26, 2025):

This issue might be a duplicate of or closely related to existing issues. Please check:

  • #4232: OpenCode displays models which aren't configured & don't exist in LM Studio - related issue with LM Studio model configuration
  • #2901: Add OpenAI-compatible /v1/models endpoint to OpenCode Zen for automatic model discovery - complementary feature for the Zen endpoint

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Dec 26, 2025): This issue might be a duplicate of or closely related to existing issues. Please check: - #4232: OpenCode displays models which aren't configured & don't exist in LM Studio - related issue with LM Studio model configuration - #2901: Add OpenAI-compatible `/v1/models` endpoint to OpenCode Zen for automatic model discovery - complementary feature for the Zen endpoint Feel free to ignore if none of these address your specific case.
Author
Owner

@mdlmarkham commented on GitHub (Dec 30, 2025):

I'm using Ollama Cloud, it seems that OpenCode pulled the available models initially... but it isn't aware of changes. I've used opencode models --refresh... but that doesn't pick up the new ones. (1.0.209)

@mdlmarkham commented on GitHub (Dec 30, 2025): I'm using Ollama Cloud, it seems that OpenCode pulled the available models initially... but it isn't aware of changes. I've used opencode models --refresh... but that doesn't pick up the new ones. (1.0.209)
Author
Owner

@manascb1344 commented on GitHub (Feb 15, 2026):

I have a custom AI provider with 100+ models and new models are added daily. Manually configuring each model in opencode.json is completely unsustainable - I would need to update the config every single day just to keep up with new models.

This issue describes exactly what I need: automatic model discovery from the provider's /v1/models endpoint. The proposed solution of querying {baseURL}/models and automatically populating the model list would solve my problem completely.

I see there are active PRs working on this:

  • #13234 - adds models endpoint (models-endpoint branch)
  • #11951 - probes loaded models from LM Studio, Ollama, etc. (models-endpoint branch)
  • #3726 - auto-detection of Ollama with baseURL variable

These implementations on the models-endpoint branch appear to be the solution this issue requests. Once merged, users like me with large, dynamic model catalogs won't need manual configuration anymore.
Related issues with the same root cause:

  • #12243 - Local Ollama models not included in model listing
  • #2047 - LM Studio Failure to refresh models
  • #7714 - The cache of the Provider's Models cannot be updatable
  • #10594 - Should be able to re-fetch/update model list
@manascb1344 commented on GitHub (Feb 15, 2026): I have a custom AI provider with 100+ models and new models are added daily. Manually configuring each model in `opencode.json` is completely unsustainable - I would need to update the config every single day just to keep up with new models. This issue describes exactly what I need: automatic model discovery from the provider's `/v1/models` endpoint. The proposed solution of querying `{baseURL}/models` and automatically populating the model list would solve my problem completely. I see there are active PRs working on this: - #13234 - adds models endpoint (models-endpoint branch) - #11951 - probes loaded models from LM Studio, Ollama, etc. (models-endpoint branch) - #3726 - auto-detection of Ollama with baseURL variable These implementations on the `models-endpoint` branch appear to be the solution this issue requests. Once merged, users like me with large, dynamic model catalogs won't need manual configuration anymore. Related issues with the same root cause: - #12243 - Local Ollama models not included in model listing - #2047 - LM Studio Failure to refresh models - #7714 - The cache of the Provider's Models cannot be updatable - #10594 - Should be able to re-fetch/update model list
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3901