opencode-models-discovery-proxy
v1.0.0
Published
OpenCode plugin for auto-discovery of OpenAI-compatible models with dynamic provider configuration
Maintainers
Readme
opencode-models-discovery-proxy
An OpenCode plugin that bridges llama-swap-proxy and OpenCode by automatically populating your provider's model list from the /v1/opencode endpoint at startup.
A fork of opencode-models-discovery
Who is this for?
If you are running llama-swap-proxy, it exposes a /v1/opencode endpoint that returns a fully-formed OpenCode provider config describing every model it serves — including context limits, tool-calling support, reasoning mode, vision capabilities, and multimodal modalities. This plugin reads that endpoint and injects those model definitions directly into OpenCode without any manual configuration, so you never have to keep your OpenCode config in sync with your model lineup.
How it works
- OpenCode calls the plugin's
confighook at startup with the full config before initializing providers - The hook reads
baseURLfrom your configured provider's options - It fetches
<baseURL>/v1/opencodeand looks up the entry whose name exactly matches the configured provider name - Every model from that entry is injected into
config.provider[name].models— OpenCode then processes the config as if you had written those models statically inopencode.jsonc
The exact-name match means two providers sharing the same base URL but with different names will never bleed models into each other.
Installation
npm install opencode-models-discovery-proxy
# or
bun add opencode-models-discovery-proxyUsage
Add the plugin with the provider option set to the exact name of your provider in opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": [
["opencode-models-discovery-proxy", {
"provider": "my-server"
}]
],
"provider": {
"my-server": {
"npm": "@ai-sdk/openai-compatible",
"name": "my-server",
"options": {
"baseURL": "http://192.168.2.44:5900/v1"
}
}
}
}The provider option must match the key used in the provider map — that's the name the plugin will look up in the /v1/opencode response. On next startup, OpenCode will have all models from your llama-swap-proxy instance available automatically.
Multiple servers
To use more than one server, add the plugin once per provider:
{
"plugin": [
["opencode-models-discovery-proxy", { "provider": "my-server" }],
["opencode-models-discovery-proxy", { "provider": "my-other-server" }]
],
"provider": {
"my-server": {
"npm": "@ai-sdk/openai-compatible",
"options": { "baseURL": "http://192.168.2.44:5900/v1" }
},
"my-other-server": {
"npm": "@ai-sdk/openai-compatible",
"options": { "baseURL": "http://192.168.2.44:5901/v1" }
}
}
}/v1/opencode response format
The plugin expects the endpoint to return a JSON document conforming to the OpenCode config schema. The provider section is what gets read:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"my-server": {
"npm": "@ai-sdk/openai-compatible",
"name": "my-server",
"options": {
"baseURL": "http://192.168.2.44:5900/v1"
},
"models": {
"Llama-3.3-70B-Instruct-Q8_0": {
"name": "Llama-3.3-70B-Instruct-Q8_0",
"tool_call": true,
"limit": { "context": 32768, "output": 32768 }
},
"Qwen3-8B-Q8_0": {
"name": "Qwen3-8B-Q8_0",
"reasoning": true,
"tool_call": true,
"limit": { "context": 200000, "output": 200000 }
},
"MiniCPM-V-4_5-Q8_0": {
"name": "MiniCPM-V-4_5-Q8_0",
"reasoning": true,
"tool_call": true,
"attachment": true,
"limit": { "context": 200000, "output": 200000 },
"modalities": {
"input": ["text", "image"],
"output": ["text"]
}
}
}
}
}
}All model fields are optional except name. The server derives these from chat templates and your config.yaml overrides — see the llama-swap-proxy README for details.
| Field | Type | Description |
| ----- | ---- | ----------- |
| name | string | Display name for the model |
| tool_call | boolean | Model supports tool/function calling |
| reasoning | boolean | Model has a reasoning/thinking mode |
| attachment | boolean | Model accepts file attachments |
| limit.context | number | Context window size in tokens |
| limit.output | number | Maximum output tokens |
| modalities.input | string[] | Accepted input types, e.g. ["text", "image"] |
| modalities.output | string[] | Produced output types, e.g. ["text"] |
Plugin configuration
| Option | Required | Description |
| ------ | -------- | ----------- |
| provider | yes | Exact name of the provider to hook into. Must match the key in your provider map. |
| models.includeRegex | no | If non-empty, only inject models whose ID matches one of these patterns |
| models.excludeRegex | no | Skip models whose ID matches any of these patterns (ignored when includeRegex is set) |
Example with model filtering:
["opencode-models-discovery-proxy", {
"provider": "my-server",
"models": {
"includeRegex": ["^Llama-", "^Qwen3-"]
}
}]Logging
Logs are emitted under the service name opencode-models-discovery-proxy via OpenCode's structured log API (client.app.log), visible with opencode --print-logs.
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Disclaimer
This project is not built by the OpenCode team and is not affiliated with OpenCode in any way.
