opencode-plugin-litellm 0.7.0 โ 0.7.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 +2 -1
- package/package.json +1 -1
- package/src/plugin/index.ts +20 -0
- package/src/types/index.ts +10 -0
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ opencode
|
|
|
74
74
|
| ๐ก **Dynamic discovery** | Queries `/v1/models` so your OpenCode model picker always reflects your live `model_list`. |
|
|
75
75
|
| ๐ท๏ธ **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`. |
|
|
76
76
|
| ๐ง **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
|
+
| ๐ต **Real pricing** | Maps `input_cost_per_token` / `output_cost_per_token` 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. |
|
|
77
78
|
| ๐งช **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`. |
|
|
78
79
|
| ๐ข **Provider extraction** | Pulls `litellm_provider` (or the `provider/model` prefix) into `organizationOwner` so models group correctly in the UI. |
|
|
79
80
|
| ๐ **Auth-aware** | Honours `LITELLM_API_KEY` / `LITELLM_MASTER_KEY` env vars or `provider.litellm.options.apiKey`. |
|
|
@@ -292,7 +293,7 @@ sequenceDiagram
|
|
|
292
293
|
1. On OpenCode startup the `config` lifecycle hook fires.
|
|
293
294
|
2. If `provider.litellm` exists, its `baseURL` is used. Otherwise common ports are probed.
|
|
294
295
|
3. A health check (`GET /v1/models`) verifies the proxy is reachable and authorized.
|
|
295
|
-
4. Models from the response are enriched with `/v1/model/info` metadata (`mode`, token limits, capability flags โ `/v1/models` omits these for database-defined models) and converted into OpenCode model entries keyed by `id`, with formatted `name`, `organizationOwner`,
|
|
296
|
+
4. Models from the response are enriched with `/v1/model/info` metadata (`mode`, token limits, capability flags, and per-token pricing โ `/v1/models` omits these for database-defined models) and converted into OpenCode model entries keyed by `id`, with formatted `name`, `organizationOwner`, inferred `modalities`, and `cost` (USD/1M tokens, converted from LiteLLM's USD/token). Non-chat models (embedding / image / audio) are excluded from the picker.
|
|
296
297
|
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.
|
|
297
298
|
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.
|
|
298
299
|
7. The whole flow is wrapped in a `Promise.race` against a 20 s timeout so a slow proxy never blocks boot.
|
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.
|
|
4
|
+
"version": "0.7.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",
|
package/src/plugin/index.ts
CHANGED
|
@@ -77,9 +77,19 @@ function enrichModel(model: LiteLLMModel, info: LiteLLMModelInfo): LiteLLMModel
|
|
|
77
77
|
supports_reasoning: model.supports_reasoning ?? info.supports_reasoning,
|
|
78
78
|
supports_pdf_input: model.supports_pdf_input ?? info.supports_pdf_input,
|
|
79
79
|
supports_audio_input: model.supports_audio_input ?? info.supports_audio_input,
|
|
80
|
+
input_cost_per_token: model.input_cost_per_token ?? info.input_cost_per_token,
|
|
81
|
+
output_cost_per_token: model.output_cost_per_token ?? info.output_cost_per_token,
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
|
|
85
|
+
/**
|
|
86
|
+
* OpenCode's `cost` config field is USD per **million** tokens (the
|
|
87
|
+
* models.dev convention); LiteLLM's `/v1/model/info` reports USD per
|
|
88
|
+
* single token. `1e6` bridges the two โ verified against a live
|
|
89
|
+
* `x-litellm-response-cost` header, not just the unit names.
|
|
90
|
+
*/
|
|
91
|
+
const USD_PER_TOKEN_TO_PER_MILLION = 1_000_000
|
|
92
|
+
|
|
83
93
|
/**
|
|
84
94
|
* Convert a discovered LiteLLM model into an OpenCode config-level
|
|
85
95
|
* model entry (the shape used in `provider.*.models` inside
|
|
@@ -110,6 +120,16 @@ function toConfigModel(model: LiteLLMModel): Record<string, unknown> | null {
|
|
|
110
120
|
if (model.supports_vision) {
|
|
111
121
|
entry.attachment = true
|
|
112
122
|
}
|
|
123
|
+
// Only emit `cost` when LiteLLM actually reported a price. Omitting
|
|
124
|
+
// it (rather than defaulting to 0) lets OpenCode/models.dev fall back
|
|
125
|
+
// to their own default instead of us asserting "this model is free"
|
|
126
|
+
// for something LiteLLM simply has no price anchor for (e.g. rerank).
|
|
127
|
+
if (model.input_cost_per_token != null || model.output_cost_per_token != null) {
|
|
128
|
+
entry.cost = {
|
|
129
|
+
input: (model.input_cost_per_token ?? 0) * USD_PER_TOKEN_TO_PER_MILLION,
|
|
130
|
+
output: (model.output_cost_per_token ?? 0) * USD_PER_TOKEN_TO_PER_MILLION,
|
|
131
|
+
}
|
|
132
|
+
}
|
|
113
133
|
const input: Array<'text' | 'image' | 'pdf' | 'audio'> = ['text']
|
|
114
134
|
if (model.supports_vision) input.push('image')
|
|
115
135
|
if (model.supports_pdf_input) input.push('pdf')
|
package/src/types/index.ts
CHANGED
|
@@ -32,6 +32,14 @@ export interface LiteLLMModel {
|
|
|
32
32
|
supports_reasoning?: boolean
|
|
33
33
|
supports_pdf_input?: boolean
|
|
34
34
|
supports_audio_input?: boolean
|
|
35
|
+
/**
|
|
36
|
+
* USD price per input/output token, reliably available via
|
|
37
|
+
* `/v1/model/info` (`/v1/models` omits pricing). Absent for models
|
|
38
|
+
* LiteLLM has no price anchor for (e.g. rerank) โ treat as "unknown",
|
|
39
|
+
* not "free".
|
|
40
|
+
*/
|
|
41
|
+
input_cost_per_token?: number
|
|
42
|
+
output_cost_per_token?: number
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
export interface LiteLLMModelsResponse {
|
|
@@ -58,6 +66,8 @@ export interface LiteLLMModelInfo {
|
|
|
58
66
|
supports_reasoning?: boolean
|
|
59
67
|
supports_pdf_input?: boolean
|
|
60
68
|
supports_audio_input?: boolean
|
|
69
|
+
input_cost_per_token?: number
|
|
70
|
+
output_cost_per_token?: number
|
|
61
71
|
}
|
|
62
72
|
|
|
63
73
|
/** A single entry returned by LiteLLM's `/v1/model/info` endpoint. */
|