Auto-discover models from local OpenAI-compatible API endpoints for OpenCode.
- Auto-discovers models from local endpoints (Ollama, LM Studio, LLM proxies)
- Fetches metadata from Models.dev and OpenRouter (context window, capabilities, cost)
- Caches metadata locally (24h TTL)
- Supports multiple endpoints
- API key authentication via config or environment variables
- Model filtering with include/exclude patterns
opencode plugin opencode-autodiscoverOr install globally:
opencode plugin opencode-autodiscover -gAdd provider(s) to your opencode.json:
{
"provider": {
"local-ollama": {
"name": "Ollama",
"options": {
"baseURL": "http://localhost:11434/v1"
}
},
"local-lmstudio": {
"name": "LM Studio",
"options": {
"baseURL": "http://localhost:1234/v1"
}
}
}
}{
"provider": {
"local-proxy": {
"name": "My Proxy",
"options": {
"baseURL": "http://localhost:8080/v1",
"apiKey": "sk-your-key"
}
}
}
}API keys can be set via environment variables:
export OPENCODE_LOCAL_MY_PROXY_API_KEY=sk-your-keyOverride metadata for specific models:
{
"provider": {
"local-ollama": {
"options": {
"baseURL": "http://localhost:11434/v1",
"modelOverrides": {
"my-custom-model": {
"contextWindow": 128000,
"maxOutput": 8192
}
}
}
}
}
}Control which models are discovered using include and exclude glob patterns inside options:
{
"provider": {
"local-ollama": {
"options": {
"baseURL": "http://localhost:11434/v1",
"include": ["qwen/*"],
"exclude": ["*embedding*", "*test*"]
}
}
}
}include— if set, only models matching at least one pattern are discoveredexclude— models matching any pattern are skipped (applied afterinclude)*matches anything (including/)- Matching is case-insensitive
- Special characters (
.,[,], etc.) are treated as literals
Models are auto-discovered at startup and appear in /models natively.
To refresh models, use the refresh-local-models tool in OpenCode, then restart.
opencode plugin opencode-autodiscover # Install to project config
opencode plugin opencode-autodiscover -g # Install to global config
opencode plugin opencode-autodiscover -f # Force update existing plugin
opencode plugin opencode-autodiscover --pure # Run without external plugins
- On startup, the plugin reads provider configs with
baseURLoptions - Fetches available models from each endpoint (
/v1/models) - Looks up metadata from Models.dev and OpenRouter (context window, cost, capabilities)
- Injects discovered models into the provider config
- Models appear in OpenCode's
/modelsUI
Metadata is cached locally for 24 hours:
- Location:
~/.cache/opencode-autodiscover/ - Files:
openrouter.json— OpenRouter metadata cachemodelsdev.json— Models.dev metadata cache
Use the refresh-local-models tool to clear cache and re-fetch.
npm install
npm test
npm run buildMIT