opencode-plugin-litellm 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,40 +1,80 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# opencode-litellm
|
|
2
4
|
|
|
3
|
-
[
|
|
4
|
-
|
|
5
|
-
[ provider for [OpenCode](https://opencode.ai) with zero configuration.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/opencode-plugin-litellm)
|
|
8
|
+
[](https://www.npmjs.com/package/opencode-plugin-litellm)
|
|
9
|
+
[](https://github.com/yuseferi/opencode-litellm/actions/workflows/ci.yml)
|
|
10
|
+
[](./LICENSE)
|
|
11
|
+
[](./tsconfig.json)
|
|
12
|
+
[](./CONTRIBUTING.md)
|
|
13
|
+
|
|
14
|
+
Auto-detect a running LiteLLM proxy, pull every model from `/v1/models`, and register them in OpenCode.
|
|
15
|
+
**No model lists to hand-maintain. No restart loops. No surprises.**
|
|
16
|
+
|
|
17
|
+
[Quickstart](#-quickstart) · [Configuration](#%EF%B8%8F-configuration) · [How it works](#-how-it-works) · [FAQ](#-faq) · [Contributing](./CONTRIBUTING.md)
|
|
6
18
|
|
|
7
|
-
|
|
8
|
-
with **auto-detection** and **dynamic model discovery**.
|
|
19
|
+
</div>
|
|
9
20
|
|
|
10
|
-
|
|
21
|
+
> **npm package:** `opencode-plugin-litellm` · **GitHub repo:** `yuseferi/opencode-litellm`
|
|
22
|
+
> The unscoped `opencode-litellm` npm name was already taken by another author.
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
> name was taken on npm). Repo name and plugin export remain `opencode-litellm`.
|
|
24
|
+
---
|
|
14
25
|
|
|
15
|
-
##
|
|
26
|
+
## ✨ Why this plugin?
|
|
16
27
|
|
|
17
|
-
|
|
18
|
-
- **Dynamic model discovery** — queries `/v1/models` so you never hand-maintain a model list
|
|
19
|
-
- **OpenAI-compatible** — registers under OpenCode as `@ai-sdk/openai-compatible`
|
|
20
|
-
- **Vendor-aware** — extracts `litellm_provider` (or the `provider/model` prefix) into `organizationOwner`
|
|
21
|
-
- **Smart formatting** — turns `anthropic/claude-3-5-sonnet` into `Claude 3 5 Sonnet` in the picker
|
|
22
|
-
- **Categorization** — chat / embedding / image / audio modalities are inferred from the model `mode` or id
|
|
23
|
-
- **Non-blocking** — discovery is capped at 5s so a slow proxy never blocks OpenCode startup
|
|
28
|
+
Maintaining a `models` block in `opencode.json` for every model your LiteLLM proxy exposes is a chore — every new entry in your `model_list` means a config edit, a restart, and a context-switch.
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
`opencode-litellm` removes that loop entirely. It hooks into OpenCode's `config` lifecycle, queries your LiteLLM proxy at startup, and merges the discovered models into your config in memory. The result: every model in `litellm config.yaml` shows up in OpenCode's picker the moment you start it — automatically.
|
|
31
|
+
|
|
32
|
+
## 🚀 Quickstart
|
|
26
33
|
|
|
27
34
|
```bash
|
|
35
|
+
# 1. Install
|
|
28
36
|
npm install opencode-plugin-litellm
|
|
29
|
-
# or
|
|
30
|
-
|
|
37
|
+
# or: bun add opencode-plugin-litellm
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```jsonc
|
|
41
|
+
// 2. Add to opencode.json
|
|
42
|
+
{
|
|
43
|
+
"$schema": "https://opencode.ai/config.json",
|
|
44
|
+
"plugin": ["opencode-plugin-litellm@latest"]
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 3. Start LiteLLM (if it isn't already)
|
|
50
|
+
litellm --config config.yaml --port 4000
|
|
51
|
+
|
|
52
|
+
# 4. Run OpenCode — every model in your LiteLLM model_list is now available.
|
|
53
|
+
opencode
|
|
31
54
|
```
|
|
32
55
|
|
|
33
|
-
|
|
56
|
+
That's it. No provider block required.
|
|
57
|
+
|
|
58
|
+
## 🎯 Features
|
|
59
|
+
|
|
60
|
+
| | |
|
|
61
|
+
|---|---|
|
|
62
|
+
| 🔍 **Auto-detection** | Probes `localhost:4000`, `:8000`, `:8080` and adopts the first responsive proxy. |
|
|
63
|
+
| 📡 **Dynamic discovery** | Queries `/v1/models` so your OpenCode model picker always reflects your live `model_list`. |
|
|
64
|
+
| 🏷️ **Smart formatting** | Turns `anthropic/claude-3-5-sonnet` into `Claude 3 5 Sonnet` in the picker — handles versions, sizes, quantizations, and brand-cased names like `gpt-4o`. |
|
|
65
|
+
| 🧠 **Modality-aware** | Infers `chat` / `embedding` / `image` / `audio` from the model `mode` field or id, and writes proper `modalities` metadata. |
|
|
66
|
+
| 🏢 **Provider extraction** | Pulls `litellm_provider` (or the `provider/model` prefix) into `organizationOwner` so models group correctly in the UI. |
|
|
67
|
+
| 🔐 **Auth-aware** | Honours `LITELLM_API_KEY` / `LITELLM_MASTER_KEY` env vars or `provider.litellm.options.apiKey`. |
|
|
68
|
+
| ⏱️ **Non-blocking startup** | Discovery is capped at **5 s** — a slow or offline proxy never delays OpenCode boot. |
|
|
69
|
+
| 🤝 **Non-destructive merge** | Only adds models you don't already have configured. Hand-curated entries are preserved verbatim. |
|
|
70
|
+
| 🪶 **Zero runtime deps** | Only depends on `@opencode-ai/plugin`. No build step, no bundler. |
|
|
71
|
+
| 🔒 **TypeScript strict** | Strict-mode compiled, fully typed public API. |
|
|
72
|
+
|
|
73
|
+
## ⚙️ Configuration
|
|
34
74
|
|
|
35
75
|
### Zero-config (recommended)
|
|
36
76
|
|
|
37
|
-
If
|
|
77
|
+
If LiteLLM is on `localhost:4000`, `:8000`, or `:8080`, the plugin self-configures:
|
|
38
78
|
|
|
39
79
|
```json
|
|
40
80
|
{
|
|
@@ -43,12 +83,11 @@ If a LiteLLM proxy is already running on `localhost:4000`, just add the plugin:
|
|
|
43
83
|
}
|
|
44
84
|
```
|
|
45
85
|
|
|
46
|
-
|
|
47
|
-
your provider list automatically.
|
|
86
|
+
### Explicit provider
|
|
48
87
|
|
|
49
|
-
|
|
88
|
+
Override the URL, set an API key, or pre-define curated models that the plugin will preserve:
|
|
50
89
|
|
|
51
|
-
```
|
|
90
|
+
```jsonc
|
|
52
91
|
{
|
|
53
92
|
"$schema": "https://opencode.ai/config.json",
|
|
54
93
|
"plugin": ["opencode-plugin-litellm@latest"],
|
|
@@ -57,39 +96,170 @@ your provider list automatically.
|
|
|
57
96
|
"npm": "@ai-sdk/openai-compatible",
|
|
58
97
|
"name": "LiteLLM (proxy)",
|
|
59
98
|
"options": {
|
|
60
|
-
"baseURL": "http://
|
|
99
|
+
"baseURL": "http://litellm.internal.example.com/v1",
|
|
61
100
|
"apiKey": "{env:LITELLM_API_KEY}"
|
|
101
|
+
},
|
|
102
|
+
"models": {
|
|
103
|
+
"openai/gpt-4o": {
|
|
104
|
+
"name": "GPT-4o (curated)",
|
|
105
|
+
"organizationOwner": "openai"
|
|
106
|
+
}
|
|
62
107
|
}
|
|
63
108
|
}
|
|
64
109
|
}
|
|
65
110
|
}
|
|
66
111
|
```
|
|
67
112
|
|
|
68
|
-
|
|
69
|
-
plugin only adds models it discovers that aren't already configured.
|
|
113
|
+
The plugin will **keep your hand-defined `openai/gpt-4o`** and only inject models it discovers that aren't already there.
|
|
70
114
|
|
|
71
115
|
### Authentication
|
|
72
116
|
|
|
73
|
-
If your LiteLLM proxy requires a master key, expose it via either:
|
|
117
|
+
If your LiteLLM proxy requires a master key, expose it via either approach:
|
|
118
|
+
|
|
119
|
+
| Method | Example |
|
|
120
|
+
|---|---|
|
|
121
|
+
| Env var | `export LITELLM_API_KEY=sk-...` |
|
|
122
|
+
| Env var (alias) | `export LITELLM_MASTER_KEY=sk-...` |
|
|
123
|
+
| Config | `"options": { "apiKey": "{env:LITELLM_API_KEY}" }` |
|
|
124
|
+
|
|
125
|
+
The env var path lets you commit `opencode.json` without leaking secrets.
|
|
126
|
+
|
|
127
|
+
## 🔧 How it works
|
|
128
|
+
|
|
129
|
+
```mermaid
|
|
130
|
+
sequenceDiagram
|
|
131
|
+
participant OC as OpenCode
|
|
132
|
+
participant Plugin as opencode-litellm
|
|
133
|
+
participant LL as LiteLLM proxy
|
|
134
|
+
|
|
135
|
+
OC->>Plugin: config(initial)
|
|
136
|
+
alt provider.litellm configured
|
|
137
|
+
Plugin->>LL: GET /v1/models @ baseURL
|
|
138
|
+
else not configured
|
|
139
|
+
Plugin->>LL: probe :4000, :8000, :8080
|
|
140
|
+
LL-->>Plugin: 200 OK on one
|
|
141
|
+
Plugin->>Plugin: auto-create provider entry
|
|
142
|
+
end
|
|
143
|
+
Plugin->>LL: GET /v1/models (with auth if set)
|
|
144
|
+
LL-->>Plugin: { data: [...models] }
|
|
145
|
+
Plugin->>Plugin: format names, infer modalities, extract owner
|
|
146
|
+
Plugin->>OC: merge into config (non-destructive)
|
|
147
|
+
OC->>OC: render model picker with all discovered models
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
1. On OpenCode startup the `config` lifecycle hook fires.
|
|
151
|
+
2. If `provider.litellm` exists, its `baseURL` is used. Otherwise common ports are probed.
|
|
152
|
+
3. A health check (`GET /v1/models`) verifies the proxy is reachable and authorized.
|
|
153
|
+
4. Models from the response are converted into OpenCode model entries with `id`, formatted `name`, `organizationOwner`, and inferred `modalities`.
|
|
154
|
+
5. Discovered models are merged on top of any user-defined ones — never overwriting them.
|
|
155
|
+
6. The whole flow is wrapped in a `Promise.race` against a 5 s timeout so a slow proxy never blocks boot.
|
|
156
|
+
|
|
157
|
+
## 📋 Requirements
|
|
158
|
+
|
|
159
|
+
- [OpenCode](https://opencode.ai) ≥ 0.1.x with plugin support (`@opencode-ai/plugin ^1.0.166`)
|
|
160
|
+
- A running [LiteLLM](https://github.com/BerriAI/litellm) proxy:
|
|
161
|
+
```bash
|
|
162
|
+
pip install 'litellm[proxy]'
|
|
163
|
+
litellm --config config.yaml --port 4000
|
|
164
|
+
```
|
|
165
|
+
- Node.js ≥ 20 (or Bun ≥ 1.0)
|
|
166
|
+
|
|
167
|
+
## 📦 Compatibility matrix
|
|
168
|
+
|
|
169
|
+
| LiteLLM version | OpenCode version | Status |
|
|
170
|
+
|---|---|---|
|
|
171
|
+
| ≥ 1.40 | ≥ 0.1.x | ✅ Tested |
|
|
172
|
+
| 1.30 – 1.39 | ≥ 0.1.x | ⚠️ Should work (older `/v1/models` schema) |
|
|
173
|
+
| < 1.30 | any | ❌ Unsupported |
|
|
174
|
+
|
|
175
|
+
## ❓ FAQ
|
|
176
|
+
|
|
177
|
+
<details>
|
|
178
|
+
<summary><b>Why doesn't a model appear in OpenCode after I add it to LiteLLM?</b></summary>
|
|
179
|
+
|
|
180
|
+
OpenCode reads the plugin output once at startup. After updating `litellm config.yaml`, restart **both** LiteLLM and OpenCode to refresh the model list.
|
|
181
|
+
</details>
|
|
182
|
+
|
|
183
|
+
<details>
|
|
184
|
+
<summary><b>Can I use this with a remote LiteLLM proxy?</b></summary>
|
|
185
|
+
|
|
186
|
+
Yes. Set `provider.litellm.options.baseURL` to your remote URL and (optionally) `apiKey`. Auto-detection only probes `localhost`, but explicit configuration works against any URL.
|
|
187
|
+
</details>
|
|
188
|
+
|
|
189
|
+
<details>
|
|
190
|
+
<summary><b>What happens if LiteLLM is offline at startup?</b></summary>
|
|
191
|
+
|
|
192
|
+
The plugin logs a warning and is a no-op. OpenCode starts normally; you just won't see LiteLLM-discovered models until you restart with the proxy up.
|
|
193
|
+
</details>
|
|
194
|
+
|
|
195
|
+
<details>
|
|
196
|
+
<summary><b>Will my hand-curated model entries be overwritten?</b></summary>
|
|
197
|
+
|
|
198
|
+
No. The merge is additive: anything you've already defined under `provider.litellm.models` is preserved exactly as-is. Discovered models are only added if their key isn't already present.
|
|
199
|
+
</details>
|
|
200
|
+
|
|
201
|
+
<details>
|
|
202
|
+
<summary><b>Why is the npm name <code>opencode-plugin-litellm</code> and not <code>opencode-litellm</code>?</b></summary>
|
|
203
|
+
|
|
204
|
+
The unscoped `opencode-litellm` was already published by another author when this project was started. The GitHub repo and exported plugin symbol still use the cleaner `opencode-litellm` name.
|
|
205
|
+
</details>
|
|
206
|
+
|
|
207
|
+
<details>
|
|
208
|
+
<summary><b>Does this work with Ollama through LiteLLM?</b></summary>
|
|
209
|
+
|
|
210
|
+
Yes — anything in your LiteLLM `model_list` shows up, including Ollama, Bedrock, Azure, OpenAI, Anthropic, Google, etc. That's the whole point of LiteLLM.
|
|
211
|
+
</details>
|
|
212
|
+
|
|
213
|
+
## 🛠️ Development
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
git clone https://github.com/yuseferi/opencode-litellm.git
|
|
217
|
+
cd opencode-litellm
|
|
218
|
+
npm install
|
|
219
|
+
npm run typecheck
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The project is intentionally tiny:
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
src/
|
|
226
|
+
├── index.ts # Public exports
|
|
227
|
+
├── types/index.ts # LiteLLM API types
|
|
228
|
+
├── utils/
|
|
229
|
+
│ ├── litellm-api.ts # health check, discovery, auto-detect
|
|
230
|
+
│ └── format-model-name.ts # owner extraction, name formatting, categorization
|
|
231
|
+
└── plugin/
|
|
232
|
+
├── index.ts # LiteLLMPlugin entry
|
|
233
|
+
├── config-hook.ts # OpenCode config-lifecycle hook (5 s timeout)
|
|
234
|
+
└── enhance-config.ts # core merge logic
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
See [`CONTRIBUTING.md`](./CONTRIBUTING.md) for the full contributor workflow.
|
|
238
|
+
|
|
239
|
+
## 🗺️ Roadmap
|
|
240
|
+
|
|
241
|
+
- [ ] Optional cost/latency overlay using LiteLLM's `/spend` and `/health` endpoints
|
|
242
|
+
- [ ] In-memory cache with TTL to avoid re-querying on rapid restarts
|
|
243
|
+
- [ ] Model categorization based on `litellm.proxy.config.model_list[].model_info`
|
|
244
|
+
- [ ] Tests with [vitest](https://vitest.dev/)
|
|
245
|
+
- [ ] `chat.params` hook for injecting LiteLLM routing tags / fallbacks
|
|
246
|
+
|
|
247
|
+
Have an idea? [Open an issue](https://github.com/yuseferi/opencode-litellm/issues/new).
|
|
248
|
+
|
|
249
|
+
## 🙏 Acknowledgements
|
|
250
|
+
|
|
251
|
+
Inspired by [`opencode-lmstudio`](https://github.com/agustif/opencode-lmstudio) by [@agustif](https://github.com/agustif) — the architectural blueprint for OpenCode model-discovery plugins.
|
|
74
252
|
|
|
75
|
-
|
|
76
|
-
- the `LITELLM_API_KEY` (or `LITELLM_MASTER_KEY`) environment variable.
|
|
253
|
+
Built on top of [LiteLLM](https://github.com/BerriAI/litellm) by the [BerriAI](https://github.com/BerriAI) team and [OpenCode](https://opencode.ai) by the OpenCode contributors.
|
|
77
254
|
|
|
78
|
-
##
|
|
255
|
+
## 📄 License
|
|
79
256
|
|
|
80
|
-
|
|
81
|
-
2. If a `litellm` provider is configured, its `baseURL` is used. Otherwise the
|
|
82
|
-
plugin probes `localhost:4000`, `:8000`, `:8080`.
|
|
83
|
-
3. Health check via `GET /v1/models`. If unreachable, the hook is a no-op.
|
|
84
|
-
4. Models from `/v1/models` are turned into OpenCode model entries with
|
|
85
|
-
sensible `name`, `organizationOwner`, and `modalities` fields.
|
|
86
|
-
5. Discovered models are merged on top of any user-configured ones.
|
|
257
|
+
[MIT](./LICENSE) © [Yusef Mohamadi](https://github.com/yuseferi)
|
|
87
258
|
|
|
88
|
-
|
|
259
|
+
---
|
|
89
260
|
|
|
90
|
-
|
|
91
|
-
- A running LiteLLM proxy (`pip install 'litellm[proxy]' && litellm --config config.yaml`)
|
|
261
|
+
<div align="center">
|
|
92
262
|
|
|
93
|
-
|
|
263
|
+
If this project saved you time, consider giving it a ⭐ on [GitHub](https://github.com/yuseferi/opencode-litellm).
|
|
94
264
|
|
|
95
|
-
|
|
265
|
+
</div>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "opencode-plugin-litellm",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"description": "OpenCode plugin for LiteLLM proxy support with auto-detection and dynamic model discovery",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.ts",
|