opencode-plugin-litellm 0.7.1 → 0.9.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 CHANGED
@@ -194,6 +194,13 @@ detects reasoning-tier models from their id (`gpt-5*`, `o1*`, `o3*`,
194
194
  `o4*`) and from LiteLLM's `mode === 'responses'` field, and creates the
195
195
  sibling provider lazily.
196
196
 
197
+ If LiteLLM reports per-model reasoning-effort support (e.g.
198
+ `supports_low_reasoning_effort`, `supports_medium_reasoning_effort`,
199
+ `supports_high_reasoning_effort` in `model_info`), the plugin automatically
200
+ surfaces those as OpenCode variants under the discovered model. Each variant
201
+ sets `reasoningEffort` to the reported level, so you can switch between
202
+ effort levels from the model picker without hand-curating every entry.
203
+
197
204
  To override the routing per model:
198
205
 
199
206
  ```jsonc
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.7.1",
4
+ "version": "0.9.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",
@@ -1,5 +1,5 @@
1
1
  import type { Model as ModelV2 } from '@opencode-ai/sdk/v2'
2
- import type { LiteLLMModel } from '../types'
2
+ import type { LiteLLMModel, LiteLLMModelInfo } from '../types'
3
3
  import {
4
4
  categorizeModel,
5
5
  formatModelName,
@@ -20,6 +20,7 @@ export function buildModelV2(
20
20
  providerID: string,
21
21
  api: { id: string; url: string; npm: string },
22
22
  model: LiteLLMModel,
23
+ info?: LiteLLMModelInfo,
23
24
  ): ModelV2 {
24
25
  const type = categorizeModel(model)
25
26
  const isVision = !!model.supports_vision
@@ -53,9 +54,12 @@ export function buildModelV2(
53
54
  interleaved: false,
54
55
  },
55
56
  cost: {
56
- input: 0,
57
- output: 0,
58
- cache: { read: 0, write: 0 },
57
+ input: info?.input_cost_per_token ?? 0,
58
+ output: info?.output_cost_per_token ?? 0,
59
+ cache: {
60
+ read: info?.cache_read_input_token_cost ?? 0,
61
+ write: info?.cache_creation_input_token_cost ?? 0,
62
+ },
59
63
  },
60
64
  limit: {
61
65
  context: model.max_input_tokens ?? 0,
@@ -66,5 +70,13 @@ export function buildModelV2(
66
70
  options: {},
67
71
  headers: {},
68
72
  release_date: '',
73
+ variants: info?.supports_reasoning_efforts?.length
74
+ ? Object.fromEntries(
75
+ info.supports_reasoning_efforts.map((effort) => [
76
+ effort,
77
+ { reasoningEffort: effort },
78
+ ]),
79
+ )
80
+ : undefined,
69
81
  }
70
82
  }
@@ -2,11 +2,12 @@ import type { Model as ModelV2, Provider as ProviderV2 } from '@opencode-ai/sdk/
2
2
  import {
3
3
  autoDetectLiteLLM,
4
4
  checkLiteLLMHealth,
5
+ discoverLiteLLMModelInfo,
5
6
  discoverLiteLLMModels,
6
7
  normalizeBaseURL,
7
8
  } from '../utils/litellm-api'
8
9
  import { requiresResponsesAPI } from '../utils/format-model-name'
9
- import type { LiteLLMModel, Transport, TransportPolicy } from '../types'
10
+ import type { LiteLLMModel, LiteLLMModelInfo, Transport, TransportPolicy } from '../types'
10
11
  import { buildModelV2 } from './build-model'
11
12
 
12
13
  const DISCOVERY_TIMEOUT_MS = 5000
@@ -138,16 +139,29 @@ export async function discoverBucket(
138
139
  return
139
140
  }
140
141
 
141
- let models: LiteLLMModel[]
142
- try {
143
- models = await discoverLiteLLMModels(baseURL, apiKey, customHeaders)
144
- } catch (error) {
142
+ const [modelsResult, infoResult] = await Promise.allSettled([
143
+ discoverLiteLLMModels(baseURL, apiKey, customHeaders),
144
+ discoverLiteLLMModelInfo(baseURL, apiKey, customHeaders),
145
+ ])
146
+
147
+ if (modelsResult.status === 'rejected') {
145
148
  console.warn(
146
149
  '[opencode-litellm] Model discovery failed:',
147
- error instanceof Error ? error.message : String(error),
150
+ modelsResult.reason instanceof Error ? modelsResult.reason.message : String(modelsResult.reason),
148
151
  )
149
152
  return
150
153
  }
154
+ const models = modelsResult.value
155
+
156
+ let infoByName: Map<string, LiteLLMModelInfo> | null = null
157
+ if (infoResult.status === 'fulfilled') {
158
+ infoByName = infoResult.value
159
+ } else {
160
+ console.warn(
161
+ '[opencode-litellm] /v1/model/info unavailable; model costs will be zero:',
162
+ infoResult.reason instanceof Error ? infoResult.reason.message : String(infoResult.reason),
163
+ )
164
+ }
151
165
 
152
166
  if (models.length === 0) {
153
167
  console.warn(
@@ -176,7 +190,8 @@ export async function discoverBucket(
176
190
  // it with "team not allowed"). Set `api.id` per-model so each
177
191
  // entry carries the correct upstream model name.
178
192
  const perModelApi = { ...resolvedApi, id: model.id }
179
- out[model.id] = buildModelV2(resolvedApi.id, perModelApi, model)
193
+ const info = infoByName?.get(model.id) ?? {}
194
+ out[model.id] = buildModelV2(resolvedApi.id, perModelApi, model, info)
180
195
  }
181
196
  }
182
197
 
@@ -97,7 +97,10 @@ const USD_PER_TOKEN_TO_PER_MILLION = 1_000_000
97
97
  * image, audio) — they can't be used as primary chat models and would
98
98
  * clutter the picker.
99
99
  */
100
- function toConfigModel(model: LiteLLMModel): Record<string, unknown> | null {
100
+ function toConfigModel(
101
+ model: LiteLLMModel,
102
+ info?: LiteLLMModelInfo,
103
+ ): Record<string, unknown> | null {
101
104
  const type = categorizeModel(model)
102
105
  if (type === 'embedding' || type === 'image' || type === 'audio') {
103
106
  return null
@@ -137,6 +140,14 @@ function toConfigModel(model: LiteLLMModel): Record<string, unknown> | null {
137
140
  if (input.length > 1) {
138
141
  entry.modalities = { input, output: ['text'] }
139
142
  }
143
+ entry.variants = info?.supports_reasoning_efforts?.length
144
+ ? Object.fromEntries(
145
+ info.supports_reasoning_efforts.map((effort) => [
146
+ effort,
147
+ { reasoningEffort: effort },
148
+ ]),
149
+ )
150
+ : undefined
140
151
  return entry
141
152
  }
142
153
 
@@ -323,7 +334,10 @@ export const LiteLLMPlugin: Plugin = async (_input: PluginInput) => {
323
334
  if (models[model.id]) continue
324
335
  const info = infoByName?.get(model.id)
325
336
  if (infoByName && !info) unmatched.push(model.id)
326
- const entry = toConfigModel(info ? enrichModel(model, info) : model)
337
+ const entry = toConfigModel(
338
+ info ? enrichModel(model, info) : model,
339
+ info,
340
+ )
327
341
  if (!entry) {
328
342
  skipped++
329
343
  continue
@@ -64,10 +64,13 @@ export interface LiteLLMModelInfo {
64
64
  supports_function_calling?: boolean
65
65
  supports_vision?: boolean
66
66
  supports_reasoning?: boolean
67
+ supports_reasoning_efforts?: string[]
67
68
  supports_pdf_input?: boolean
68
69
  supports_audio_input?: boolean
69
70
  input_cost_per_token?: number
70
71
  output_cost_per_token?: number
72
+ cache_read_input_token_cost?: number
73
+ cache_creation_input_token_cost?: number
71
74
  }
72
75
 
73
76
  /** A single entry returned by LiteLLM's `/v1/model/info` endpoint. */
@@ -125,6 +125,25 @@ export async function discoverLiteLLMModelInfo(
125
125
  info[flag] = paramsValue
126
126
  }
127
127
  }
128
+
129
+ // Add supports reasoning efforts if present in litellm_params
130
+ const reasoningEffortPattern = /^supports_([a-z]+)_reasoning_effort$/
131
+ const efforts = new Set<string>()
132
+ for (const source of [info, entry.litellm_params]) {
133
+ if (!source || typeof source !== 'object') continue
134
+ for (const [key, value] of Object.entries(source)) {
135
+ const match = key.match(reasoningEffortPattern)
136
+ if (match && value === true) {
137
+ efforts.add(match[1])
138
+ }
139
+ }
140
+ }
141
+ if (efforts.size > 0) {
142
+ info.supports_reasoning_efforts = [
143
+ ...new Set([...(info.supports_reasoning_efforts ?? []), ...efforts]),
144
+ ]
145
+ }
146
+
128
147
  // Index under every alias LiteLLM may use for this model — the
129
148
  // `/v1/models` id can match any of them depending on how the
130
149
  // deployment names its entries (alias vs upstream model string).