A universal OpenCode plugin for dynamic model discovery across any OpenAI-compatible provider.
Originally inspired by opencode-lmstudio, this project has been refactored into a general-purpose model discovery plugin with provider-level discovery controls, model filtering, metadata enrichment, and /connect-backed credential support.
- Works with any OpenAI-compatible provider
- Discovers models dynamically from provider model endpoints
- Injects discovered models into OpenCode provider config automatically
- Supports provider-level include, exclude, and endpoint overrides
- Supports regex-based model filtering
- Can enrich model limits and reasoning metadata from provider-specific endpoints
- Supports OpenCode
/connectcredentials for custom providers
npm install opencode-models-discovery
# or
bun add opencode-models-discoveryAdd the plugin to your opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": [
"opencode-models-discovery@latest"
],
"provider": {
"lmstudio": {
"npm": "@ai-sdk/openai-compatible",
"name": "LM Studio (local)",
"options": {
"baseURL": "http://127.0.0.1:1234/v1",
"modelsDiscovery": {
"enabled": true
}
}
}
}
}On startup, the plugin will query the provider's models endpoint and merge discovered models into the active OpenCode config.
If you upgrade the plugin and OpenCode still behaves like it is using an older build, refresh the OpenCode plugin cache and restart OpenCode.
This can happen because OpenCode may continue using a previously cached package after the npm package itself has been updated.
For custom OpenAI-compatible providers, you still define the provider in opencode.json so OpenCode and this plugin know the provider id, npm package, and baseURL.
If the API credential is managed through OpenCode /connect, you do not need to duplicate the same key in provider.<name>.options.apiKey.
Discovery auth precedence is:
provider.<name>.options.apiKey- OpenCode resolved provider key, when available during plugin startup
- OpenCode
/connectauth store for same-idtype: "api"credentials
Details and examples: docs/connect-and-auth.md
- Configuration guide:
docs/configuration.md /connectcredentials and auth-backed discovery:docs/connect-and-auth.md- Provider compatibility and detection rules:
docs/providers.md - Upgrade notes:
docs/upgrading.md
- OpenCode with plugin support
- At least one OpenAI-compatible provider running locally or remotely
- Provider API accessible through either a
/v1-style base URL or an explicitly configured discovery endpoint
When available, the plugin writes logs through OpenCode's structured server log API via client.app.log(...) using the service name opencode-models-discovery.
If structured logging is unavailable in the runtime, the plugin falls back to prefixed console.* output. Key log categories are emitted through metadata such as plugin, config, discovery, event, and filtering to make local debugging easier with opencode --print-logs.
Contributions are welcome. Please feel free to submit a Pull Request.
MIT
This project is not built by the OpenCode team and is not affiliated with OpenCode in any way.