opencode-plugin-litellm 1.7.1 → 1.8.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 CHANGED
@@ -74,7 +74,7 @@ also shows how to configure a provider directly in `opencode.json`.
74
74
  | 📡 **Dynamic discovery** | Queries `/v1/models` so your OpenCode model picker always reflects your live `model_list`. |
75
75
  | ⚡ **Stale-while-revalidate** | A warm disk cache supplies models without a network request. New sessions trigger a background refresh, and cache entries expire after 7 days. |
76
76
  | 🏷️ **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`. Set `formatModelNames: false` to keep the raw LiteLLM ids instead. |
77
- | 🧠 **Modality-aware** | Enriches `/v1/models` entries with `/v1/model/info` (`mode`, token limits, capability flags) and hides embedding / image / audio models from the picker. |
77
+ | 🧠 **Modality-aware** | Enriches `/v1/models` entries with `/v1/model/info` (`mode`, token limits, capability flags) and hides embedding / image / audio models from the picker. Declares `temperature` support only for models whose `supported_openai_params` lists it, so OpenCode applies (and the user can set) a sampling temperature on exactly those models. |
78
78
  | 💵 **Real pricing** | Maps `input_cost_per_token` / `output_cost_per_token` (and cache read/write costs) from `/v1/model/info` into OpenCode's `cost` field, so the picker and `/cost` show what the proxy actually bills instead of `$0.00`. Models LiteLLM has no price for are left unpriced, not falsely marked free. |
79
79
  | 🧩 **Reasoning-effort variants** | When LiteLLM reports per-model effort support (`supports_low_reasoning_effort`, …), the plugin surfaces each level as a picker variant automatically. |
80
80
  | 🧭 **Responses-API routing** | Models LiteLLM reports with `mode: "responses"` are invoked through `/v1/responses` instead of `/v1/chat/completions`, with no extra configuration. OpenCode 2 overrides the runtime package per model; OpenCode 1 gets a `<provider>-responses` sibling. |
@@ -590,6 +590,35 @@ the plugin logs a warning and you won't see LiteLLM-discovered models until
590
590
  the proxy is reachable again.
591
591
  </details>
592
592
 
593
+ <details>
594
+ <summary><b>Why does the first <code>opencode run</code> fail with <code>Model unavailable: litellm/…</code> on OpenCode 2?</b></summary>
595
+
596
+ This happens only on OpenCode 2, in a one-shot command (`opencode run`, CI jobs, scripts), when the plugin has no model cache yet. That covers the first run, a cleared or expired cache, and a changed config or credential. OpenCode registers the providers declared under `providers.*` only after plugin setup returns, so the plugin can't discover their models during setup. Discovery starts right after that, but a one-shot command has already resolved its model and fails before the models arrive. With `--standalone`, the process usually exits before discovery reaches the disk cache, so running it again fails the same way. Interactive sessions (TUI, web, desktop) and `opencode serve` aren't affected. This is how the OpenCode host orders startup ([anomalyco/opencode#57421](https://github.com/anomalyco/opencode/issues/57421)), not a plugin bug.
597
+
598
+ Workarounds:
599
+
600
+ - **Warm the cache once.** Open an interactive session or run `opencode serve` until the models appear, then stop it. One-shot runs use the cache until it expires (7 days) or the config or credential changes.
601
+ - **Pass the connection as plugin options** for CI and scripts. Plugin options are available during setup, so discovery finishes before the command resolves its model, even with a cold cache:
602
+
603
+ ```jsonc
604
+ {
605
+ "plugins": [
606
+ {
607
+ "package": "opencode-plugin-litellm@latest",
608
+ "options": {
609
+ "baseURL": "https://litellm.internal.example.com/v1",
610
+ "apiKey": "{env:LITELLM_API_KEY}"
611
+ }
612
+ }
613
+ ]
614
+ }
615
+ ```
616
+
617
+ One plugin entry describes one provider. To [split one proxy into several providers](#splitting-one-proxy-into-multiple-providers-includemodels--excludemodels) in a cold one-shot run, warm the cache first.
618
+
619
+ The OpenCode feature request for a readiness latch ([anomalyco/opencode#56119](https://github.com/anomalyco/opencode/issues/56119)) would remove the need for either workaround.
620
+ </details>
621
+
593
622
  <details>
594
623
  <summary><b>Will my hand-curated model entries be overwritten?</b></summary>
595
624
 
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": "1.7.1",
4
+ "version": "1.8.1",
5
5
  "description": "OpenCode CLI (v1 and v2) and Desktop plugin for LiteLLM proxy support with auto-detection and dynamic model discovery",
6
6
  "type": "module",
7
7
  "main": "./src/index.ts",
@@ -287,6 +287,17 @@ export function toConfigModel(
287
287
  if (model.supports_vision) {
288
288
  entry.attachment = true
289
289
  }
290
+ // Declare `temperature` only when `/v1/model/info` lists it among the model's
291
+ // `supported_openai_params`. OpenCode sends a sampling temperature (its own
292
+ // per-model default, or one set on the agent) only for models flagged as
293
+ // supporting it, so a model that accepts the parameter would otherwise
294
+ // silently ignore the user's setting. When the parameter is not listed, or
295
+ // `/v1/model/info` is unavailable, the field stays unset and OpenCode keeps
296
+ // its default behavior (some deployments, such as reasoning-only endpoints or
297
+ // guardrail classifiers, reject the parameter outright).
298
+ if (info?.supported_openai_params?.includes('temperature')) {
299
+ entry.temperature = true
300
+ }
290
301
  // Only emit `cost` when LiteLLM actually reported a price. Omitting
291
302
  // it (rather than defaulting to 0) lets OpenCode/models.dev fall back
292
303
  // to their own default instead of us asserting "this model is free"
package/src/plugin/v2.ts CHANGED
@@ -240,6 +240,8 @@ function toProviderModels(
240
240
  tools: entry.tool_call === undefined ? defaults.capabilities.tools : entry.tool_call === true,
241
241
  input,
242
242
  output,
243
+ // Left unset (unknown) unless the model was declared to accept it.
244
+ ...(entry.temperature === true ? { temperature: true } : {}),
243
245
  },
244
246
  cost,
245
247
  variants,
@@ -11,6 +11,18 @@ function stripVersionSuffix(part: string): string {
11
11
  return part.replace(/@(default|\d{6,8})$/i, '')
12
12
  }
13
13
 
14
+ /**
15
+ * Like `looksLikeVersionComponent`, but tolerates a single leading
16
+ * version letter — only the letters seen in real version positions
17
+ * (`v3`, `k2`, `m2`), so quantization prefixes like `q4` never pair.
18
+ * Dotted ids like `deepseek-v3.2` or `kimi-k2.5` have their version
19
+ * split apart by the tokenizer, and the letter-prefixed half must
20
+ * still merge back with the digits after the dot.
21
+ */
22
+ function looksLikePrefixedVersionComponent(token: string): boolean {
23
+ return /^[vkm]?\d{1,2}$/i.test(token)
24
+ }
25
+
14
26
  /**
15
27
  * Heuristic: does this numeric token look like a real version component
16
28
  * (single or double digit) rather than a date stamp or build number?
@@ -31,6 +43,15 @@ function looksLikeVersionComponent(token: string): boolean {
31
43
  * version pair, but the formatter would otherwise render it as
32
44
  * "Claude Opus 4 5".
33
45
  *
46
+ * The left-hand token may also carry a single version letter (`v3`,
47
+ * `k2`, `m2`): ids like `deepseek-v3.2` or `kimi-k2.5` get their dot
48
+ * split apart by the tokenizer and must re-join as `v3.2` / `k2.5`,
49
+ * never render as "DeepSeek V3 2" / "Kimi K2 5".
50
+ * Quantization prefixes never pair (`q4_0` tokenises as `q4` + `0`,
51
+ * but `q` is not a version letter), so `mistral-7b-instruct-q4_0`
52
+ * renders "Mistral 7B Instruct Q4 0" while ids with a real version
53
+ * pair like `llama-3.1-8b-instruct-q4_0` keep merging `3.1`.
54
+ *
34
55
  * Conservative on purpose:
35
56
  * - Only the FIRST mergeable pair scanning from the right is collapsed:
36
57
  * `gpt-3-5-turbo-16k` merges `3-5` into `3.5` and stops there.
@@ -49,7 +70,7 @@ function joinTrailingVersionPair(tokens: string[]): string[] {
49
70
  for (let i = tokens.length - 1; i >= 1; i--) {
50
71
  const a = tokens[i - 1]
51
72
  const b = tokens[i]
52
- if (looksLikeVersionComponent(a) && looksLikeVersionComponent(b)) {
73
+ if (looksLikePrefixedVersionComponent(a) && looksLikeVersionComponent(b)) {
53
74
  const prev = tokens[i - 2]
54
75
  const next = tokens[i + 1]
55
76
  const prevIsShortNumeric = prev !== undefined && looksLikeVersionComponent(prev)
@@ -101,7 +122,11 @@ export function categorizeModel(model: LiteLLMModel): 'chat' | 'embedding' | 'im
101
122
  * - Collapse a trailing pair of bare numeric tokens into a single
102
123
  * dotted version. Anthropic uses dash-only ids — `claude-opus-4-7`
103
124
  * would otherwise render as "Claude Opus 4 7" instead of
104
- * "Claude Opus 4.7".
125
+ * "Claude Opus 4.7". The left-hand token may carry a version
126
+ * letter, so `deepseek-v3.2` renders "DeepSeek V3.2", not
127
+ * "Deepseek V3 2".
128
+ * - Keep the official casing of known brand names (GLM, DeepSeek,
129
+ * MiniMax) instead of generic title-case.
105
130
  *
106
131
  * Examples:
107
132
  * "openai/gpt-4o-mini" -> "GPT 4o Mini"
@@ -110,6 +135,10 @@ export function categorizeModel(model: LiteLLMModel): 'chat' | 'embedding' | 'im
110
135
  * "claude-sonnet-4-6@default" -> "Claude Sonnet 4.6"
111
136
  * "bedrock/amazon.nova-pro-v1" -> "Amazon Nova Pro V1"
112
137
  * "qwen/qwen3-30b-a3b" -> "Qwen3 30B A3B"
138
+ * "litellm/deepseek-v3.2" -> "DeepSeek V3.2"
139
+ * "litellm/glm-5.3" -> "GLM 5.3"
140
+ * "litellm/kimi-k2.5" -> "Kimi K2.5"
141
+ * "litellm/minimax-m2.5" -> "MiniMax M2.5"
113
142
  */
114
143
  export function formatModelName(model: LiteLLMModel): string {
115
144
  const { id } = model
@@ -124,10 +153,17 @@ export function formatModelName(model: LiteLLMModel): string {
124
153
  const modelPart = stripVersionSuffix(afterProvider)
125
154
 
126
155
  const acronyms = new Set([
127
- 'gpt', 'oss', 'api', 'gguf', 'ggml', 'nomic', 'vl', 'it', 'mlx',
156
+ 'gpt', 'glm', 'oss', 'api', 'gguf', 'ggml', 'nomic', 'vl', 'it', 'mlx',
128
157
  'llm', 'ai', 'sdk', 'aws', 'gcp', 'tts', 'stt', 'mm',
129
158
  ])
130
159
 
160
+ // Mixed-case brand names that generic title-case would mangle
161
+ // ("Deepseek", "Minimax").
162
+ const brandNames: Record<string, string> = {
163
+ deepseek: 'DeepSeek',
164
+ minimax: 'MiniMax',
165
+ }
166
+
131
167
  const rawTokens = modelPart
132
168
  .split(/[-_.]/) // split on -, _ and .
133
169
  .filter(Boolean)
@@ -138,6 +174,7 @@ export function formatModelName(model: LiteLLMModel): string {
138
174
  // when both sides are pure digits).
139
175
  const tokens = joinTrailingVersionPair(rawTokens).map((token) => {
140
176
  const lower = token.toLowerCase()
177
+ if (brandNames[lower]) return brandNames[lower]
141
178
  if (acronyms.has(lower)) return token.toUpperCase()
142
179
  // sizes (30b, 7b, 4k...)
143
180
  if (/^\d+[bkmg]$/i.test(token)) return token.toUpperCase()
@@ -29,7 +29,7 @@ export interface ModelHints {
29
29
  * from older plugin versions are ignored rather than deserialized into
30
30
  * an incompatible structure.
31
31
  */
32
- const CACHE_VERSION = 5
32
+ const CACHE_VERSION = 6
33
33
 
34
34
  /**
35
35
  * Maximum age of a cache entry before it's treated as a miss. Without a