opencode-plugin-litellm 0.1.1 โ 0.2.0
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 +82 -3
- package/package.json +1 -1
- package/src/plugin/config-hook.ts +5 -2
- package/src/plugin/enhance-config.ts +166 -36
- package/src/plugin/index.ts +16 -1
- package/src/types/index.ts +41 -0
- package/src/utils/format-model-name.ts +29 -0
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ That's it. No provider block required.
|
|
|
63
63
|
| ๐ก **Dynamic discovery** | Queries `/v1/models` so your OpenCode model picker always reflects your live `model_list`. |
|
|
64
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
65
|
| ๐ง **Modality-aware** | Infers `chat` / `embedding` / `image` / `audio` from the model `mode` field or id, and writes proper `modalities` metadata. |
|
|
66
|
+
| ๐งช **Reasoning-aware routing** | Auto-routes `gpt-5*` / `o1`/`o3`/`o4*` models through a sibling `litellm-responses` provider that uses `/v1/responses`, so tools + `reasoning_effort` actually work. Override per model via `responsesApiModels` / `chatApiModels`. |
|
|
66
67
|
| ๐ข **Provider extraction** | Pulls `litellm_provider` (or the `provider/model` prefix) into `organizationOwner` so models group correctly in the UI. |
|
|
67
68
|
| ๐ **Auth-aware** | Honours `LITELLM_API_KEY` / `LITELLM_MASTER_KEY` env vars or `provider.litellm.options.apiKey`. |
|
|
68
69
|
| โฑ๏ธ **Non-blocking startup** | Discovery is capped at **5 s** โ a slow or offline proxy never delays OpenCode boot. |
|
|
@@ -112,6 +113,53 @@ Override the URL, set an API key, or pre-define curated models that the plugin w
|
|
|
112
113
|
|
|
113
114
|
The plugin will **keep your hand-defined `openai/gpt-4o`** and only inject models it discovers that aren't already there.
|
|
114
115
|
|
|
116
|
+
### Reasoning models (gpt-5, o1/o3/o4)
|
|
117
|
+
|
|
118
|
+
OpenAI's reasoning-tier models reject requests that combine `reasoning_effort`
|
|
119
|
+
with function tools when sent to `/v1/chat/completions`. The OpenAI Responses
|
|
120
|
+
API (`/v1/responses`) has no such restriction, so the plugin routes those
|
|
121
|
+
models through a **second provider entry** named `litellm-responses` that
|
|
122
|
+
uses an SDK speaking the Responses API.
|
|
123
|
+
|
|
124
|
+
You don't need to do anything for the default behaviour โ the plugin
|
|
125
|
+
detects reasoning-tier models from their id (`gpt-5*`, `o1*`, `o3*`,
|
|
126
|
+
`o4*`) and from LiteLLM's `mode === 'responses'` field, and creates the
|
|
127
|
+
sibling provider lazily.
|
|
128
|
+
|
|
129
|
+
To override the routing per model:
|
|
130
|
+
|
|
131
|
+
```jsonc
|
|
132
|
+
{
|
|
133
|
+
"provider": {
|
|
134
|
+
"litellm": {
|
|
135
|
+
"options": {
|
|
136
|
+
"baseURL": "http://localhost:4000/v1",
|
|
137
|
+
|
|
138
|
+
// "auto" (default) | "chat" | "responses"
|
|
139
|
+
"transport": "auto",
|
|
140
|
+
|
|
141
|
+
// Force these into /v1/responses (highest precedence)
|
|
142
|
+
"responsesApiModels": ["gpt-5-4-high", "my-custom-reasoning-model"],
|
|
143
|
+
|
|
144
|
+
// Force these into /v1/chat/completions
|
|
145
|
+
"chatApiModels": ["o1-mini-cheap"]
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The two providers share `baseURL` and `apiKey`. Models curated by hand
|
|
153
|
+
under either provider's `models` block are preserved verbatim, and a
|
|
154
|
+
discovered model is skipped if its key already exists under **either**
|
|
155
|
+
provider.
|
|
156
|
+
|
|
157
|
+
> **Note**: this requires LiteLLM โฅ 1.40 (which proxies `/v1/responses`)
|
|
158
|
+
> and an `@ai-sdk/openai` version that supports the Responses API. Older
|
|
159
|
+
> AI SDKs may silently fall back to chat-completions, in which case set
|
|
160
|
+
> `responsesApiModels` to an empty list and fix the upstream LiteLLM
|
|
161
|
+
> config instead (e.g. `use_responses_api: true` per model).
|
|
162
|
+
|
|
115
163
|
### Authentication
|
|
116
164
|
|
|
117
165
|
If your LiteLLM proxy requires a master key, expose it via either approach:
|
|
@@ -143,7 +191,9 @@ sequenceDiagram
|
|
|
143
191
|
Plugin->>LL: GET /v1/models (with auth if set)
|
|
144
192
|
LL-->>Plugin: { data: [...models] }
|
|
145
193
|
Plugin->>Plugin: format names, infer modalities, extract owner
|
|
146
|
-
Plugin->>
|
|
194
|
+
Plugin->>Plugin: bucket each model by transport (chat vs responses)
|
|
195
|
+
Plugin->>OC: merge chat-completions models into provider.litellm
|
|
196
|
+
Plugin->>OC: merge responses models into provider.litellm-responses (lazy)
|
|
147
197
|
OC->>OC: render model picker with all discovered models
|
|
148
198
|
```
|
|
149
199
|
|
|
@@ -151,8 +201,9 @@ sequenceDiagram
|
|
|
151
201
|
2. If `provider.litellm` exists, its `baseURL` is used. Otherwise common ports are probed.
|
|
152
202
|
3. A health check (`GET /v1/models`) verifies the proxy is reachable and authorized.
|
|
153
203
|
4. Models from the response are converted into OpenCode model entries with `id`, formatted `name`, `organizationOwner`, and inferred `modalities`.
|
|
154
|
-
5.
|
|
155
|
-
6.
|
|
204
|
+
5. Each model is bucketed by transport โ reasoning-tier models (`gpt-5*`, `o1`/`o3`/`o4*`, or anything with `mode === 'responses'`) go into the `litellm-responses` provider; everything else goes into `litellm`. Per-model overrides via `responsesApiModels` / `chatApiModels` win.
|
|
205
|
+
6. Discovered models are merged on top of any user-defined ones โ never overwriting them. A model is skipped if its key already exists under **either** provider.
|
|
206
|
+
7. The whole flow is wrapped in a `Promise.race` against a 5 s timeout so a slow proxy never blocks boot.
|
|
156
207
|
|
|
157
208
|
## ๐ Requirements
|
|
158
209
|
|
|
@@ -210,6 +261,34 @@ The unscoped `opencode-litellm` was already published by another author when thi
|
|
|
210
261
|
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
262
|
</details>
|
|
212
263
|
|
|
264
|
+
<details>
|
|
265
|
+
<summary><b>I get <code>Function tools with reasoning_effort are not supported โฆ in /v1/chat/completions</code> โ what do I do?</b></summary>
|
|
266
|
+
|
|
267
|
+
This error comes from OpenAI: their reasoning-tier models (gpt-5, o1, o3, o4) refuse function-tool calls on `/v1/chat/completions` when `reasoning_effort` is set. They require `/v1/responses` instead.
|
|
268
|
+
|
|
269
|
+
As of `0.2.0`, `opencode-litellm` automatically routes those models through a sibling `litellm-responses` provider that uses the Responses API. If your model id doesn't match the heuristic (e.g. you renamed it in LiteLLM), add it explicitly:
|
|
270
|
+
|
|
271
|
+
```jsonc
|
|
272
|
+
"provider": {
|
|
273
|
+
"litellm": {
|
|
274
|
+
"options": {
|
|
275
|
+
"responsesApiModels": ["my-renamed-gpt-5-high"]
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
The model will appear under the **LiteLLM (responses)** provider in the picker; pick it from there and tool-calling will work.
|
|
282
|
+
</details>
|
|
283
|
+
|
|
284
|
+
<details>
|
|
285
|
+
<summary><b>Why are there suddenly two providers (<code>litellm</code> and <code>litellm-responses</code>) in the picker?</b></summary>
|
|
286
|
+
|
|
287
|
+
Same LiteLLM proxy, different transport. `litellm` talks to `/v1/chat/completions`; `litellm-responses` talks to `/v1/responses`. The split is required for OpenAI reasoning models โ see the FAQ entry above.
|
|
288
|
+
|
|
289
|
+
The responses provider is created lazily and only appears if at least one discovered model needs it. To collapse everything back into a single provider, set `"transport": "chat"` in `provider.litellm.options` (you'll lose tool-calling on reasoning models in exchange).
|
|
290
|
+
</details>
|
|
291
|
+
|
|
213
292
|
## ๐ ๏ธ Development
|
|
214
293
|
|
|
215
294
|
```bash
|
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.
|
|
4
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -27,11 +27,14 @@ export function createConfigHook() {
|
|
|
27
27
|
console.error('[opencode-litellm] Config enhancement failed:', error)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const chatCount = config?.provider?.litellm?.models
|
|
31
31
|
? Object.keys(config.provider.litellm.models).length
|
|
32
32
|
: 0
|
|
33
|
+
const responsesCount = config?.provider?.['litellm-responses']?.models
|
|
34
|
+
? Object.keys(config.provider['litellm-responses'].models).length
|
|
35
|
+
: 0
|
|
33
36
|
|
|
34
|
-
if (
|
|
37
|
+
if (chatCount + responsesCount === 0 && config?.provider?.litellm) {
|
|
35
38
|
console.warn('[opencode-litellm] No models loaded โ is LiteLLM reachable and is your model_list non-empty?')
|
|
36
39
|
}
|
|
37
40
|
}
|
|
@@ -4,10 +4,16 @@ import {
|
|
|
4
4
|
discoverLiteLLMModels,
|
|
5
5
|
normalizeBaseURL,
|
|
6
6
|
} from '../utils/litellm-api'
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
categorizeModel,
|
|
9
|
+
extractModelOwner,
|
|
10
|
+
formatModelName,
|
|
11
|
+
requiresResponsesAPI,
|
|
12
|
+
} from '../utils/format-model-name'
|
|
13
|
+
import type { LiteLLMModel, Transport, TransportPolicy } from '../types'
|
|
9
14
|
|
|
10
|
-
const
|
|
15
|
+
const CHAT_PROVIDER_KEY = 'litellm'
|
|
16
|
+
const RESPONSES_PROVIDER_KEY = 'litellm-responses'
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* Build the OpenCode model entry for a single discovered model.
|
|
@@ -50,34 +56,98 @@ function buildModelEntry(model: LiteLLMModel): Record<string, unknown> {
|
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
59
|
+
* Sanitize an id into a key OpenCode can parse. Most LiteLLM ids are
|
|
60
|
+
* already safe (`gpt-4o`, `anthropic/claude-3-5-sonnet`).
|
|
61
|
+
*/
|
|
62
|
+
function safeKey(id: string): string {
|
|
63
|
+
return /^[a-zA-Z0-9/_.\-:]+$/.test(id) ? id : id.replace(/[^a-zA-Z0-9_-]/g, '_')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Decide which transport bucket a model belongs to. Order of
|
|
68
|
+
* precedence (highest first):
|
|
69
|
+
*
|
|
70
|
+
* 1. Explicit allowlist `responsesApiModels` โ 'responses'
|
|
71
|
+
* 2. Explicit denylist `chatApiModels` โ 'chat'
|
|
72
|
+
* 3. Global policy `transport: 'chat' | 'responses'`
|
|
73
|
+
* 4. Heuristic via {@link requiresResponsesAPI} โ 'responses' or 'chat'
|
|
74
|
+
*/
|
|
75
|
+
function pickTransport(
|
|
76
|
+
model: LiteLLMModel,
|
|
77
|
+
policy: TransportPolicy,
|
|
78
|
+
responsesApiModels: ReadonlySet<string>,
|
|
79
|
+
chatApiModels: ReadonlySet<string>,
|
|
80
|
+
): Transport {
|
|
81
|
+
if (responsesApiModels.has(model.id)) return 'responses'
|
|
82
|
+
if (chatApiModels.has(model.id)) return 'chat'
|
|
83
|
+
if (policy === 'chat') return 'chat'
|
|
84
|
+
if (policy === 'responses') return 'responses'
|
|
85
|
+
return requiresResponsesAPI(model) ? 'responses' : 'chat'
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Ensure a provider entry exists on `config.provider[key]` and return
|
|
90
|
+
* it. If we created it just now, `created` is true so callers can log
|
|
91
|
+
* one-time messages.
|
|
92
|
+
*/
|
|
93
|
+
function ensureProvider(
|
|
94
|
+
config: any,
|
|
95
|
+
key: string,
|
|
96
|
+
defaults: () => Record<string, unknown>,
|
|
97
|
+
): { provider: any; created: boolean } {
|
|
98
|
+
if (config.provider[key]) {
|
|
99
|
+
return { provider: config.provider[key], created: false }
|
|
100
|
+
}
|
|
101
|
+
const provider = defaults()
|
|
102
|
+
config.provider[key] = provider
|
|
103
|
+
return { provider, created: true }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Mutates `config` in place: ensures the litellm provider(s) exist,
|
|
108
|
+
* fetches all models from the LiteLLM proxy, and merges them into the
|
|
109
|
+
* appropriate transport bucket (`litellm` for /v1/chat/completions,
|
|
110
|
+
* `litellm-responses` for /v1/responses).
|
|
55
111
|
*/
|
|
56
112
|
export async function enhanceConfig(config: any): Promise<void> {
|
|
57
113
|
if (!config) return
|
|
58
114
|
|
|
59
115
|
if (!config.provider) config.provider = {}
|
|
60
|
-
let
|
|
116
|
+
let chatProvider = config.provider[CHAT_PROVIDER_KEY]
|
|
61
117
|
|
|
62
|
-
// Resolve baseURL & apiKey, either from the user's provider
|
|
63
|
-
// or by auto-detecting a running LiteLLM proxy.
|
|
118
|
+
// Resolve baseURL & apiKey, either from the user's primary provider
|
|
119
|
+
// config or by auto-detecting a running LiteLLM proxy.
|
|
64
120
|
let baseURL: string
|
|
65
121
|
let apiKey: string | undefined
|
|
66
122
|
|
|
67
|
-
if (
|
|
68
|
-
baseURL = normalizeBaseURL(
|
|
69
|
-
apiKey =
|
|
123
|
+
if (chatProvider) {
|
|
124
|
+
baseURL = normalizeBaseURL(chatProvider.options?.baseURL ?? 'http://localhost:4000')
|
|
125
|
+
apiKey =
|
|
126
|
+
chatProvider.options?.apiKey ??
|
|
127
|
+
process.env.LITELLM_API_KEY ??
|
|
128
|
+
process.env.LITELLM_MASTER_KEY
|
|
70
129
|
} else {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
130
|
+
// Allow the user to pre-define ONLY the responses provider; in that
|
|
131
|
+
// case we still need to know the baseURL/apiKey for discovery.
|
|
132
|
+
const preDefinedResponses = config.provider[RESPONSES_PROVIDER_KEY]
|
|
133
|
+
if (preDefinedResponses) {
|
|
134
|
+
baseURL = normalizeBaseURL(preDefinedResponses.options?.baseURL ?? 'http://localhost:4000')
|
|
135
|
+
apiKey =
|
|
136
|
+
preDefinedResponses.options?.apiKey ??
|
|
137
|
+
process.env.LITELLM_API_KEY ??
|
|
138
|
+
process.env.LITELLM_MASTER_KEY
|
|
139
|
+
} else {
|
|
140
|
+
const detected = await autoDetectLiteLLM()
|
|
141
|
+
if (!detected) {
|
|
142
|
+
// Nothing to do โ LiteLLM doesn't appear to be running anywhere
|
|
143
|
+
// we know about. Silently bail; this is the no-op case.
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
baseURL = normalizeBaseURL(detected)
|
|
147
|
+
apiKey = process.env.LITELLM_API_KEY ?? process.env.LITELLM_MASTER_KEY
|
|
76
148
|
}
|
|
77
|
-
baseURL = normalizeBaseURL(detected)
|
|
78
|
-
apiKey = process.env.LITELLM_API_KEY ?? process.env.LITELLM_MASTER_KEY
|
|
79
149
|
|
|
80
|
-
|
|
150
|
+
chatProvider = {
|
|
81
151
|
npm: '@ai-sdk/openai-compatible',
|
|
82
152
|
name: 'LiteLLM (proxy)',
|
|
83
153
|
options: {
|
|
@@ -86,7 +156,7 @@ export async function enhanceConfig(config: any): Promise<void> {
|
|
|
86
156
|
},
|
|
87
157
|
models: {},
|
|
88
158
|
}
|
|
89
|
-
config.provider[
|
|
159
|
+
config.provider[CHAT_PROVIDER_KEY] = chatProvider
|
|
90
160
|
}
|
|
91
161
|
|
|
92
162
|
// Verify the server is actually answering before we hammer /v1/models.
|
|
@@ -99,32 +169,92 @@ export async function enhanceConfig(config: any): Promise<void> {
|
|
|
99
169
|
try {
|
|
100
170
|
models = await discoverLiteLLMModels(baseURL, apiKey)
|
|
101
171
|
} catch (error) {
|
|
102
|
-
console.warn(
|
|
172
|
+
console.warn(
|
|
173
|
+
'[opencode-litellm] Model discovery failed:',
|
|
174
|
+
error instanceof Error ? error.message : String(error),
|
|
175
|
+
)
|
|
103
176
|
return
|
|
104
177
|
}
|
|
105
178
|
|
|
106
179
|
if (models.length === 0) {
|
|
107
|
-
console.warn(
|
|
180
|
+
console.warn(
|
|
181
|
+
'[opencode-litellm] LiteLLM responded but exposed zero models. Check your `model_list` in litellm config.yaml',
|
|
182
|
+
)
|
|
108
183
|
return
|
|
109
184
|
}
|
|
110
185
|
|
|
111
|
-
|
|
112
|
-
const
|
|
186
|
+
// Read the routing policy + per-model overrides from the chat provider's options.
|
|
187
|
+
const policy: TransportPolicy =
|
|
188
|
+
(chatProvider.options?.transport as TransportPolicy | undefined) ?? 'auto'
|
|
189
|
+
const responsesApiModels = new Set<string>(
|
|
190
|
+
Array.isArray(chatProvider.options?.responsesApiModels)
|
|
191
|
+
? chatProvider.options.responsesApiModels
|
|
192
|
+
: [],
|
|
193
|
+
)
|
|
194
|
+
const chatApiModels = new Set<string>(
|
|
195
|
+
Array.isArray(chatProvider.options?.chatApiModels) ? chatProvider.options.chatApiModels : [],
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
// First pass: bucket every discovered model by transport.
|
|
199
|
+
const chatBucket: Record<string, any> = {}
|
|
200
|
+
const responsesBucket: Record<string, any> = {}
|
|
113
201
|
|
|
114
202
|
for (const model of models) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
discovered[key] = buildModelEntry(model)
|
|
203
|
+
const key = safeKey(model.id)
|
|
204
|
+
const entry = buildModelEntry(model)
|
|
205
|
+
const transport = pickTransport(model, policy, responsesApiModels, chatApiModels)
|
|
206
|
+
if (transport === 'responses') {
|
|
207
|
+
responsesBucket[key] = entry
|
|
208
|
+
} else {
|
|
209
|
+
chatBucket[key] = entry
|
|
210
|
+
}
|
|
124
211
|
}
|
|
125
212
|
|
|
126
|
-
|
|
213
|
+
// Lazily create the responses provider only when we actually have
|
|
214
|
+
// something to put in it (or the user already declared one).
|
|
215
|
+
let responsesProvider: any | undefined = config.provider[RESPONSES_PROVIDER_KEY]
|
|
216
|
+
if (!responsesProvider && Object.keys(responsesBucket).length > 0) {
|
|
217
|
+
responsesProvider = {
|
|
218
|
+
npm: '@ai-sdk/openai',
|
|
219
|
+
name: 'LiteLLM (responses)',
|
|
220
|
+
options: {
|
|
221
|
+
baseURL: `${baseURL}/v1`,
|
|
222
|
+
...(apiKey ? { apiKey } : {}),
|
|
223
|
+
// Help the AI SDK route to /v1/responses for reasoning models
|
|
224
|
+
// when the upstream supports it.
|
|
225
|
+
compatibility: 'strict',
|
|
226
|
+
},
|
|
227
|
+
models: {},
|
|
228
|
+
}
|
|
229
|
+
config.provider[RESPONSES_PROVIDER_KEY] = responsesProvider
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Non-destructive merge into each provider. A key is considered
|
|
233
|
+
// "already present" if it exists under EITHER provider, so the user's
|
|
234
|
+
// hand-curated entry wins regardless of which bucket we'd have chosen.
|
|
235
|
+
const mergeIntoProvider = (
|
|
236
|
+
provider: any,
|
|
237
|
+
bucket: Record<string, any>,
|
|
238
|
+
bucketLabel: string,
|
|
239
|
+
): number => {
|
|
240
|
+
if (!provider) return 0
|
|
241
|
+
const existingHere: Record<string, any> = provider.models ?? {}
|
|
242
|
+
const existingChat: Record<string, any> = chatProvider.models ?? {}
|
|
243
|
+
const existingResp: Record<string, any> = responsesProvider?.models ?? {}
|
|
244
|
+
const additions: Record<string, any> = {}
|
|
245
|
+
for (const [key, entry] of Object.entries(bucket)) {
|
|
246
|
+
if (existingHere[key]) continue
|
|
247
|
+
if (existingChat[key] || existingResp[key]) continue
|
|
248
|
+
additions[key] = entry
|
|
249
|
+
}
|
|
250
|
+
if (Object.keys(additions).length === 0) return 0
|
|
251
|
+
provider.models = { ...existingHere, ...additions }
|
|
252
|
+
console.log(
|
|
253
|
+
`[opencode-litellm] Discovered ${Object.keys(additions).length} ${bucketLabel} model(s) from LiteLLM at ${baseURL}`,
|
|
254
|
+
)
|
|
255
|
+
return Object.keys(additions).length
|
|
256
|
+
}
|
|
127
257
|
|
|
128
|
-
|
|
129
|
-
|
|
258
|
+
mergeIntoProvider(chatProvider, chatBucket, 'chat-completions')
|
|
259
|
+
mergeIntoProvider(responsesProvider, responsesBucket, 'responses-API')
|
|
130
260
|
}
|
package/src/plugin/index.ts
CHANGED
|
@@ -8,6 +8,16 @@ import { createConfigHook } from './config-hook'
|
|
|
8
8
|
* the full `model_list` out of `/v1/models` so you don't have to
|
|
9
9
|
* hand-maintain models in `opencode.json`.
|
|
10
10
|
*
|
|
11
|
+
* Discovered models are split into two providers based on the transport
|
|
12
|
+
* required by the upstream model:
|
|
13
|
+
*
|
|
14
|
+
* - `litellm` โ /v1/chat/completions (most models)
|
|
15
|
+
* - `litellm-responses` โ /v1/responses (gpt-5*, o-series with reasoning)
|
|
16
|
+
*
|
|
17
|
+
* The split is necessary because reasoning-tier OpenAI models reject
|
|
18
|
+
* requests that combine `reasoning_effort` with function tools when sent
|
|
19
|
+
* to chat-completions.
|
|
20
|
+
*
|
|
11
21
|
* Configure (optional):
|
|
12
22
|
*
|
|
13
23
|
* {
|
|
@@ -18,7 +28,12 @@ import { createConfigHook } from './config-hook'
|
|
|
18
28
|
* "name": "LiteLLM (proxy)",
|
|
19
29
|
* "options": {
|
|
20
30
|
* "baseURL": "http://localhost:4000/v1",
|
|
21
|
-
* "apiKey": "{env:LITELLM_API_KEY}"
|
|
31
|
+
* "apiKey": "{env:LITELLM_API_KEY}",
|
|
32
|
+
*
|
|
33
|
+
* // Optional routing controls (added in 0.2.0):
|
|
34
|
+
* "transport": "auto", // "auto" | "chat" | "responses"
|
|
35
|
+
* "responsesApiModels": ["gpt-5-4-high"], // force into /v1/responses
|
|
36
|
+
* "chatApiModels": ["o1-mini"] // force into /v1/chat/completions
|
|
22
37
|
* }
|
|
23
38
|
* }
|
|
24
39
|
* }
|
package/src/types/index.ts
CHANGED
|
@@ -18,6 +18,10 @@ export interface LiteLLMModel {
|
|
|
18
18
|
* Optional capability metadata exposed by some LiteLLM versions
|
|
19
19
|
* via `/model/info` (we ignore it for the lean discovery endpoint
|
|
20
20
|
* but keep the type around for forward-compat).
|
|
21
|
+
*
|
|
22
|
+
* Newer LiteLLM versions may expose `'responses'` here for models
|
|
23
|
+
* that must be routed through the OpenAI Responses API rather than
|
|
24
|
+
* `/v1/chat/completions` (e.g. `gpt-5*`, `o1/o3/o4*` with reasoning).
|
|
21
25
|
*/
|
|
22
26
|
mode?: string
|
|
23
27
|
max_tokens?: number
|
|
@@ -34,7 +38,44 @@ export interface LiteLLMModelsResponse {
|
|
|
34
38
|
|
|
35
39
|
export type ModelType = 'chat' | 'embedding' | 'image' | 'audio' | 'unknown'
|
|
36
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Which OpenAI-compatible HTTP surface a model should be invoked through.
|
|
43
|
+
*
|
|
44
|
+
* - `chat` โ `/v1/chat/completions` (most models)
|
|
45
|
+
* - `responses` โ `/v1/responses` (gpt-5*, o-series with reasoning)
|
|
46
|
+
*/
|
|
47
|
+
export type Transport = 'chat' | 'responses'
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* User-facing routing override. Defaults to `'auto'`.
|
|
51
|
+
*
|
|
52
|
+
* - `'auto'` โ use the heuristic + LiteLLM `mode` field
|
|
53
|
+
* - `'chat'` โ force every discovered model into the chat-completions provider
|
|
54
|
+
* - `'responses'` โ force every discovered model into the responses provider
|
|
55
|
+
*/
|
|
56
|
+
export type TransportPolicy = 'auto' | Transport
|
|
57
|
+
|
|
37
58
|
export interface LiteLLMOptions {
|
|
38
59
|
baseURL?: string
|
|
39
60
|
apiKey?: string
|
|
61
|
+
/**
|
|
62
|
+
* Routing policy for discovered models. See {@link TransportPolicy}.
|
|
63
|
+
* Defaults to `'auto'`.
|
|
64
|
+
*/
|
|
65
|
+
transport?: TransportPolicy
|
|
66
|
+
/**
|
|
67
|
+
* Explicit allowlist of model ids that MUST be routed through the
|
|
68
|
+
* OpenAI Responses API (`/v1/responses`). Takes priority over the
|
|
69
|
+
* heuristic and over the `transport` policy.
|
|
70
|
+
*
|
|
71
|
+
* Match is exact against the LiteLLM model id (e.g. `"gpt-5-4-high"`).
|
|
72
|
+
*/
|
|
73
|
+
responsesApiModels?: string[]
|
|
74
|
+
/**
|
|
75
|
+
* Explicit denylist of model ids that MUST be routed through chat
|
|
76
|
+
* completions (`/v1/chat/completions`), even if the heuristic would
|
|
77
|
+
* otherwise put them in the responses bucket. Takes priority over
|
|
78
|
+
* the heuristic but is overridden by `responsesApiModels`.
|
|
79
|
+
*/
|
|
80
|
+
chatApiModels?: string[]
|
|
40
81
|
}
|
|
@@ -83,3 +83,32 @@ export function formatModelName(model: LiteLLMModel): string {
|
|
|
83
83
|
|
|
84
84
|
return tokens || id
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Decide whether a model must be invoked through the OpenAI Responses
|
|
89
|
+
* API (`/v1/responses`) instead of `/v1/chat/completions`.
|
|
90
|
+
*
|
|
91
|
+
* OpenAI's reasoning-tier models (gpt-5*, o1/o3/o4*) reject requests
|
|
92
|
+
* that combine `reasoning_effort` with function tools when sent to
|
|
93
|
+
* `/v1/chat/completions`. The Responses API has no such restriction,
|
|
94
|
+
* so we route those models there.
|
|
95
|
+
*
|
|
96
|
+
* Detection rules (first match wins):
|
|
97
|
+
* 1. `model.mode === 'responses'` (LiteLLM exposes this on newer versions)
|
|
98
|
+
* 2. The model id (after any `provider/` prefix) matches the
|
|
99
|
+
* `gpt-5*` / `o[134]*` family.
|
|
100
|
+
*/
|
|
101
|
+
export function requiresResponsesAPI(model: LiteLLMModel): boolean {
|
|
102
|
+
if (model.mode && model.mode.toLowerCase() === 'responses') return true
|
|
103
|
+
|
|
104
|
+
const id = model.id.toLowerCase()
|
|
105
|
+
const slashIdx = id.indexOf('/')
|
|
106
|
+
const tail = slashIdx >= 0 ? id.slice(slashIdx + 1) : id
|
|
107
|
+
|
|
108
|
+
// gpt-5, gpt-5.4, gpt-5-4-high, gpt-5o, ...
|
|
109
|
+
if (/^gpt-?5(?:[-.].*)?$/.test(tail)) return true
|
|
110
|
+
// o1, o1-mini, o3, o3-mini, o4-mini, o4, ... but NOT "openai", "ollama"
|
|
111
|
+
if (/^o[134](?:[-.].*)?$/.test(tail)) return true
|
|
112
|
+
|
|
113
|
+
return false
|
|
114
|
+
}
|