opencode-provider-aliasAlias and curate OpenCode providers with model metadata from models.dev.
13
81
近 7 天 18
35.8
生态多维模型
3 个月前
2026-05-11
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-provider-alias@1.0.4"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-provider-alias@1.0.4"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-provider-aliasopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
English | 简体中文
Alias and curate OpenCode providers with model metadata from models.dev.
This plugin lets you define your own OpenCode provider IDs and model IDs, then hydrate them from an existing models.dev provider/model. It is useful when you want a local provider such as my-openai to behave like openai, but expose only a selected model set or local model aliases.
Features
- Map a local OpenCode provider ID to a models.dev provider.
- Inherit all models from the target provider by default.
- Limit exposed models with exact
includesentries. - Use glob-style
includespatterns and!exclusions, powered byminimatch. - Map local model aliases to target models, for example
bar -> openai/gpt-5.5. - Preserve your existing OpenCode provider config such as
name,npm, andoptions.
Usage
No manual install step is required for normal OpenCode usage. Reference the package name in your OpenCode config and keep your provider definition under provider.
{
"plugin": [
[
"opencode-provider-alias@latest",
{
"my-openai": {
"provider": "openai",
"includes": [
"gpt-5.5",
"gpt-5.4",
"gpt-5.4-mini",
"gpt-5.3-codex",
"gpt-5.3-codex-spark"
]
}
}
]
],
"provider": {
"my-openai": {
"npm": "@ai-sdk/openai",
"name": "My OpenAI",
"options": {
"apiKey": "{env:OPENAI_API_KEY}",
"baseURL": "https://example.com/v1"
}
}
}
}
The resulting my-openai provider keeps your provider config, but its model metadata is filled from the openai provider in models.dev.
Configuration
Plugin options are keyed by your local provider ID.
type PluginOptions = Record<
string,
| string
| {
provider?: string
includes?: string[]
models?: Record<string, string>
}
>
Provider alias
Use a string when you only need to map a local provider to a models.dev provider.
{
"plugin": [
[
"opencode-provider-alias@latest",
{
"gpt": "openai"
}
]
],
"provider": {
"gpt": {
"npm": "@ai-sdk/openai",
"name": "GPT",
"options": {
"apiKey": "{env:OPENAI_API_KEY}"
}
}
}
}
If provider.gpt.models is not set, all models from openai are inherited.
Include selected models
Use includes to expose only selected models from the target provider.
{
"my-openai": {
"provider": "openai",
"includes": ["gpt-5.5", "gpt-5.4", "gpt-5.4-mini"]
}
}
includes also supports glob patterns and ! exclusions.
{
"my-openai": {
"provider": "openai",
"includes": ["gpt-5.*", "!gpt-5.4-nano"]
}
}
Rules are applied in two phases: first all positive entries select models, then ! entries remove matching models.
Model alias
Use models to map local model IDs to target models.
{
"foo": {
"models": {
"bar": "openai/gpt-5.5"
}
}
}
Then declare the local model under your OpenCode provider config.
{
"provider": {
"foo": {
"npm": "@ai-sdk/openai",
"name": "Foo",
"options": {
"apiKey": "{env:OPENAI_API_KEY}"
},
"models": {
"bar": {}
}
}
}
}
If provider is also set, model references may omit the provider prefix.
{
"foo": {
"provider": "openai",
"models": {
"bar": "gpt-5.5"
}
}
}
Behavior notes
- The plugin only modifies providers that already exist under OpenCode
providerconfig. - User-defined provider fields are preserved and merged over models.dev metadata.
- User-defined model fields are preserved and merged over hydrated model metadata.
- models.dev metadata is read from
~/.cache/opencode/models.jsonwhen available. If it is missing, the plugin fetcheshttps://models.dev/api.jsonand writes that cache file.
Development
bun install
bun run test
bun run build
Available scripts:
bun run build- build the ESM package with Rslib.bun run dev- run Rslib in watch mode.bun run test- run the Rstest suite.bun run check- run Biome checks and apply safe fixes.bun run format- format files with Biome.