@pinkbanana/dsh-balance 0.15.2 → 0.16.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 +17 -8
- package/README_EN.md +18 -7
- package/docs/dsh-advisor-card-en.png +0 -0
- package/docs/dsh-advisor-card.png +0 -0
- package/docs/dsh-advisor-dark-narrow-en.png +0 -0
- package/docs/dsh-advisor-dark-narrow-zh-tw.png +0 -0
- package/docs/dsh-session-drilldown-en.png +0 -0
- package/docs/dsh-session-drilldown.png +0 -0
- package/docs/dsh-usage-dark-narrow-en.png +0 -0
- package/docs/dsh-usage-dark-narrow-zh-tw.png +0 -0
- package/docs/estimates.en.md +54 -0
- package/docs/estimates.md +54 -0
- package/lib/client.js +143 -20
- package/lib/client.js.map +1 -1
- package/lib/index.js +212 -24
- package/lib/index.js.map +1 -1
- package/lib/types/billing.d.ts +14 -8
- package/lib/types/client/locales.d.ts +2 -1
- package/lib/types/pricing.d.ts +6 -0
- package/lib/types/tokener-pricing.d.ts +59 -6
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额,以及 De
|
|
|
23
23
|
- 缓存查询结果并支持手动刷新
|
|
24
24
|
- 模型列表标注内置参考价(输入 / 输出每百万 tokens),未收录价格的模型明确标记
|
|
25
25
|
- 统计页「会话」分类中点击任一会话,下钻查看该会话的完整请求明细,可随时返回总览
|
|
26
|
-
- 按本会话近期已计费请求的 token 构成估算下轮费用:当前时段、下个峰谷切换后、新开会话(全部未命中缓存)、现在 /compact(摘要请求 + 压缩后首轮;摘要长度按约 4,000 tokens 假设),以及本 Harness
|
|
26
|
+
- 按本会话近期已计费请求的 token 构成估算下轮费用:当前时段、下个峰谷切换后、新开会话(全部未命中缓存)、现在 /compact(摘要请求 + 压缩后首轮;摘要长度按约 4,000 tokens 假设),以及本 Harness 已配置且可计价的其他官方模型;同时给出继续本会话相对新开因缓存节省的费用。这是估算而非官方账单,不会自动换模型,也不会把会话内容送出本机。计算细节见 [估算是怎么算的](./docs/estimates.md)
|
|
27
27
|
- 一键导出当前视图为 JSON 或 CSV(总览导出所选分类或完整摘要,会话导出请求级记录),数据不离开本机
|
|
28
28
|
- 统计页可直接填写 USD→CNY 汇率(存于浏览器 localStorage,无需重启);插件配置 `usdToCny` 优先生效
|
|
29
29
|
- 配置 `pricingOverrides` 可用自定义费率替换内置价格(按 provider + model 匹配,支持生效时间),模型列表与计费估算同步生效
|
|
@@ -34,7 +34,7 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额,以及 De
|
|
|
34
34
|
- 原生支持简体中文、繁體中文(zh-TW,缺失键回退到简体中文)和英文,并跟随 Harness 系统语言切换
|
|
35
35
|
- 支持 Harness 已保存的 `DEEPSEEK_API_KEY`
|
|
36
36
|
|
|
37
|
-

