For custom OpenAI-compatible providers, you still need to define the provider in opencode.json so OpenCode and this plugin know the provider id, npm package, and baseURL.
This page documents the OpenCode v1 /connect and auth-store integration. OpenCode v2 support is currently in beta and does not use the V1 auth-store fallback; configure credentials in providers.<id>.settings according to the V2 configuration guide.
However, you do not have to hardcode options.apiKey when the provider credential is managed through OpenCode /connect.
{
"$schema": "https://opencode.ai/config.json",
"plugin": [
"opencode-models-discovery@latest"
],
"provider": {
"test_provider": {
"npm": "@ai-sdk/openai-compatible",
"name": "Test Provider",
"options": {
"baseURL": "http://127.0.0.1:4000/v1",
"modelsDiscovery": {
"enabled": true
}
}
}
}
}Then run /connect, choose the same provider id, and save the API key there.
Discovery requests resolve credentials in this order:
provider.<name>.options.apiKey- OpenCode resolved provider key, when available during plugin startup
- Host auth store for same-id
type: "api"credentials
This preserves existing explicit apiKey configs while also allowing custom providers to rely on /connect without duplicating secrets in opencode.json.
- On OpenCode startup, the plugin's
confighook is called. - The plugin iterates through all configured providers.
- For each provider, it checks whether it is OpenAI-compatible by npm, by a
/v1baseURL, by an explicit discovery endpoint override, or by a forced provider-level discovery override. - For each accessible provider, it resolves discovery auth from explicit config first and then from OpenCode-managed auth when available.
- It queries the configured models endpoint, defaulting to
/v1/models. - Discovered models are automatically merged into the provider's configuration.
- The enhanced configuration is used for the current session.
- OpenCode's provider resolution API can time out inside the
confighook, so the plugin includes a fallback for/connectAPI-key credentials. - That fallback first respects
OPENCODE_AUTH_CONTENT, then reads a host-specific auth store location derived fromxdg-basedir. - When
OPENCODE=1is present, the plugin reads~/.local/share/opencode/auth.json. - When
MIMOCODE=1is present, the plugin reads~/.local/share/mimocode/auth.json. - When neither host marker is present, the plugin defaults to
~/.local/share/opencode/auth.json. - The plugin never writes the recovered key back into
opencode.jsonand never logs the secret value.