@chenlongapps/opencode-token-usage 0.2.5 → 0.3.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/dist/usage.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { officialPrice } from "./pricing.js";
2
+ export const modelKey = (model) => `${model.providerID}/${model.id}`;
1
3
  const safe = (n) => n !== undefined && Number.isFinite(n) ? Math.max(0, n) : 0;
2
4
  export function normalize(tokens) {
3
5
  return {
@@ -7,29 +9,33 @@ export function normalize(tokens) {
7
9
  }
8
10
  export const incoming = (t) => t.input + t.cache.read + t.cache.write;
9
11
  export const total = (t) => incoming(t) + t.output + t.reasoning;
10
- // Matches OpenCode 2.0.9 SessionUsage.calculateCost: thresholds are exclusive.
12
+ // Matches OpenCode 2.0.11 SessionUsage.calculateCost: thresholds are exclusive.
11
13
  export function estimate(tokens, prices = []) {
12
14
  const tier = prices.filter(p => p.tier && incoming(tokens) > p.tier.size)
13
15
  .sort((a, b) => b.tier.size - a.tier.size)[0];
14
16
  const price = tier ?? prices.find(p => !p.tier);
15
17
  const rates = [price?.input, price?.output, price?.cache?.read, price?.cache?.write];
18
+ const quantities = [tokens.input, tokens.output + tokens.reasoning, tokens.cache.read, tokens.cache.write];
16
19
  return {
17
- cost: (tokens.input * safe(rates[0]) + (tokens.output + tokens.reasoning) * safe(rates[1])
18
- + tokens.cache.read * safe(rates[2]) + tokens.cache.write * safe(rates[3])) / 1_000_000,
19
- defaultPrice: rates.some(rate => rate === undefined || !Number.isFinite(rate) || rate < 0),
20
+ cost: quantities.reduce((sum, quantity, index) => sum + quantity * safe(rates[index]), 0) / 1_000_000,
21
+ defaultPrice: total(tokens) > 0 && (!price || rates.some((rate, index) => quantities[index] > 0
22
+ && (rate === undefined || !Number.isFinite(rate) || rate < 0))),
20
23
  };
21
24
  }
22
- export function summarize(messages, prices = []) {
25
+ /** Prices every call with its recorded model. OpenCode's resolved price wins;
26
+ * the built-in manufacturer snapshot is used only when that price is incomplete. */
27
+ export function summarize(messages, catalog = new Map()) {
23
28
  const tokens = normalize();
24
29
  let cost = 0;
25
30
  let steps = 0;
26
- let defaultPrice = prices.length === 0;
31
+ let knownCosts = 0;
32
+ let missingCosts = 0;
27
33
  for (const message of messages) {
28
34
  // Matches OpenCode SessionStats: every assistant message is one step,
29
35
  // with or without reported usage; compaction and user messages are not.
30
36
  if (message.type === "assistant")
31
37
  steps++;
32
- if ((message.type !== "assistant" && message.type !== "compaction") || !message.tokens)
38
+ if (message.type !== "assistant" && message.type !== "compaction")
33
39
  continue;
34
40
  const t = normalize(message.tokens);
35
41
  tokens.input += t.input;
@@ -37,13 +43,28 @@ export function summarize(messages, prices = []) {
37
43
  tokens.reasoning += t.reasoning;
38
44
  tokens.cache.read += t.cache.read;
39
45
  tokens.cache.write += t.cache.write;
40
- const value = estimate(t, prices);
41
- cost += value.cost;
42
- defaultPrice ||= value.defaultPrice;
46
+ if (total(t) === 0)
47
+ continue;
48
+ if (!message.model) {
49
+ missingCosts++;
50
+ continue;
51
+ }
52
+ let value = estimate(t, catalog.get(modelKey(message.model)));
53
+ if (value.defaultPrice)
54
+ value = estimate(t, officialPrice(message.model)?.prices);
55
+ if (value.defaultPrice)
56
+ missingCosts++;
57
+ else {
58
+ cost += value.cost;
59
+ knownCosts++;
60
+ }
43
61
  }
62
+ const costStatus = missingCosts > 0
63
+ ? knownCosts > 0 ? "partial" : "unavailable"
64
+ : knownCosts > 0 ? "complete" : "empty";
44
65
  return {
45
66
  tokens, total: total(tokens), cacheRate: incoming(tokens) ? tokens.cache.read / incoming(tokens) : 0,
46
- steps, cost, defaultPrice,
67
+ steps, cost, costStatus,
47
68
  };
48
69
  }
49
70
  const usableLimit = (value) => value !== undefined && Number.isFinite(value) && value > 0;
@@ -85,8 +106,12 @@ export function usageRows(summary, context, performance) {
85
106
  if (t && t.cache.write > 0)
86
107
  rows.push(["Cache Write", number(t.cache.write)]);
87
108
  rows.push(["Cache Rate", summary ? `${(summary.cacheRate * 100).toFixed(1)}%` : "—"], ["Total", number(summary?.total)]);
88
- if (summary && summary.cost > 0)
109
+ if (summary?.costStatus === "complete")
89
110
  rows.push(["Cost", formatCost(summary.cost)]);
111
+ if (summary?.costStatus === "partial")
112
+ rows.push(["Cost", `${formatCost(summary.cost)} · partial`]);
113
+ if (summary?.costStatus === "unavailable")
114
+ rows.push(["Cost", "—"]);
90
115
  if (performance?.tps !== undefined && Number.isFinite(performance.tps)) {
91
116
  rows.push(["TPS", `${performance.tpsEstimated ? "~" : ""}${Math.max(0, performance.tps).toFixed(1)} tok/s`]);
92
117
  }
@@ -0,0 +1,282 @@
1
+ # 内置官方价格快照
2
+
3
+ v0.3.0 在 OpenCode 当前模型目录没有可用于某条消息的完整价格时,使用本页所列的厂商官方标准价补全。快照核验于 **2026-09-23**,共收录 72 个模型,金额均为美元 / 100 万 token。
4
+
5
+ ## 规则
6
+
7
+ - 每条 assistant 与 compaction 消息按自身记录的 `providerID`、模型 ID 和 token 用量分别计算。
8
+ - OpenCode 当前解析出的完整适用价格优先;仅当适用档位或本次实际使用的 token 类别缺价时,整条消息回退到内置价格,不混用两套费率。
9
+ - 网关模型只通过精确厂商 ID、精确别名及已知包装格式匹配,例如 `openai/gpt-5.6-luna`、`us.anthropic.claude-opus-5` 和 `claude-opus-5@default`。不按相似名称猜测。
10
+ - 目录首版只新增 2026-03-22 至 2026-09-22 发布、具有明确标准 token 价格的模型。后续版本只限制新增窗口,已经收录的模型不会因超过半年而自动删除。
11
+ - 采用标准同步 API 的公开价,不含 Batch、Flex、Fast/Priority、区域溢价、网关加价、免费额度、企业折扣、工具费和税费,因此 Cost 仍是估算,不代表账单。
12
+ - 任一有用量消息仍无法定价时,已知小计标记 `partial`;全部无法定价时显示 `—`。明确零价才显示 `$0.00`。
13
+ - 促销价按核验日官网显示的费率收录(如 `gpt-5.6-sol`、MiniMax-M3 的"长期 5 折"标价),不用划线原价。
14
+
15
+ ## OpenAI
16
+
17
+ 来源:[OpenAI API Pricing](https://developers.openai.com/api/docs/pricing)
18
+
19
+ | 模型 | 发布日期 | Input | Output | Cache Read | Cache Write | 长上下文档位 |
20
+ | --- | --- | ---: | ---: | ---: | ---: | --- |
21
+ | `gpt-5.5` | 2026-04-23 | 5 | 30 | 0.5 | — | ≥272K:10 / 45 / 1 / — |
22
+ | `gpt-5.5-pro` | 2026-04-23 | 30 | 180 | — | — | ≥272K:60 / 270 / — / — |
23
+ | `gpt-5.6-sol` | 2026-07-09 | 4 | 20 | 0.4 | 5 | ≥272K:8 / 30 / 0.8 / 10 |
24
+ | `gpt-5.6-terra` | 2026-07-09 | 2 | 12 | 0.2 | 2.5 | ≥272K:4 / 18 / 0.4 / 5 |
25
+ | `gpt-5.6-luna` | 2026-07-09 | 0.2 | 1.2 | 0.02 | 0.25 | ≥272K:0.4 / 1.8 / 0.04 / 0.5 |
26
+ | `gpt-6-astra` | 2026-09-04 | 10 | 50 | 1 | 12.5 | ≥272K:20 / 75 / 2 / 25 |
27
+ | `chat-latest`(别名 `gpt-chat-latest`) | 2026-05-05 | 5 | 30 | 0.5 | — | — |
28
+
29
+ `gpt-5.6-sol` 的当前标准价是限期促销价;快照采用核验日官网显示的费率。`chat-latest` 是官方 ChatGPT SKU,OpenRouter 上的 `gpt-chat-latest` 作为精确别名指向同一条目。
30
+
31
+ ## Anthropic
32
+
33
+ 来源:[Claude Platform Pricing](https://platform.claude.com/docs/en/about-claude/pricing)
34
+
35
+ | 模型 | 发布日期 | Input | Output | Cache Read | Cache Write |
36
+ | --- | --- | ---: | ---: | ---: | ---: |
37
+ | `claude-opus-4-7` | 2026-04-14 | 5 | 25 | 0.5 | 6.25 |
38
+ | `claude-opus-4-8` | 2026-05-28 | 5 | 25 | 0.5 | 6.25 |
39
+ | `claude-fable-5` | 2026-06-07 | 10 | 50 | 1 | 12.5 |
40
+ | `claude-sonnet-5` | 2026-06-29 | 2 | 10 | 0.2 | 2.5 |
41
+ | `claude-opus-5` | 2026-07-24 | 5 | 25 | 0.5 | 6.25 |
42
+ | `claude-fable-5-1` | 2026-09-01 | 10 | 50 | 0.25 | 12.5 |
43
+ | `claude-opus-5-5` | 2026-09-22 | 4 | 20 | 0.2 | 5 |
44
+
45
+ Cache Write 采用官方 5 分钟写入价。OpenCode 的聚合字段不区分 5 分钟与 1 小时 TTL,无法从历史消息可靠应用 1 小时写入价。OpenRouter 的 `claude-opus-4.7`、`claude-opus-4.8`、`claude-opus-5.5` 圆点写法注册为对应条目的精确别名。
46
+
47
+ `claude-opus-5-5` 的 Cache Read 是官方 0.05 倍基础输入价的特殊乘率(多数 Claude 模型为 0.1 倍),按官方标价 $0.20 / M 收录。
48
+
49
+ ## Google
50
+
51
+ 来源:[Gemini Developer API Pricing](https://ai.google.dev/gemini-api/docs/pricing)
52
+
53
+ | 模型 | 发布日期 | Input | Output(含 thinking) | Cache Read |
54
+ | --- | --- | ---: | ---: | ---: |
55
+ | `gemini-3.1-flash-lite` | 2026-05-07 | 0.25 | 1.5 | 0.025 |
56
+ | `gemini-3.5-flash` | 2026-05-19 | 1.5 | 9 | 0.15 |
57
+ | `gemini-3.5-flash-lite` | 2026-07-21 | 0.3 | 2.5 | 0.03 |
58
+ | `gemini-3.6-flash` | 2026-07-21 | 0.75 | 3.75 | 0.075 |
59
+ | `gemini-3.7-flash` | 2026-08-13 | 0.75 | 3.75 | 0.075 |
60
+ | `gemini-3.8-flash` | 2026-09-02 | 0.75 | 3.75 | 0.075 |
61
+
62
+ Gemini 3.6–3.8 Flash 的表中价格有效至 2026-12-31。上下文缓存还按存储时间收费;消息 token 统计无法表示该费用,因此目录不伪造 Cache Write 费率,遇到实际 cache write 且 OpenCode 也缺价时会标为不可用。
63
+
64
+ ## xAI
65
+
66
+ 来源:[Grok Models & Pricing](https://docs.x.ai/developers/models)
67
+
68
+ | 模型 | 发布日期 | Input | Output | Cache Read | ≥200K Input / Output / Cache Read |
69
+ | --- | --- | ---: | ---: | ---: | --- |
70
+ | `grok-build-0.1` | 2026-04-16 | 1 | 2 | 0.2 | 2 / 4 / 0.4 |
71
+ | `grok-4.3` | 2026-04-17 | 1.25 | 2.5 | 0.2 | 2.5 / 5 / 0.4 |
72
+ | `grok-4.5` | 2026-07-08 | 2 | 6 | 0.3 | 4 / 12 / 0.6 |
73
+ | `grok-4.6` | 2026-08-12 | 2 | 6 | 0.5 | 4 / 12 / 1 |
74
+ | `grok-4.7` | 2026-09-21 | 2 | 6 | 0.5 | 4 / 12 / 1 |
75
+
76
+ ## Mistral 与 Cohere
77
+
78
+ 来源:[Mistral Pricing](https://docs.mistral.ai/inference/pricing)、[Cohere Pricing](https://cohere.com/pricing)
79
+
80
+ | 模型 | 发布日期 | Input | Output | Cache Read |
81
+ | --- | --- | ---: | ---: | ---: |
82
+ | `mistral-medium-3-5-26-04` | 2026-04-29 | 1.5 | 7.5 | 0.15 |
83
+ | `command-a-plus-05-2026` | 2026-05-20 | 2.5 | 10 | — |
84
+
85
+ ## Z.ai(GLM)
86
+
87
+ 来源:[Z.AI Pricing](https://docs.z.ai/guides/overview/pricing)
88
+
89
+ | 模型 | 发布日期 | Input | Output | Cache Read |
90
+ | --- | --- | ---: | ---: | ---: |
91
+ | `glm-5.1` | 2026-04-06 | 1.4 | 4.4 | 0.26 |
92
+ | `glm-5.2` | 2026-06-16 | 1.4 | 4.4 | 0.26 |
93
+ | `glm-5.3` | 2026-08-16 | 1.4 | 4.4 | 0.26 |
94
+ | `glm-5.3-flash` | 2026-08-26 | 0.15 | 0.5 | 0.03 |
95
+ | `glm-5.3-flashx` | 2026-09-18 | 0.37 | 1.25 | 0.075 |
96
+
97
+ 官方按时间收取缓存存储费(限期免费),没有 cache write token 价,因此这些模型遇到实际 cache write 用量且 OpenCode 也缺价时标记为不可用。
98
+
99
+ ## DeepSeek
100
+
101
+ 来源:[DeepSeek Models & Pricing](https://api-docs.deepseek.com/quick_start/pricing)
102
+
103
+ | 模型 | 发布日期 | Input | Output | Cache Read |
104
+ | --- | --- | ---: | ---: | ---: |
105
+ | `deepseek-v4.1-flash` | 2026-09-10 | 0.30 | 1.20 | 0.006 |
106
+ | `deepseek-v4-pro-0813` | 2026-08-13 | 1.32 | 3.96 | 0.044 |
107
+
108
+ 表中采用官方**峰值时段最高价**作为保守估算上界;非峰值时段实际费率为表中一半。历史消息没有保留请求发生时对应的计费时段,无法准确选择峰谷档。已退役的 `deepseek-v4-flash` 与 `deepseek-v4-flash-vision-exp` 当前由官方路由到 V4.1 Flash 并按 Flash 价格计费;`deepseek-v4-flash-0731` 作为明确版本别名映射到同一条目。`deepseek-v4-pro` 当前对应 V4-Pro-0813。
109
+
110
+ ## Moonshot(Kimi)
111
+
112
+ 来源:[Kimi Model Inference Pricing](https://platform.moonshot.ai/docs/pricing)
113
+
114
+ | 模型 | 发布日期 | Input | Output | Cache Read | Cache Write |
115
+ | --- | --- | ---: | ---: | ---: | ---: |
116
+ | `kimi-k3` | 2026-07-15 | 3 | 15 | 0.30 | 3(5 分钟 TTL) |
117
+ | `kimi-k2.7-code` | 2026-06-12 | 0.95 | 4.00 | 0.19 | — |
118
+ | `kimi-k2.6` | 2026-04-20 | 0.95 | 4.00 | 0.16 | — |
119
+
120
+ K3 同时公布 5 分钟与 1 小时 cache write,快照沿用 Anthropic 约定取 5 分钟档;K2 系列只公布 cache 命中输入价,没有 cache write 价。
121
+
122
+ ## 阿里云百炼(Qwen)
123
+
124
+ 来源:[Model Studio Model inference pricing](https://www.alibabacloud.com/help/en/model-studio/model-pricing)(新加坡 International 站点标准价)
125
+
126
+ | 模型 | 发布日期 | Input | Output | Cache Read |
127
+ | --- | --- | ---: | ---: | ---: |
128
+ | `qwen3.8-max`(含别名 `qwen3.8-max-0902`) | 2026-08-03 | 2 | 6 | — |
129
+ | `qwen3.8-2.4t-a95b` | 2026-08-12 | 2 | 6 | — |
130
+ | `qwen3.8-27b` | 2026-08-14 | 0.5 | 3 | 0.1 |
131
+ | `qwen3.8-flash` | 2026-08-26 | 0.15 | 0.47 | — |
132
+ | `qwen3.7-max` | 2026-05-20 | 2.5 | 7.5 | 0.5 |
133
+ | `qwen3.7-plus` | 2026-05-26 | 0.4 / 1.2(>256K) | 1.6 / 4.8(>256K) | 0.08 / 0.24(>256K) |
134
+ | `qwen3.7-flash` | 2026-07-15 | 0.03 / 0.10 / 0.20(>32K、>256K) | 0.13 / 0.40 / 0.80(>32K、>256K) | 0.006 / 0.02 / 0.04(>32K、>256K) |
135
+ | `qwen3.6-max-preview` | 2026-04-20 | 1.3 / 2(>128K) | 7.8 / 12(>128K) | — |
136
+ | `qwen3.6-plus` | 2026-04-02 | 0.5 / 2(>256K) | 3 / 6(>256K) | — |
137
+ | `qwen3.6-flash` | 2026-04-16 | 0.25 / 1(>256K) | 1.5 / 4(>256K) | — |
138
+ | `qwen3.6-27b` | 2026-04-22 | 0.6 | 3.6 | — |
139
+ | `qwen3.6-35b-a3b` | 2026-04-15 | 0.375 | 2.25 | — |
140
+ | `qwen3.5-plus-2026-04-20`(别名 `qwen3.5-plus-20260420`) | 2026-04-20 | 0.4 / 0.5(>256K) | 2.4 / 3(>256K) | — |
141
+
142
+ 档位边界按官方措辞换算:`256K<Token≤1M` 即传入超过 256,000 token 启用高价档。Cache Read 收录官方隐式缓存命中价(所在档 Input 的 20%),仅限官方公布该费率的模型;`qwen3.8-max`、`qwen3.8-max-0902`、`qwen3.8-flash`、`qwen3.8-2.4t-a95b` 的缓存价只在控制台公布,不收录。隐式缓存创建按 Input 100% 计费、显式缓存创建按 125% 计费,聚合字段无法区分,因此一律不收 Cache Write。`qwen3.7-plus` 页面当前标注限期 8 折,快照采用未打折的刊例价。
143
+
144
+ ## 小米(MiMo)
145
+
146
+ 来源:[Xiaomi MiMo API Pricing](https://mimo.mi.com/docs/price/pay-as-you-go)(海外美元价)
147
+
148
+ | 模型 | 发布日期 | Input | Output | Cache Read |
149
+ | --- | --- | ---: | ---: | ---: |
150
+ | `mimo-v2.5` | 2026-04-22 | 0.14 | 0.28 | 0.0028 |
151
+ | `mimo-v2.5-pro` | 2026-04-22 | 0.435 | 0.87 | 0.0036 |
152
+ | `mimo-v2.6-flash` | 2026-09-21 | 0.14 | 0.28 | 0.0028 |
153
+ | `mimo-v2.6-pro` | 2026-09-21 | 0.435 | 0.87 | 0.0036 |
154
+ | `mimo-v2.6-pro-ultraspeed` | 2026-09-21 | 4.35 | 8.7 | 0.036 |
155
+
156
+ V2.6 系列官方宣布沿用 V2.5 系列 API 定价。Cache Write 官方限期免费,不设 token 价。
157
+
158
+ ## MiniMax
159
+
160
+ 来源:[MiniMax Pay as You Go](https://platform.minimax.io/docs/guides/pricing-paygo)
161
+
162
+ | 模型 | 发布日期 | Input | Output | Cache Read |
163
+ | --- | --- | ---: | ---: | ---: |
164
+ | `minimax-m3` | 2026-05-31 | 0.30 / 0.60(>512K) | 1.20 / 2.40(>512K) | 0.06 / 0.12(>512K) |
165
+
166
+ M3 页面标注"长期 5 折",快照按核验日的实收价收录;官方只公布 cache 读取价,没有 cache write 价。
167
+
168
+ ## 腾讯(混元)
169
+
170
+ 来源:[Tencent Cloud TokenHub Model pricing](https://intl.cloud.tencent.com/document/product/1300/78937)(新加坡国际站美元价)
171
+
172
+ | 模型 | 发布日期 | Input | Output | Cache Read |
173
+ | --- | --- | ---: | ---: | ---: |
174
+ | `hy3` | 2026-07-06 | 0.132 | 0.528 | 0.033 |
175
+ | `hy4-preview` | 2026-08-27 | 0.834 | 2.501 | 0.042 |
176
+
177
+ 官方页面只公布 cache 命中价,没有 cache write 价。
178
+
179
+ ## StepFun
180
+
181
+ 来源:[StepFun Pricing Details](https://platform.stepfun.ai/docs/en/guides/pricing/details)(海外站)
182
+
183
+ | 模型 | 发布日期 | Input | Output | Cache Read | Cache Write |
184
+ | --- | --- | ---: | ---: | ---: | ---: |
185
+ | `step-5-preview` | 2026-09-21 | 1 | 2.7 | 0.05 | 1 |
186
+ | `step-3.7-flash` | 2026-05-28 | 0.20 | 1.15 | 0.04 | — |
187
+
188
+ Step 5 Preview 官方明确说明 cache-miss Input 包含首次缓存写入,因此 OpenCode 单独上报的 Cache Write 按同一 `$1 / M` 费率计算。按 7:2:1 的 Cache Read / Input / Output token 比例,综合价为 `(7 × 0.05 + 2 × 1 + 1 × 2.7) / 10 = $0.505 / M`,约 `$0.51 / M`;该数值仅用于场景比较,插件仍按每条消息的实际五类 token 计算。Step 3.7 Flash 没有公布独立 cache write 价。
189
+
190
+ ## Meta(Muse Spark)
191
+
192
+ 来源:[Meta Model API Pricing and rate limits](https://ai.developer.meta.com/docs/pricing-rate-limits)
193
+
194
+ | 模型 | 发布日期 | Input | Output | Cache Read |
195
+ | --- | --- | ---: | ---: | ---: |
196
+ | `muse-spark-1.1` | 2026-07-09 | 1.25 | 4.25 | 0.15 |
197
+ | `muse-spark-1.2` | 2026-08-05 | 1.25 | 4.25 | 0.15 |
198
+ | `muse-spark-1.3` | 2026-09-02 | 1.25 | 4.25 | 0.15 |
199
+
200
+ 这里只收录 Standard tier。Contributor tier 虽然也是官方 API,但以允许 Meta 使用提示词和回答训练为条件的折扣方案,不属于标准价;官方没有 cache write token 价。
201
+
202
+ ## Inception
203
+
204
+ 来源:[Inception Models](https://www.inceptionlabs.ai/models)
205
+
206
+ | 模型 | 发布日期 | Input | Output | Cache Read |
207
+ | --- | --- | ---: | ---: | ---: |
208
+ | `mercury-2.5`(别名 `mercury-2.5-preview`) | 2026-09-08 | 0.04 | 0.15 | 0.004 |
209
+
210
+ 官网在核验日同时显示 `$0.20 / $0.75 / $0.02` 的刊例价和 80% off 的当前 API 价;快照采用当前实收的促销价,未使用 OpenRouter 自行报价。官方没有公布 cache write token 价。
211
+
212
+ ## Upstage
213
+
214
+ 来源:[Solar Pro 4 model page](https://console.upstage.ai/docs/models/solar-pro-4)
215
+
216
+ | 模型 | 发布日期 | Input | Output | Cache Read |
217
+ | --- | --- | ---: | ---: | ---: |
218
+ | `solar-pro4`(别名 `solar-pro4-260806`) | 2026-08-06 | 0.30 | 1.20 | 0.06 |
219
+
220
+ Solar Pro 4 的 90% off 活动已于 2026-09-10 结束,快照采用模型页当前标准 Console API 价;官方没有公布 cache write token 价。
221
+
222
+ ## Arcee AI
223
+
224
+ 来源:[Arcee Platform Pricing](https://docs.arcee.ai/get-started/pricing)
225
+
226
+ | 模型 | 发布日期 | Input | Output | Cache Read |
227
+ | --- | --- | ---: | ---: | ---: |
228
+ | `trinity-large-thinking` | 2026-04-01 | 0.25 | 0.80 | 0.06 |
229
+
230
+ 该条目是 Arcee 托管 API 的标准推理价;模型同时提供开源权重,但本目录只记录 API 费用。官方没有公布 cache write token 价。
231
+
232
+ ## ByteDance Seed
233
+
234
+ 来源:[BytePlus ModelArk Pricing](https://docs.byteplus.com/en/docs/ModelArk/1099320)、[Seed2.1 release](https://seed.bytedance.com/en/blog/seed2-1-officially-released-advancing-ai-productivity)
235
+
236
+ | 模型 | 发布日期 | Input | Output | Cache Read |
237
+ | --- | --- | ---: | ---: | ---: |
238
+ | `dola-seed-2-1-turbo`(别名 `seed-2-1-turbo`、`dola-seed-2-1-turbo-260628`) | 2026-06-23 | 0.50 | 2.50 | 0.10 |
239
+
240
+ 表中采用 BytePlus ModelArk 在线标准推理价。缓存存储按 token·小时另行收费,不是可由当前五类 token 统计表示的 Cache Write 单价,因此不收录。
241
+
242
+ ## Sakana Fugu
243
+
244
+ 来源:[Sakana Fugu Pricing](https://console.sakana.ai/pricing)、[Fugu Max and Fugu Ultra v2 release](https://sakana.ai/fugu-max-release)
245
+
246
+ | 模型 | 发布日期 | Input | Output | Cache Read | 长上下文档位 |
247
+ | --- | --- | ---: | ---: | ---: | --- |
248
+ | `fugu-ultra-v2.0`(别名 `fugu-ultra-v2`) | 2026-09-11 | 5 | 30 | 0.50 | >272K:10 / 45 / 1 |
249
+ | `fugu-max-v1.0`(别名 `fugu-max`) | 2026-09-11 | 2 | 6 | 0.25 | — |
250
+
251
+ Fugu Ultra 的编排 token 已包含在 API 返回的 input/output 用量中,按同一 token 价估算;web search/web fetch 等工具调用费不是五类 token,故不计入 Cost。官方没有公布 cache write token 价。
252
+
253
+ ## Aion Labs
254
+
255
+ 来源:[Aion Labs Models](https://www.aionlabs.ai/docs/models)
256
+
257
+ | 模型 | 发布日期 | Input | Output | Cache Read |
258
+ | --- | --- | ---: | ---: | ---: |
259
+ | `aion-3.0`(别名 `aion-labs/aion-3.0`) | 2026-05-05 | 3.00 | 6.00 | 0.75 |
260
+ | `aion-3.0-mini`(别名 `aion-labs/aion-3.0-mini`) | 2026-05-14 | 0.70 | 1.40 | 0.18 |
261
+
262
+ 表中是 Aion Labs 自家 API 目录公布的 per-token 价,不是 OpenRouter 网关价;官方没有公布 cache write token 价。Aion 3.0 与 3.0 Mini 是基于 GLM / DeepSeek 家族的多模型协作系统,按一次请求的输入输出 token 计费。
263
+
264
+ ## 美团(LongCat)
265
+
266
+ 来源:[LongCat API Docs — LongCat-2.0 Pricing](https://longcat.chat/platform/docs/Pricing/LongCat-2.0.html)、[LongCat-2.0 发布](https://www.meituan.com/news/NN260630164005904)
267
+
268
+ | 模型 | 发布日期 | Input | Output | Cache Read |
269
+ | --- | --- | ---: | ---: | ---: |
270
+ | `longcat-2.0` | 2026-06-30 | 0.30 | 1.20 | 0.006 |
271
+
272
+ 官方页面同时列出刊例价($0.75 / $2.95 / $0.015)与限时活动价;与 MiniMax-M3、Mercury 2.5 相同,快照按核验日实际计收的限时价收录。官方没有公布 cache write token 价,缓存存储也不同 token 计费。
273
+
274
+ ## 暂不收录
275
+
276
+ - Realtime、音频、图片、视频、embedding、按页、按分钟和按工具调用收费的模型无法仅由当前五类 token 用量准确计算。
277
+ - `grok-4.20`、`grok-4.20-multi-agent` 发布于 2026-03-09,早于目录收录窗口起点 2026-03-22。
278
+ - Fast/Priority 等加速档(`claude-opus-*-fast`、`gpt-5.6-*-pro`、`gpt-6-astra-pro`、MiniMax priority 档)不是标准同步价。
279
+ - 免费模型(Gemma 系列、`cohere/north-mini-code` 等开源或网关零价款)不设价格条目。
280
+ - 无法从厂商官方页面确认标准 token 价格的模型不猜价,包括 OpenRouter stealth/alpha 匿名模型、`z-ai/glm-5v-turbo`、`qwen3.6-plus-preview`、腾讯 `hy3-preview` 与 `hy-mt2-*`、`kwaipilot/kat-coder-pro-v2.5` 及其 Air 版本、`inclusionai/ling-3.0-*`、`bytedance-seed/seed-2.0-code` 等。这些模型目前只能查到 OpenRouter、AtlasCloud、DeepInfra 等网关或第三方报价,不能据此推断厂商标准价。
281
+ - 浮动别名(`-latest` 指针与 OpenRouter `~` 前缀条目)随底层模型漂移,不收录固定价。
282
+ - 只有询价、托管部署价或无法从厂商官方页面确认标准 token 价格的模型不猜价。
@@ -2,30 +2,34 @@
2
2
 
3
3
  ## 未发布(SDK 2.0.11)
4
4
 
5
- 验证日期:2026-09-22。环境:macOS、Node.js v22.23.2、npm 10.9.8、OpenCode v2.0.11;`@opencode/plugin`、`@opencode/client`、`@opencode/schema` 和 `@opencode/theme` 均精确锁定为 2.0.11。
5
+ 验证日期:2026-09-23。环境:macOS、Node.js v22.23.2、npm 10.9.8、OpenCode v2.0.11;`@opencode/plugin`、`@opencode/client`、`@opencode/schema` 和 `@opencode/theme` 均精确锁定为 2.0.11。
6
6
 
7
7
  ### 自动化检查
8
8
 
9
9
  | 检查 | 结果 |
10
10
  | --- | --- |
11
11
  | `npm run typecheck` | 通过 |
12
- | `npm test` | 32 项通过 |
12
+ | `npm test` | 44 项通过 |
13
13
  | `npm run build` | 通过,输出 ESM 与类型声明 |
14
14
  | `npm run test:smoke` | 通过,使用实际 `.tgz` 安装产物和真实 OpenCode 2.0.11 |
15
15
 
16
16
  SDK 从 2.0.9 升级到 2.0.11 后,四个顶层 OpenCode 包及锁文件中的传递依赖均已统一到 2.0.11。`@opencode/plugin` 两版的导出结构一致;包内容差异除依赖版本外,仅为 `ToastOptions` 新增可选的 `sessionID` 类型字段。
17
17
 
18
+ 本次发放在内置官方价格快照中新增 Anthropic `claude-opus-5-5`(2026-09-22 发布,$4 / $20,5 分钟缓存写入 $5,缓存读取按官方 0.05 倍基础输入价计为 $0.20),OpenRouter 圆点写法 `claude-opus-5.5` 注册为精确别名;快照由 71 个模型增至 72 个,新增测试锁定官方费率、0.05 倍缓存读取乘率、OpenRouter 与 Bedrock 包装格式匹配。
19
+
18
20
  新增共享性能监视器测试覆盖:查看会话 A 时捕获独立会话 B 的流,切换到 B 后立即恢复实时 TPS/TTFT;生成中切走、继续接收 delta 再切回;控制器销毁重建后恢复共享流;不同会话树隔离、新子代理即时纳入,以及删除会话清理运行期状态。既有重复事件去重与完成后收敛为精确 TPS 的断言继续通过。
19
21
 
20
22
  新增 Steps 计数覆盖:`summarize` 对带与不带 `tokens` 的 assistant 消息各计一个 step、compaction 与 user 消息不计、无 summary 时显示 `—`;`uniqueMessages` 链路上分叉继承副本不重复计数(快照 2 个 step、独立分叉树 1 个 step)、compaction 不产生 step、孙会话视图与根视图同为 6 个 step;行序断言锁定 Context → Steps → Input,无 Context 时 Steps 位于面板第一行。基准行数由 6 行调整为 7 行。
21
23
 
24
+ v0.3.0 成本测试覆盖:assistant 与 compaction 按消息实际 `model` 和五类 token 分别计算,混合模型树各自采用对应价格,消息自带 `cost` 不参与主 Cost。当前 OpenCode 模型目录中的完整适用价格优先;适用档位或实际使用类别缺价时,整条消息回退到内置官方快照,不拼接两套费率。官方目录测试锁定 72 个 2026-03-22 至 2026-09-22 发布的模型、来源 URL、唯一 ID、OpenAI/xAI/通义千问/MiniMax/Sakana 长上下文与上下文档位边界,以及 OpenRouter、Bedrock、Vertex 等包装格式和明确别名;相似名称不得猜价。目录按 OpenCode 当前模型目录(`temp/models.json`,210 个模型)补齐主流厂商:OpenAI、Anthropic、Google、xAI、Mistral、Cohere 之外新增 Z.ai(GLM)、DeepSeek、Moonshot(Kimi)、阿里云百炼(Qwen)、小米(MiMo)、MiniMax、腾讯(混元)、StepFun、Meta、Inception、Upstage、Arcee AI、ByteDance Seed、Sakana、Aion Labs、美团(LongCat);DeepSeek V4.1 Flash 与 V4 Pro 按厂商官方峰值最高价估算,旧 Flash、Vision Exp 和日期版本通过精确别名匹配。Step 5 Preview 的缓存写入按官方“cache-miss Input 包含首次缓存写入”规则使用 `$1 / M`。OpenRouter 圆点写法 `claude-opus-4.7`/`4.8`/`5.5`、官方 ChatGPT SKU `chat-latest`(别名 `gpt-chat-latest`)、Mercury 2.5、Solar Pro 4、Seed 2.1 Turbo、Fugu 版本、Aion 的 `aion-labs/` 前缀与 LongCat 网关链路同样通过精确别名匹配。窗口外的 `grok-4.20`、Fast/Priority 档、图片/音频/视频、免费与无官方标准价的模型均不收录;`kwaipilot/kat-coder-pro-v2.5`、`inclusionai/ling-3.0-*` 和 `bytedance-seed/seed-2.0-code` 只有网关或第三方报价,未据此猜价。缺价显示 `Cost —`,已知小计与缺价消息并存时显示 `· partial`,明确零价显示 `$0.00`。
25
+
22
26
  ### 真实 OpenCode 集成
23
27
 
24
- 隔离 smoke 测试确认打包插件可加载;空会话隐藏无数据行并显示 `Steps 0`;在独立会话已经开始慢速流后,同一 TUI 切换过去会立即显示 `TPS ~…` 与 TTFT,完成后变为无 `~` 的精确 TPS;既有 token、上下文与费用刷新、真实子代理全树累计、会话局部上下文及模型切换验证均继续通过。Steps 在真实集成中断言为:首条 assistant 完成后 `Steps 1` 且行序位于 Context 与 Input 之间;真实子代理场景下根视图与子代理视图均为 `Steps 4`(父 3 条 + 子 1 条),而被查看会话自身仍为 1,确认 Steps 随整棵树累计、上下文保持会话局部。测试产物保存在 `/var/folders/rw/bmx6c8hd737brl55m0_ff_b80000gn/T/token-usage-smoke-423PQP`。
28
+ 隔离 smoke 测试确认打包插件可加载;空会话隐藏无数据行并显示 `Steps 0`;在独立会话已经开始慢速流后,同一 TUI 切换过去会立即显示 `TPS ~…` 与 TTFT,完成后变为无 `~` 的精确 TPS;既有 token、上下文刷新、真实子代理全树累计、会话局部上下文及模型切换验证均继续通过。Steps 在真实集成中断言为:首条 assistant 完成后 `Steps 1` 且行序位于 Context 与 Input 之间;真实子代理场景下根视图与子代理视图均为 `Steps 4`(父 3 条 + 子 1 条),而被查看会话自身仍为 1。按 OpenCode 夹具价格计算,首条调用为 `$0.00126`,四条父/子代理调用累计 `$0.00504`;根会话切换到另一价格模型后,历史消息仍按自身模型保持 `$0.00504`,Context 则从 128,000 上限同步切换到 32,000。另一个模型在 OpenCode 目录中明确为 `cost: []`,其 `gpt-5.6-luna` 调用由打包产物内置官方价格计算为 `$0.000149`,TUI 显示 `Cost <$0.01`;安装包同时断言包含 `dist/pricing.js`、类型声明与 `docs/pricing.md`。本次 smoke 使用官方 `@opencode/cli-darwin-arm64@2.0.11` 的隔离二进制(安装于 `/private/var/folders/rw/bmx6c8hd737brl55m0_ff_b80000gn/T/opencode/isolated-cli-2011`,机器默认宿主仍为 2.0.14,未放宽版本断言),测试产物保存在 `/var/folders/rw/bmx6c8hd737brl55m0_ff_b80000gn/T/token-usage-smoke-Zq62zn`。
25
29
 
26
30
  ### 验证边界
27
31
 
28
- 当前 SDK 2.0.11 与宿主 2.0.11 的组合已完整验证。验证时机器默认宿主已是 2.0.12,因此 smoke 使用校验完整性的官方 `@opencode/cli-darwin-arm64@2.0.11` 隔离二进制,没有放宽宿主版本断言。2.0.9 和 2.0.10 宿主的历史验证记录保留在下方,但升级 SDK 后未重新执行这两个旧宿主的打包矩阵。后续升级 SDK 或宿主时,仍需重新核对分叉副本、compaction 排序及 step/delta 事件语义。
32
+ 当前 SDK 2.0.11 与宿主 2.0.11 的组合已完整验证。验证时机器默认宿主已是 2.0.14,因此 smoke 使用校验完整性的官方 `@opencode/cli-darwin-arm64@2.0.11` 隔离二进制,没有放宽宿主版本断言。2.0.9 和 2.0.10 宿主的历史验证记录保留在下方,但升级 SDK 后未重新执行这两个旧宿主的打包矩阵。后续升级 SDK 或宿主时,仍需重新核对消息模型字段、模型价格结构、分叉副本、compaction 排序及 step/delta 事件语义。官方价格是 2026-09-23 的版本内快照,采用标准同步 API 公开价;DeepSeek 峰谷计费采用峰值最高价作为保守上界。网关溢价、区域价、免费额度、折扣、工具费及无法由五类 token 表示的计费不在估算内,详细范围见 `docs/pricing.md`。
29
33
 
30
34
  ## v0.2.1(TPS 与 TTFT)
31
35
 
@@ -95,7 +99,7 @@ npm 发布前检查确认无作用域名称 `opencode-token-usage` 已由其他
95
99
  - 宿主 `Ws` 还使用 `session.revert` 作为搜索上界;本版本不读取 revert 状态,回退会话的取值可能与宿主不同。
96
100
  - 分母使用被查看会话的**活动模型**,而不是产生该用量的消息自身记录的模型;会话中途切换模型后两者可能不同。
97
101
  - Cost 与上下文上限使用同一活动模型解析规则,同样不使用消息自身记录的 `model` 字段:混合模型会话的 Cost 按查看时活动模型统一重算,不等于各模型实际账单之和。真实集成只验证了单夹具模型下的价格重算,混合模型的失真未单独断言。
98
- - 不显示进度条,上下文百分比与用量同行;行值加标签约 31 字符,窄侧边栏可能换行,响应式布局留待 v0.3.0。
102
+ - 不显示进度条,上下文百分比与用量同行;行值加标签约 31 字符,窄侧边栏可能换行,响应式布局与进度条留待后续版本。
99
103
  - 夹具 `usage-test/large` 的上下文上限改为 32,000 以便观测模型切换,`usage-test/small` 保持 128,000。
100
104
 
101
105
  ## v0.1.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenlongapps/opencode-token-usage",
3
- "version": "0.2.5",
3
+ "version": "0.3.1",
4
4
  "description": "Session-tree token usage, live performance, context window and estimated cost for OpenCode 2",
5
5
  "keywords": [
6
6
  "opencode",
@@ -30,6 +30,7 @@
30
30
  "dist",
31
31
  "README.md",
32
32
  "ROADMAP.md",
33
+ "docs/pricing.md",
33
34
  "docs/verification.md",
34
35
  "LICENSE"
35
36
  ],