|
|
38
38
|
|
|
39
39
|
## 兼容性
|
|
40
40
|
|
|
@@ -140,7 +140,7 @@ providers:
|
|
|
140
140
|
|
|
141
141
|
统计仅覆盖当前 dsh 保存的本地会话,不包含其他客户端或整个组织的调用,也不提供 API Key 维度。请求数、输入、输出、缓存读取与缓存写入按 dsh 标准化的 usage 统计;缓存读取已从标准化输入中拆出,不重复计数。支持提供方、模型、会话、日期和活动时段明细,提供方别名统一归为 Tokener。
|
|
142
142
|
|
|
143
|
-
内置 2026-11-
|
|
143
|
+
内置 2026-11-28 对照 [公开机器可读目录](https://console.tokener.ai/api/public/v1/models) 与 [Tokener 模型说明](https://www.tokener.ai/docs/guides/models) 核验的美元参考价,逐个匹配完整模型 ID。使用 Tokener 目录价格,不套用原厂价格或 DeepSeek 的 2 倍峰谷倍率。目录中公布了官方低谷价的模型(目前为 `deepseek-flash`、`deepseek-v4-pro`)按 [模型页](https://www.tokener.ai/models/deepseek-flash) 的规则计价:北京时间周一至周五 09:00–12:00、14:00–18:00 为高峰(不含中国法定节假日),其余时间为低谷(含周末补班);低谷价仅适用于 2026-01-01 至 2027-12-31,窗口之外按高峰价。有上下文分档的模型(目前为 `claude-haiku-5-5`)按官方规则,用「含缓存在内的输入 token 数」匹配分档,整次请求套用该档的输入、缓存读取和输出单价。嵌入模型按官方「只计输入」计价;缓存读取单价未公布时,带缓存读取的请求标为未计费。已离开公开目录的模型 ID 仍沿用 2026-11-03 快照,便于历史会话估算;2026-11-28 核验时发现改价的模型(`claude-haiku-5-5`、`grok-4.3`、`grok-4.6`)在该日 00:00 北京时间之前沿用旧快照。参考价不代表历史实际扣款。未知模型、缺少 usage,以及包含未公开价格的缓存写入(或嵌入模型的缓存读取)请求,保留请求数与 token 并标为“未计费”。账户余额、折扣和实际消费以 [Tokener 控制台](https://console.tokener.ai) 为准。
|
|
144
144
|
|
|
145
145
|
## 统计口径
|
|
146
146
|
|
|
@@ -155,13 +155,22 @@ providers:
|
|
|
155
155
|
|
|
156
156
|
## 下轮费用估算
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
会话「消费」页会展示下轮费用估算卡片;在用量统计里点击会话名下钻时也会看到同一卡片。聊天框下方的余额摘要可按需展开该估算,默认收起以免占用空间。
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
卡片对照四种下一步的费用:当前时段继续、等待下个峰谷切换、现在 `/compact`(摘要请求 + 压缩后首轮;摘要约 4,000 tokens,至多历史的四分之一),以及新开会话(全部未命中缓存),并显示继续本会话相对新开因缓存可节省的费用。也可对照本 Harness 已配置且可计价的其他官方模型。仅为估算,不会自动压缩或换模型。
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过与用量统计相同的计价引擎计算。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。完整计算说明、峰谷规则和局限见 [估算是怎么算的](./docs/estimates.md)。
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+

|
|
165
|
+
|
|
166
|
+
窄屏(360px)深色主题:
|
|
167
|
+
|
|
168
|
+
<img src="./docs/dsh-advisor-dark-narrow-zh-tw.png" alt="窄屏深色主题的下轮费用估算(繁體中文)" width="280" />
|
|
169
|
+
<img src="./docs/dsh-usage-dark-narrow-zh-tw.png" alt="窄屏深色主题的用量页(繁體中文)" width="280" />
|
|
170
|
+
|
|
171
|
+
这些数字是公开标准价估算,不是官方账单。StepFun `step-5-preview` 在使用 2026-10-14 之后的标准缓存命中价时,会注明账户可能仍享受 0.35 元/百万的保留价,插件无法识别。Tokener 按 2026-11-28 公开目录计价,已计入官方低谷价和上下文分档(如有),不套用原厂价格或 DeepSeek 的 2 倍峰谷倍率。无法定价的模型会被省略,不会显示为 $0。美元与原生人民币分别展示;只有配置了 `usdToCny` 才会给出人民币合计。
|
|
172
|
+
|
|
173
|
+
本机只读接口为 `GET /dsh-balance/api/advice?session=…`(也可用 `sessionId`),仅本机可访问,响应不含 prompt 或会话正文。本版本尚未提供可供模型调用的 agent tool;只读的 `dsh_balance_advise` 仍在[路线图](./ROADMAP.md)中。
|
|
165
174
|
|
|
166
175
|
## 扩展与设计
|
|
167
176
|
|
|
@@ -178,7 +187,7 @@ pnpm check
|
|
|
178
187
|
pnpm preview
|
|
179
188
|
```
|
|
180
189
|
|
|
181
|
-
预览不使用真实密钥。可使用 `?page=session`
|
|
190
|
+
预览不使用真实密钥。可使用 `?page=session` 检查会话消费页与下轮估算卡片(124 次 StepFun 请求、7,161,128 tokens;预览夹具含现在 /compact),使用 `?page=usage` 查看独立统计页并下钻会话,使用 `?page=usage&lang=en&theme=dark` 或 `?lang=zh-tw` 检查英文、繁体中文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换与可展开的估算。估算计算说明见 [估算是怎么算的](./docs/estimates.md)。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。实时模型余额和统计修复自 `0.7.0` 起提供。
|
|
182
191
|
|
|
183
192
|
## License
|
|
184
193
|
|
package/README_EN.md
CHANGED
|
@@ -23,7 +23,7 @@ The composer readout follows the current session’s provider and model. The Set
|
|
|
23
23
|
- Cache query results with manual refresh support
|
|
24
24
|
- Annotate the model list with catalogued reference rates (input/output per million tokens); models without published pricing are marked explicitly
|
|
25
25
|
- Drill from the Sessions category into any session's full request breakdown and back to the overview
|
|
26
|
-
- Estimate the next turn from this session’s recent priced token mix: the current period, after the next peak change, a fresh session (all cache-miss), and other official models already configured in this Harness that can actually be priced, plus how much cache saves by continuing versus starting over. These are estimates, not an official bill; the plugin never auto-switches models and never sends session text off the machine
|
|
26
|
+
- Estimate the next turn from this session’s recent priced token mix: the current period, after the next peak change, a fresh session (all cache-miss), compact now (summarizer request plus the first post-compact turn; about 4,000 summary tokens assumed), and other official models already configured in this Harness that can actually be priced, plus how much cache saves by continuing versus starting over. These are estimates, not an official bill; the plugin never auto-switches models and never sends session text off the machine. See [How estimates are computed](./docs/estimates.en.md) for the details.
|
|
27
27
|
- Export the current view as JSON or CSV (overview: full summary or the visible category; session: request-level records) — data never leaves the machine
|
|
28
28
|
- Enter a display-only USD→CNY rate on the usage page (kept in browser localStorage, no restart); the plugin's `usdToCny` config still takes precedence
|
|
29
29
|
- Replace built-in prices with `pricingOverrides` (matched by provider + model, optional `effectiveFrom`); the model list and usage estimates follow
|
|
@@ -119,7 +119,7 @@ The Host queries the documented `GET /v1/models` with Bearer authentication; cre
|
|
|
119
119
|
|
|
120
120
|
Statistics cover locally saved dsh sessions only, not other clients or organization-wide usage, and do not group by API key. Requests and tokens are grouped by provider, model, session, date and activity hour. DSH usage already separates cache reads from uncached input; the plugin does not count them twice.
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
Estimates use USD reference rates re-checked on 2026-11-28 against the [machine-readable public catalog](https://console.tokener.ai/api/public/v1/models) and the [Tokener models guide](https://www.tokener.ai/docs/guides/models), matching exact model IDs, without vendor rates or DeepSeek's 2× peak multiplier. Models that publish official off-peak rates (currently `deepseek-flash` and `deepseek-v4-pro`) follow the [model page](https://www.tokener.ai/models/deepseek-flash): peak is Monday–Friday 09:00–12:00 and 14:00–18:00 Beijing time, excluding Chinese public holidays; all other times are off-peak, including weekend makeup workdays. Off-peak prices apply only from 2026-01-01 through 2027-12-31; outside that window, peak prices apply. Models with context price tiers (currently `claude-haiku-5-5`) use the official rule: the input count includes cached tokens, and the matching range sets the input, cache-read, and output prices for the whole request. Embedding models are priced on input only; when a cache-read rate is unpublished, requests that include cache reads stay unpriced. Model IDs that left the public catalog keep the 2026-11-03 snapshot so historical sessions can still be estimated. Models whose public rates changed at the 2026-11-28 check (`claude-haiku-5-5`, `grok-4.3`, `grok-4.6`) keep the earlier snapshot until 00:00 Beijing time on that day. These figures do not reconstruct historical charges. Unknown models, missing usage, and requests with unpublished cache-write pricing (or unpublished cache-read pricing on embedding models) retain their requests/tokens but stay unpriced. Account balances and actual bills remain in the [Tokener console](https://console.tokener.ai).
|
|
123
123
|
|
|
124
124
|
## StepFun setup
|
|
125
125
|
|
|
@@ -151,13 +151,24 @@ Built-in estimates use [official DeepSeek USD rates](https://api-docs.deepseek.c
|
|
|
151
151
|
|
|
152
152
|
## Next-turn estimates
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
The session Usage tab shows a next-turn estimate card; the same card appears when you drill into a session from Usage Statistics. The composer balance dock can expand the estimate on demand; it stays collapsed by default so it does not clutter the row.
|
|
155
155
|
|
|
156
|
-
The
|
|
156
|
+
The card compares four next steps: continue in the current period, wait for the next peak change, **`/compact` now** (summarizer request plus the first post-compact turn; about 4,000 summary tokens, at most a quarter of the history), and a fresh session (all cache-miss), plus how much cache saves by continuing versus starting over. It can also compare other official models already configured in this Harness that can be priced. These are estimates only; nothing is compacted or switched automatically.
|
|
157
157
|
|
|
158
|
-
The
|
|
158
|
+
The token shape is the per-bucket median of the session’s most recent 8 priced requests (uncached input, cache read, cache write, output), priced through the same billing engines as usage totals rather than a second pricing path. The next turn may not match, for example after compaction, a large paste, or vision input. The full method, peak-hour rules, and limitations are in [How estimates are computed](./docs/estimates.en.md).
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+

|
|
161
|
+
|
|
162
|
+

|
|
163
|
+
|
|
164
|
+
Narrow (360px) dark theme:
|
|
165
|
+
|
|
166
|
+
<img src="./docs/dsh-advisor-dark-narrow-en.png" alt="Next-turn estimate card, narrow dark theme" width="280" />
|
|
167
|
+
<img src="./docs/dsh-usage-dark-narrow-en.png" alt="Usage page, narrow dark theme" width="280" />
|
|
168
|
+
|
|
169
|
+
These figures are published-rate estimates, not an official bill. When the post-2026-10-14 standard StepFun `step-5-preview` cache-hit rate is used, the UI notes that some accounts may still be grandfathered at 0.35 CNY per million tokens; the plugin cannot detect that. Tokener estimates use the 2026-11-28 public catalog, including official off-peak and context-tier rates where published, without vendor rates or the DeepSeek peak multiplier. Unpriced models are omitted rather than shown as $0. Native USD and CNY are shown separately; a combined CNY total appears only when `usdToCny` is set.
|
|
170
|
+
|
|
171
|
+
The local read-only route is `GET /dsh-balance/api/advice?session=…` (`sessionId` is also accepted), loopback-only, and the payload never includes prompt or session text. This version has no agent tool the model can call; a read-only `dsh_balance_advise` tool is still on the [roadmap](./ROADMAP.md).
|
|
161
172
|
|
|
162
173
|
## Extension and design
|
|
163
174
|
|
|
@@ -174,7 +185,7 @@ pnpm check
|
|
|
174
185
|
pnpm preview
|
|
175
186
|
```
|
|
176
187
|
|
|
177
|
-
The preview uses no real credentials. Use `?lang=en&theme=dark` for English
|
|
188
|
+
The preview uses no real credentials. Use `?page=session` for the conversation usage view and next-turn estimate card (the fixture includes compact now), or `?page=usage` for the statistics overview and session drill-down. Add `?lang=en&theme=dark` or `?lang=zh-tw` for English, Traditional Chinese, and dark mode, or `?state=missing`, `error`, `empty`, or `loading` to inspect those states. The sample model selector also exercises the composer readout and the expandable estimate. See [How estimates are computed](./docs/estimates.en.md) for the method. StepFun balance and model queries and the redesigned account page are available starting with `0.6.0`. Live model balances, and usage accounting fixes are available starting with `0.7.0`.
|
|
178
189
|
|
|
179
190
|
## License
|
|
180
191
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# How estimates are computed
|
|
2
|
+
|
|
3
|
+
The next-turn advisor compares four next steps: continue in the current period, wait for the next peak/off-peak change, run `/compact` now, or start a fresh session. The figures are published-rate estimates, **not an official bill**. The plugin never switches models or runs `/compact` on its own, and session text never leaves this machine.
|
|
4
|
+
|
|
5
|
+
For the shorter product summary see the [README](../README_EN.md#next-turn-estimates). 简体中文版见 [估算是怎么算的](./estimates.md).
|
|
6
|
+
|
|
7
|
+
## Sampling and token shape
|
|
8
|
+
|
|
9
|
+
Estimates use only this session’s **most recent 8 priced requests** (or all of them if there are fewer). The advisor takes a median for each usage bucket and prices that shape through the same billing engines as the usage totals — not a second pricing path:
|
|
10
|
+
|
|
11
|
+
- uncached input
|
|
12
|
+
- cache read (hit)
|
|
13
|
+
- cache write
|
|
14
|
+
- output
|
|
15
|
+
|
|
16
|
+
The four medians are independent, so the synthetic “typical turn” may not match any single historical request. The next turn may also differ after compaction, a large paste, or vision input.
|
|
17
|
+
|
|
18
|
+
If the session has no priced requests, the card explains that it cannot estimate. It does not show $0.
|
|
19
|
+
|
|
20
|
+
## The four next steps
|
|
21
|
+
|
|
22
|
+
| Option | How it is priced |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| Continue in the current period | The median usage, priced at **now** (peak, off-peak, or the provider’s standard rate). |
|
|
25
|
+
| Wait for the next peak change | The same usage, priced at the next peak↔off-peak switch. Official DeepSeek rates, and Tokener models that publish official off-peak prices (such as `deepseek-flash` and `deepseek-v4-pro`), show this row. StepFun and other flat-rate Tokener models do not use DeepSeek's 2× multiplier, so the row is omitted. |
|
|
26
|
+
| Compact now | Cost of the **summarizer request** plus the **first turn after compaction**. The summarizer reads the whole history (the already-cached prefix still hits) and is assumed to write about 4,000 output tokens, capped at one quarter of the history. After compaction, only the **smallest cache-hit prefix** seen in the session still hits; the summary and the new input miss. Output stays at the median. Actual summary length and the model used to compact may differ. |
|
|
27
|
+
| Fresh session | Cache reads are treated as cache misses; output and cache writes are unchanged. This simulates a new session with no reusable prefix. |
|
|
28
|
+
|
|
29
|
+
“Saved by continuing this session vs starting over” is the difference between the fresh-session estimate and the current-period estimate. The card may also compare other official models already configured in this Harness that can actually be priced (same median usage, current period). Unpriced models are omitted rather than shown as $0. Tokener models are compared only when they are already in the session or current selection; they are not expanded from a built-in alternative catalog.
|
|
30
|
+
|
|
31
|
+
## Prices, peak hours, and limits
|
|
32
|
+
|
|
33
|
+
- **DeepSeek**: [official USD rates](https://api-docs.deepseek.com/quick_start/pricing/) with Beijing-time peak hours. Peak is Monday–Friday 09:00–12:00 and 14:00–18:00, excluding Chinese public holidays; weekends and those holidays are all-day off-peak. The built-in holiday calendar currently runs through 2027; later dates are estimated as ordinary weekdays and the card says so.
|
|
34
|
+
- **StepFun**: official standard CNY rates. The standard `step-5-preview` cache-hit rate is 0.70 CNY per million tokens from 2026-10-14; accounts that had already used the pay-as-you-go API before then may still be grandfathered at 0.35. The plugin cannot detect that, so it applies the standard effective-from date and notes the limitation.
|
|
35
|
+
- **Tokener**: USD reference rates from the 2026-11-28 public catalog, without vendor rates or DeepSeek's 2× peak multiplier. Official off-peak and context-tier rates are applied where the catalog publishes them. A turn that includes an unpublished cache-write price (or an unpublished cache-read price on an embedding model) is omitted from the estimate.
|
|
36
|
+
- `pricingOverrides` are shared with usage accounting. A combined CNY total appears only when `usdToCny` is configured (or a display rate is entered on the usage page), and it is labeled as a fixed-rate conversion.
|
|
37
|
+
|
|
38
|
+
Plans, discounts, account-specific rates, or unrecorded historical price changes can make the actual charge differ from the estimate.
|
|
39
|
+
|
|
40
|
+
## Where to find it
|
|
41
|
+
|
|
42
|
+
- The current session’s Usage tab, and the usage-page drill-down after you click a session name, both show the full estimate card.
|
|
43
|
+
- The balance dock under the composer can expand the same estimate on demand; it stays collapsed by default.
|
|
44
|
+
- Local read-only API: `GET /dsh-balance/api/advice?session=…` (`sessionId` is also accepted; optional `provider`, `model`, and repeated `compare=provider:model`). Loopback only; the payload never includes prompt or session text.
|
|
45
|
+
|
|
46
|
+
This version has **no** agent tool the model can call. A read-only `dsh_balance_advise` tool is still on the [roadmap](../ROADMAP.md). Until then, use the UI or the local HTTP route above.
|
|
47
|
+
|
|
48
|
+
Local preview (no credentials):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pnpm preview
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then open `?page=session` for the conversation usage view and advisor card, or `?page=usage` for the statistics overview and session drill-down. Add `&lang=en`, `&lang=zh-tw`, or `&theme=dark` as needed.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# 估算是怎么算的
|
|
2
|
+
|
|
3
|
+
下轮费用估算回答的是「下一步怎么走更省」:继续当前会话、等到下一个峰谷切换、现在执行 `/compact`,还是新开一个会话。这些数字是公开标准价估算,**不是官方账单**;插件不会自动换模型,也不会替你执行 `/compact`,更不会把会话正文送出本机。
|
|
4
|
+
|
|
5
|
+
更短的功能说明见 [README](../README.md#下轮费用估算);英文版见 [How estimates are computed](./estimates.en.md)。
|
|
6
|
+
|
|
7
|
+
## 取样与 token 构成
|
|
8
|
+
|
|
9
|
+
估算只使用本会话**最近 8 次已计费请求**(不足 8 次则全用)。对四个用量桶分别取中位数,再送给与用量统计相同的计价引擎,而不是另建一套价格路径:
|
|
10
|
+
|
|
11
|
+
- 未缓存输入
|
|
12
|
+
- 缓存读取(命中)
|
|
13
|
+
- 缓存写入
|
|
14
|
+
- 输出
|
|
15
|
+
|
|
16
|
+
四个桶的中位数是独立计算的,因此合成的「典型一轮」可能与任何单次历史请求都不完全相同。下轮实际用量也可能不同,例如上下文压缩、大段粘贴或视觉输入。
|
|
17
|
+
|
|
18
|
+
没有已计费请求时,卡片会说明无法估算,而不会把费用显示为 $0。
|
|
19
|
+
|
|
20
|
+
## 四种下一步
|
|
21
|
+
|
|
22
|
+
| 选项 | 怎么计价 |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| 当前时段继续 | 用上面的中位数用量,按**现在**的峰谷(或标准价)计价。 |
|
|
25
|
+
| 等待下个峰谷切换 | 用量不变,把计价时间推到下一次高峰↔低谷切换。DeepSeek 官方价,以及 Tokener 目录中公布了官方低谷价的模型(如 `deepseek-flash`、`deepseek-v4-pro`)会出现这一行;StepFun 与其他按标准价计价的 Tokener 模型不会套用 DeepSeek 的 2 倍倍率,因此不会出现这一行。 |
|
|
26
|
+
| 现在 `/compact` | **摘要请求**费用 + **压缩后首轮**费用。摘要请求读取整段历史(已缓存部分仍按命中计),输出按约 4,000 tokens 估算,且不超过历史长度的四分之一。压缩后的首轮里,仅会话中曾经出现过的**最小缓存命中前缀**仍命中,摘要文本与新的输入均按未命中计;输出仍用中位数。实际摘要长度和压缩所用模型可能不同。 |
|
|
27
|
+
| 新开会话 | 把当前的缓存读取全部改算为未命中,输出与缓存写入不变,模拟「没有前缀可命中」的新会话。 |
|
|
28
|
+
|
|
29
|
+
「继续本会话相对新开可节省」来自「新开会话」与「当前时段」的差额。插件还可以对照本 Harness 已配置、且能按官方目录定价的其他模型(同一中位数用量、当前时段);无法定价的模型会被省略,不会显示为 $0。Tokener 模型只作为当前会话对照,不会被当作官方备选目录展开。
|
|
30
|
+
|
|
31
|
+
## 价格、峰谷与局限
|
|
32
|
+
|
|
33
|
+
- **DeepSeek**:按[官方美元定价](https://api-docs.deepseek.com/quick_start/pricing/)和北京时间峰谷。高峰为周一至周五 09:00–12:00、14:00–18:00(不含中国法定节假日);周末和法定节假日全天低谷。内置节假日日历目前到 2027 年,超出后会按普通工作日估算并给出提示。
|
|
34
|
+
- **StepFun**:按官方人民币标准价。`step-5-preview` 缓存命中标准价自 2026-10-14 起为 0.70 元/百万 tokens;此前已按量调用的账户可能仍适用 0.35 元,插件无法识别该保留价,一律按标准生效时间计价,并在卡片上注明。
|
|
35
|
+
- **Tokener**:按 2026-11-28 公开目录的美元参考价,不套用原厂价格或 DeepSeek 的 2 倍峰谷倍率。已公布官方低谷价或上下文分档的模型按目录规则计价;含未公开价格的缓存写入(或嵌入模型的缓存读取)时,该次估算会被省略。
|
|
36
|
+
- 插件配置里的 `pricingOverrides` 与用量统计共用;配置了 `usdToCny`(或在统计页填写了显示汇率)时,才会出现人民币合计,并标明是固定汇率换算。
|
|
37
|
+
|
|
38
|
+
套餐、折扣、账户特殊价格或不在目录里的历史调价,都可能导致实际扣款与估算不同。
|
|
39
|
+
|
|
40
|
+
## 在哪里查看
|
|
41
|
+
|
|
42
|
+
- 当前会话的「消费」页,以及用量统计里点击会话名后的下钻页,都会显示完整估算卡片。
|
|
43
|
+
- 聊天框下方的余额条可按需展开同一估算,默认收起。
|
|
44
|
+
- 本机只读接口:`GET /dsh-balance/api/advice?session=…`(也可用 `sessionId`;可选 `provider`、`model` 与重复的 `compare=provider:model`)。仅本机可访问,响应不含 prompt 或会话正文。
|
|
45
|
+
|
|
46
|
+
本版本**没有**可供模型调用的 agent tool。只读的 `dsh_balance_advise` 仍在[路线图](../ROADMAP.md)中;在此之前,请使用上面的界面或本机 HTTP 接口。
|
|
47
|
+
|
|
48
|
+
本地预览(无需密钥):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pnpm preview
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
然后打开 `?page=session` 查看会话消费页与估算卡片,或 `?page=usage` 查看统计总览并下钻到某个会话。可加 `&lang=en`、`&lang=zh-tw`、`&theme=dark`。
|
package/lib/client.js
CHANGED
|
@@ -2128,13 +2128,19 @@ window.__ModuleLoader__.load({
|
|
|
2128
2128
|
const { weekday, dateKey } = beijingCalendar(date);
|
|
2129
2129
|
return weekday >= 1 && weekday <= 5 && !CHINESE_PUBLIC_HOLIDAYS.has(dateKey);
|
|
2130
2130
|
}
|
|
2131
|
-
/** Whether the
|
|
2132
|
-
|
|
2133
|
-
|
|
2131
|
+
/** Whether the Beijing clock falls in Mon–Fri 09:00–12:00 or 14:00–18:00, excluding Chinese public holidays.
|
|
2132
|
+
* Unlike `isPeakHour`, this has no provider-specific effective-from gate.
|
|
2133
|
+
*/
|
|
2134
|
+
function isChineseStatutoryPeakHour(date) {
|
|
2134
2135
|
if (!isPeakCalendarDay(date)) return false;
|
|
2135
2136
|
const hour = beijingCalendar(date).hour;
|
|
2136
2137
|
return PEAK_WINDOWS.some(([start, end]) => hour >= start && hour < end);
|
|
2137
2138
|
}
|
|
2139
|
+
/** Whether the given instant falls inside a DeepSeek peak-pricing window. */
|
|
2140
|
+
function isPeakHour(date) {
|
|
2141
|
+
if (date.getTime() < PEAK_EFFECTIVE_FROM) return false;
|
|
2142
|
+
return isChineseStatutoryPeakHour(date);
|
|
2143
|
+
}
|
|
2138
2144
|
/** The next instant at which the current pricing period ends (Beijing time). */
|
|
2139
2145
|
function nextPeriodChange(date) {
|
|
2140
2146
|
const ms = date.getTime();
|
|
@@ -2153,13 +2159,32 @@ window.__ModuleLoader__.load({
|
|
|
2153
2159
|
}
|
|
2154
2160
|
//#endregion
|
|
2155
2161
|
//#region src/tokener-pricing.ts
|
|
2156
|
-
/** USD per million tokens from
|
|
2157
|
-
*
|
|
2158
|
-
*
|
|
2159
|
-
*
|
|
2162
|
+
/** USD per million tokens from the public Tokener catalog.
|
|
2163
|
+
* Current snapshot checked 2026-11-28 against
|
|
2164
|
+
* https://console.tokener.ai/api/public/v1/models
|
|
2165
|
+
* (schemaVersion 1, catalogRevision sha256:d6e160bc81b620b91cb7b6c263fb2487d0e0060f84e651b3b06d6ca9b77bcf31),
|
|
2166
|
+
* https://www.tokener.ai/docs/guides/models, and model pages such as
|
|
2167
|
+
* https://www.tokener.ai/models/deepseek-flash and
|
|
2168
|
+
* https://www.tokener.ai/models/claude-haiku-5-5.
|
|
2169
|
+
* Model IDs are exact and case-sensitive. These are reference estimates, not account bills.
|
|
2170
|
+
* Cache-write pricing is not published; requests with cache writes stay unpriced.
|
|
2171
|
+
* Embedding models are priced on input only; a cache-read rate is not published for them.
|
|
2160
2172
|
*/
|
|
2161
|
-
const TOKENER_PRICING_VERSION = "tokener-reference-2026-11-
|
|
2162
|
-
const
|
|
2173
|
+
const TOKENER_PRICING_VERSION = "tokener-reference-2026-11-28";
|
|
2174
|
+
const TOKENER_LEGACY_PRICING_VERSION = "tokener-reference-2026-11-03";
|
|
2175
|
+
/** Re-verification instant for rate changes noticed on 2026-11-28. Not a vendor-published effective date. */
|
|
2176
|
+
const TOKENER_CURRENT_EFFECTIVE_FROM = Date.parse("2026-11-28T00:00:00+08:00");
|
|
2177
|
+
function rates(cacheMissUsdPerMillion, cacheHitUsdPerMillion, outputUsdPerMillion) {
|
|
2178
|
+
return {
|
|
2179
|
+
cacheMissUsdPerMillion,
|
|
2180
|
+
cacheHitUsdPerMillion,
|
|
2181
|
+
outputUsdPerMillion
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
/** Last known public-catalog rates from the 2026-11-03 snapshot.
|
|
2185
|
+
* Kept so IDs that left the public catalog, and pre-change rates for repriced models, can still be estimated.
|
|
2186
|
+
*/
|
|
2187
|
+
const TOKENER_LEGACY_PRICES = {
|
|
2163
2188
|
"claude-fable-5": [
|
|
2164
2189
|
10,
|
|
2165
2190
|
1,
|
|
@@ -2671,6 +2696,74 @@ window.__ModuleLoader__.load({
|
|
|
2671
2696
|
12
|
|
2672
2697
|
]
|
|
2673
2698
|
};
|
|
2699
|
+
/** Public catalog models as of 2026-11-28 (38 entries). */
|
|
2700
|
+
const TOKENER_CURRENT_PRICES = {
|
|
2701
|
+
"claude-fable-5": { rates: rates(10, 1, 50) },
|
|
2702
|
+
"claude-fable-5-1": { rates: rates(10, .25, 50) },
|
|
2703
|
+
"claude-fable-5-2": { rates: rates(8, .2, 40) },
|
|
2704
|
+
"claude-haiku-4-5-20251001": { rates: rates(1, .1, 5) },
|
|
2705
|
+
"claude-haiku-5-5": {
|
|
2706
|
+
rates: rates(.1, .01, .5),
|
|
2707
|
+
contextPriceTiers: [{
|
|
2708
|
+
thresholdTokens: 100001,
|
|
2709
|
+
...rates(.5, .05, 2.5)
|
|
2710
|
+
}]
|
|
2711
|
+
},
|
|
2712
|
+
"claude-opus-4-5-20251101": { rates: rates(5, .5, 25) },
|
|
2713
|
+
"claude-opus-4-6": { rates: rates(5, .5, 25) },
|
|
2714
|
+
"claude-opus-4-7": { rates: rates(5, .5, 25) },
|
|
2715
|
+
"claude-opus-4-8": { rates: rates(5, .5, 25) },
|
|
2716
|
+
"claude-opus-5": { rates: rates(5, .5, 25) },
|
|
2717
|
+
"claude-opus-5-5": { rates: rates(4, .2, 20) },
|
|
2718
|
+
"claude-sonnet-4-5-20250929": { rates: rates(3, .3, 15) },
|
|
2719
|
+
"claude-sonnet-4-6": { rates: rates(3, .3, 15) },
|
|
2720
|
+
"claude-sonnet-5": { rates: rates(2, .2, 10) },
|
|
2721
|
+
"claude-sonnet-5-5": { rates: rates(2, .1, 10) },
|
|
2722
|
+
"deepseek-flash": {
|
|
2723
|
+
rates: rates(.3, .006, 1.2),
|
|
2724
|
+
offPeakRates: rates(.15, .003, .6)
|
|
2725
|
+
},
|
|
2726
|
+
"deepseek-v3.2": { rates: rates(.62, .62, 1.85) },
|
|
2727
|
+
"deepseek-v4-pro": {
|
|
2728
|
+
rates: rates(1.32, .044, 3.96),
|
|
2729
|
+
offPeakRates: rates(.66, .022, 1.98)
|
|
2730
|
+
},
|
|
2731
|
+
"embed-english-v3": {
|
|
2732
|
+
rates: rates(.1, 0, 0),
|
|
2733
|
+
unpublishedCacheRead: true
|
|
2734
|
+
},
|
|
2735
|
+
"embed-multilingual-v3": {
|
|
2736
|
+
rates: rates(.1, 0, 0),
|
|
2737
|
+
unpublishedCacheRead: true
|
|
2738
|
+
},
|
|
2739
|
+
"embed-v4": {
|
|
2740
|
+
rates: rates(.12, 0, 0),
|
|
2741
|
+
unpublishedCacheRead: true
|
|
2742
|
+
},
|
|
2743
|
+
"glm-4.7": { rates: rates(.6, .6, 2.2) },
|
|
2744
|
+
"glm-4.7-flash": { rates: rates(.07, .07, .4) },
|
|
2745
|
+
"glm-5": { rates: rates(1, .2, 3.2) },
|
|
2746
|
+
"grok-4.3": { rates: rates(1.25, .2, 2.5) },
|
|
2747
|
+
"grok-4.6": { rates: rates(2, .5, 6) },
|
|
2748
|
+
"grok-4.7": { rates: rates(2, .5, 6) },
|
|
2749
|
+
"kimi-k3": { rates: rates(3, .3, 15) },
|
|
2750
|
+
"kimi-k3.1": { rates: rates(4, .2, 20) },
|
|
2751
|
+
"kimi-k3.1-pro": { rates: rates(2, .2, 10) },
|
|
2752
|
+
"MiniMax-M2.5": { rates: rates(.3, .03, 1.2) },
|
|
2753
|
+
"qwen3-235b-a22b-2507": { rates: rates(.22, .22, .88) },
|
|
2754
|
+
"qwen3-32b": { rates: rates(.15, .15, .6) },
|
|
2755
|
+
"qwen3-coder-30b-a3b": { rates: rates(.15, .15, .6) },
|
|
2756
|
+
"qwen3-coder-480b-a35b": { rates: rates(.45, .45, 1.8) },
|
|
2757
|
+
"qwen3-coder-next": { rates: rates(.5, .5, 1.2) },
|
|
2758
|
+
"qwen3-next-80b-a3b": { rates: rates(.15, .15, 1.2) },
|
|
2759
|
+
"qwen3-vl-235b-a22b": { rates: rates(.53, .53, 2.66) }
|
|
2760
|
+
};
|
|
2761
|
+
/** Models whose public-catalog rates changed between the 2026-11-03 snapshot and the 2026-11-28 check. */
|
|
2762
|
+
const TOKENER_REPRICED_MODELS = /* @__PURE__ */ new Set([
|
|
2763
|
+
"claude-haiku-5-5",
|
|
2764
|
+
"grok-4.3",
|
|
2765
|
+
"grok-4.6"
|
|
2766
|
+
]);
|
|
2674
2767
|
//#endregion
|
|
2675
2768
|
//#region src/billing.ts
|
|
2676
2769
|
const USAGE_ROUTE = "/dsh-balance/api/usage";
|
|
@@ -2802,16 +2895,43 @@ window.__ModuleLoader__.load({
|
|
|
2802
2895
|
pricingVersion,
|
|
2803
2896
|
...rates
|
|
2804
2897
|
})),
|
|
2805
|
-
...
|
|
2898
|
+
...tokenerBillingPrices()
|
|
2899
|
+
];
|
|
2900
|
+
function tokenerUsdPrice(model, quote, effectiveFrom, pricingVersion) {
|
|
2901
|
+
return {
|
|
2806
2902
|
provider: "tokener",
|
|
2807
2903
|
model,
|
|
2808
|
-
effectiveFrom
|
|
2809
|
-
pricingVersion
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2904
|
+
effectiveFrom,
|
|
2905
|
+
pricingVersion,
|
|
2906
|
+
...quote.rates,
|
|
2907
|
+
...quote.contextPriceTiers === void 0 ? {} : { contextPriceTiers: quote.contextPriceTiers },
|
|
2908
|
+
...quote.offPeakRates === void 0 ? {} : { offPeakRates: quote.offPeakRates },
|
|
2909
|
+
...quote.unpublishedCacheRead === void 0 ? {} : { unpublishedCacheRead: true }
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2912
|
+
/** Historical 2026-11-03 snapshot plus the 2026-11-28 public catalog, with dated rows for repriced models. */
|
|
2913
|
+
function tokenerBillingPrices() {
|
|
2914
|
+
const epoch = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
2915
|
+
const currentFrom = new Date(TOKENER_CURRENT_EFFECTIVE_FROM).toISOString();
|
|
2916
|
+
const rows = [];
|
|
2917
|
+
for (const [model, [input, cacheRead, output]] of Object.entries(TOKENER_LEGACY_PRICES)) {
|
|
2918
|
+
if (model in TOKENER_CURRENT_PRICES && !TOKENER_REPRICED_MODELS.has(model)) continue;
|
|
2919
|
+
rows.push({
|
|
2920
|
+
provider: "tokener",
|
|
2921
|
+
model,
|
|
2922
|
+
effectiveFrom: epoch,
|
|
2923
|
+
pricingVersion: TOKENER_LEGACY_PRICING_VERSION,
|
|
2924
|
+
cacheMissUsdPerMillion: input,
|
|
2925
|
+
cacheHitUsdPerMillion: cacheRead,
|
|
2926
|
+
outputUsdPerMillion: output
|
|
2927
|
+
});
|
|
2928
|
+
}
|
|
2929
|
+
for (const [model, quote] of Object.entries(TOKENER_CURRENT_PRICES)) {
|
|
2930
|
+
const effectiveFrom = TOKENER_REPRICED_MODELS.has(model) ? currentFrom : epoch;
|
|
2931
|
+
rows.push(tokenerUsdPrice(model, quote, effectiveFrom, TOKENER_PRICING_VERSION));
|
|
2932
|
+
}
|
|
2933
|
+
return rows;
|
|
2934
|
+
}
|
|
2815
2935
|
/** The latest effective price for one provider/model pair, for display only. */
|
|
2816
2936
|
function findBillingPrice(provider, model) {
|
|
2817
2937
|
const providerId = findBalanceProvider(provider)?.id ?? provider;
|
|
@@ -3044,6 +3164,7 @@ window.__ModuleLoader__.load({
|
|
|
3044
3164
|
"tokener.console": "打开 Tokener 控制台",
|
|
3045
3165
|
"error.BALANCE_NOT_SUPPORTED": "此提供方尚未公开余额查询接口",
|
|
3046
3166
|
"billing.reason.unknown-cache-write-price": "缓存写入价格未公开",
|
|
3167
|
+
"billing.reason.unknown-cache-read-price": "缓存读取价格未公开",
|
|
3047
3168
|
"dock.loading": "查询中…",
|
|
3048
3169
|
"dock.unavailable": "暂时无法获取",
|
|
3049
3170
|
"dock.empty": "暂无余额信息",
|
|
@@ -3184,7 +3305,7 @@ window.__ModuleLoader__.load({
|
|
|
3184
3305
|
"advice.caveat.estimate-not-a-bill": "以上为公开标准价估算,不是官方账单;套餐、折扣或账户特殊价格可能导致实际扣款不同。",
|
|
3185
3306
|
"advice.caveat.shape-may-differ": "下轮实际用量可能与此中位数不同,例如上下文压缩、大段粘贴或视觉输入。",
|
|
3186
3307
|
"advice.caveat.stepfun-grandfathering": "step-5-preview 缓存命中标准价自 2026-10-14 起为 0.70 元/百万 tokens;此前已按量调用的账户可能仍适用 0.35 元,插件无法识别该保留价。",
|
|
3187
|
-
"advice.caveat.tokener-snapshot": "Tokener 费用按 2026-11-
|
|
3308
|
+
"advice.caveat.tokener-snapshot": "Tokener 费用按 2026-11-28 公开目录估算,已计入官方低谷价和上下文分档(如有);不套用原厂价格或 DeepSeek 峰谷倍率。",
|
|
3188
3309
|
"advice.caveat.no-priced-sample": "本会话还没有已计费请求,无法根据历史用量估算下轮费用。",
|
|
3189
3310
|
"advice.caveat.unpriced-omitted": "无法定价的模型已省略,不会显示为 $0。",
|
|
3190
3311
|
"advice.caveat.holiday-calendar-stale": "内置法定节假日仅到 2027 年;此后的节假日会被按普通工作日(峰时)估算,请升级插件。",
|
|
@@ -3248,6 +3369,7 @@ window.__ModuleLoader__.load({
|
|
|
3248
3369
|
"tokener.console": "Open Tokener console",
|
|
3249
3370
|
"error.BALANCE_NOT_SUPPORTED": "This provider has no documented balance API",
|
|
3250
3371
|
"billing.reason.unknown-cache-write-price": "Cache-write pricing is not published",
|
|
3372
|
+
"billing.reason.unknown-cache-read-price": "Cache-read pricing is not published",
|
|
3251
3373
|
"dock.loading": "Loading…",
|
|
3252
3374
|
"dock.unavailable": "Temporarily unavailable",
|
|
3253
3375
|
"dock.empty": "No balance information",
|
|
@@ -3388,7 +3510,7 @@ window.__ModuleLoader__.load({
|
|
|
3388
3510
|
"advice.caveat.estimate-not-a-bill": "These figures are published-rate estimates, not an official bill. Plans, discounts, or account-specific rates can change the actual charge.",
|
|
3389
3511
|
"advice.caveat.shape-may-differ": "The next turn may not match this median, for example after compaction, a large paste, or vision input.",
|
|
3390
3512
|
"advice.caveat.stepfun-grandfathering": "The standard step-5-preview cache-hit rate is 0.70 CNY per million tokens from 2026-10-14. Accounts that already used pay-as-you-go before then may still be billed at 0.35; this plugin cannot detect that grandfathering.",
|
|
3391
|
-
"advice.caveat.tokener-snapshot": "Tokener costs use the 2026-11-
|
|
3513
|
+
"advice.caveat.tokener-snapshot": "Tokener costs use the 2026-11-28 public catalog, including official off-peak and context-tier rates where published, without vendor rates or the DeepSeek peak multiplier.",
|
|
3392
3514
|
"advice.caveat.no-priced-sample": "This session has no priced requests yet, so the next turn cannot be estimated from usage history.",
|
|
3393
3515
|
"advice.caveat.unpriced-omitted": "Models that cannot be priced are omitted rather than shown as $0.",
|
|
3394
3516
|
"advice.caveat.holiday-calendar-stale": "Built-in Chinese public holidays end in 2027; later holidays are priced as ordinary weekdays (peak). Update the plugin.",
|
|
@@ -3841,6 +3963,7 @@ window.__ModuleLoader__.load({
|
|
|
3841
3963
|
"tokener.console": "開啟 Tokener 控制台",
|
|
3842
3964
|
"error.BALANCE_NOT_SUPPORTED": "此供應商尚未公開餘額查詢介面",
|
|
3843
3965
|
"billing.reason.unknown-cache-write-price": "快取寫入價格未公開",
|
|
3966
|
+
"billing.reason.unknown-cache-read-price": "快取讀取價格未公開",
|
|
3844
3967
|
"dock.loading": "查詢中…",
|
|
3845
3968
|
"dock.unavailable": "暫時無法獲取",
|
|
3846
3969
|
"dock.empty": "暫無餘額資訊",
|
|
@@ -3981,7 +4104,7 @@ window.__ModuleLoader__.load({
|
|
|
3981
4104
|
"advice.caveat.estimate-not-a-bill": "以上為公開標準價估算,不是官方帳單;套餐、折扣或帳戶特殊價格可能導致實際扣款不同。",
|
|
3982
4105
|
"advice.caveat.shape-may-differ": "下輪實際用量可能與此中位數不同,例如上下文壓縮、大段貼上或視覺輸入。",
|
|
3983
4106
|
"advice.caveat.stepfun-grandfathering": "step-5-preview 快取命中標準價自 2026-10-14 起為 0.70 元/百萬 tokens;此前已依量呼叫的帳戶可能仍適用 0.35 元,外掛無法識別該保留價。",
|
|
3984
|
-
"advice.caveat.tokener-snapshot": "Tokener 費用依 2026-11-
|
|
4107
|
+
"advice.caveat.tokener-snapshot": "Tokener 費用依 2026-11-28 公開目錄估算,已計入官方離峰價與上下文分檔(如有);不套用原廠價格或 DeepSeek 尖離峰倍率。",
|
|
3985
4108
|
"advice.caveat.no-priced-sample": "本工作階段還沒有已計費請求,無法根據歷史用量估算下輪費用。",
|
|
3986
4109
|
"advice.caveat.unpriced-omitted": "無法定價的模型已省略,不會顯示為 $0。",
|
|
3987
4110
|
"advice.caveat.holiday-calendar-stale": "內建法定假日僅到 2027 年;此後的假日會依一般工作日(尖峰)估算,請升級外掛。",
|