@chenlongapps/opencode-token-usage 0.4.27 → 0.5.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 +5 -5
- package/README.zh-CN.md +5 -5
- package/dist/aliases.d.ts +7 -5
- package/dist/aliases.js +32 -24
- package/dist/overrides.d.ts +7 -8
- package/dist/overrides.js +20 -49
- package/dist/price-identity.d.ts +38 -0
- package/dist/price-identity.js +75 -0
- package/dist/prices.generated.d.ts +2 -3933
- package/dist/prices.generated.js +1405 -307
- package/dist/pricing.d.ts +3 -23
- package/dist/pricing.js +4 -97
- package/dist/tui.js +33 -22
- package/dist/usage.d.ts +4 -5
- package/dist/usage.js +25 -9
- package/docs/pricing.md +27 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Use it to see how many tokens a session and its subagents consume, how full the
|
|
|
27
27
|
|
|
28
28
|
- **Session-tree totals:** Track input, output, reasoning and cache tokens across the session tree, including unopened subagents, without double-counting inherited fork history.
|
|
29
29
|
- **Context visibility:** See the viewed session's context usage, latest reported request and estimated prompt composition.
|
|
30
|
-
- **Estimated cost by model:** Price recorded calls using their actual models, with
|
|
30
|
+
- **Estimated cost by model:** Price recorded calls using their actual models, with one built-in official or reference price per model/SKU as a fallback. Estimates are not provider bills.
|
|
31
31
|
- **Performance at a glance:** Monitor tokens per second (TPS), time to first token (TTFT) and the viewed session's own elapsed response time. Live TPS and elapsed-time estimates are marked with `~`.
|
|
32
32
|
- **Native terminal UI:** Keep a sidebar panel in the main session and a single-line summary in subagent views; open details only when needed.
|
|
33
33
|
- **On-demand details:** Use `/token-usage` for compact or detailed statistics, including per-model usage and rates, without sending a prompt to the model.
|
|
@@ -129,8 +129,8 @@ Costs follow the sidebar's pricing and `partial`/unavailable/free conventions. I
|
|
|
129
129
|
- `Run Time` / `Time` shows the duration and its estimate/freshness markers, without running-status text or animation. An idle parent's time never advances just because a child is active. Closing or switching views cleans up their estimates, and the shared elapsed-time ticker stops when no view needs it. Unavailable/stale timing keeps its own marker.
|
|
130
130
|
- A confirmed zero `Run Time` / `Time` is hidden in the sidebar, subagent summary/dialog and both `/token-usage` modes, without leaving an empty row or field. A nonzero live estimate makes the first turn visible even before any response has completed. Nonzero millisecond durations, unavailable values and stale timing remain visible.
|
|
131
131
|
- Runtime follows retained history: agent/model switches and compaction preserve past turns; fork copies never contribute to the fork's own time. A staged revert does not remove turns, but a committed revert deleting messages also removes their durations. Deleted historical timing cannot be reconstructed.
|
|
132
|
-
- `Est. Cost` prices
|
|
133
|
-
- The
|
|
132
|
+
- `Est. Cost` prices each message with its recorded model. Complete non-zero OpenCode prices take precedence. A verified Free SKU contributes the estimate at its paid counterpart's rate when that rate covers the call; By Model labels this `Free usage reference`, not a charge. Otherwise keep valid zero rates (except reviewed billing exceptions). Fallbacks replace the whole schedule without mixing rates or filling in missing categories.
|
|
133
|
+
- The offline snapshot is generated from [models.dev](https://models.dev/catalog.json) using verified LAB/model identities. It keeps one schedule per model or billing SKU: official non-zero prices first, then OpenRouter, Vercel AI Gateway, Amazon Bedrock and LLM Gateway in order, then the lowest other non-zero base Input + Output rate, and finally explicit zero prices. Reviewed overrides replace entire schedules. Free references are exact SKU links to existing rates, not duplicated quotes or guesses based on a suffix. No prices are downloaded or compared across providers at runtime.
|
|
134
134
|
- Confirmed free usage displays `$0.00`; positive estimates below `$0.001` display `<$0.001`, estimates through and including `$0.01` use three decimal places, and larger estimates use two. Unavailable prices display `—`; known subtotals with unpriced messages are marked `partial`. The snapshot excludes gateway markups, regional premiums, unlisted discounts, non-text billing, tool fees, and taxes, so Est. Cost is not a provider bill. See [price sources and limitations](docs/pricing.md).
|
|
135
135
|
- Live `TPS` uses a ~2s sliding window and batches deliveries within 100 ms. It starts calculating and displaying only when all three conditions hold: that response has accumulated at least 20 estimated tokens (80 UTF-8 bytes), the current window contains at least three merged batches, and those batches span at least 500 ms. The first batch counts toward the response-wide threshold but is only a speed baseline: its bytes are not counted as output generated after its timestamp. Token readiness is separate for each response, never pooled across responses or subagents. Smoothing follows elapsed time rather than delta count. Before readiness, historical TPS takes over, or the row is hidden if unavailable. After 2s without a new delta, a shared in-memory timeout expires the estimate without reading history. Resuming output after expiry starts a fresh baseline and smoothing state and must satisfy the batch/span conditions again; the same response's accumulated token count is retained.
|
|
136
136
|
- Reconnection resets live TPS windows and reconciles all tracked sessions, including offscreen sessions, with the server's active-session set. Quiet unfinished streams get a shared activity check after 60s, without reading message history. Confirmed inactive streams and their TTFT observations expire after a further 60s. Running tools, retries and pre-first-token waits have no hard lifetime; failed activity reads retain state and retry. Provider `streamed` metadata alone never means that tools have finished. Checks stop when no unfinished streams remain.
|
|
@@ -155,9 +155,9 @@ For native TTFT/TPS checks on a host with `time.firstToken`, run `npm run test:s
|
|
|
155
155
|
|
|
156
156
|
The OpenCode SDK packages are pinned to `2.3.0`, with OpenTUI `0.8.4` and Solid/compiler `1.9.16`. OpenTUI declares Node.js `>=26.4.0` for its native Node runtime, so npm reports `EBADENGINE` on Node 22; `engine-strict` installations require a Node version meeting that dependency's engine requirement. The plugin's TUI runs inside OpenCode, not as a standalone Node 22 renderer. The project's Node.js 22+ minimum is unchanged; see the [verification record](docs/verification.md) for checks of this dependency set.
|
|
157
157
|
|
|
158
|
-
The [price update workflow](.github/workflows/update-prices.yml) checks models.dev every 4 hours (or on demand via **Run workflow** on `main`). No snapshot diff means no release.
|
|
158
|
+
The [price update workflow](.github/workflows/update-prices.yml) checks models.dev every 4 hours (or on demand via **Run workflow** on `main`). No snapshot diff means no release. A change to selected prices or lookup data must pass lint, typecheck, tests, build, and pack validation before the workflow bumps the patch version (for example, `0.4.4` → `0.4.5`), commits only `src/prices.generated.ts`, `package.json`, and `package-lock.json`, and atomically pushes `main` and its version tag. The workflow creates a GitHub Release and explicitly dispatches [`publish.yml`](.github/workflows/publish.yml) on that tag to publish via npm Trusted Publishing/OIDC; no long-lived npm token is needed. GitHub Actions must be allowed to push to `main` and create tags, and npm must trust `publish.yml` with permission to run `npm publish`.
|
|
159
159
|
|
|
160
|
-
Failed validation never bumps the version. An unfinished tagged price release is retried with the same version before checking new prices; registry outages are not treated as missing versions. Publishing skips versions already on npm, prevents moving `latest` backwards, and polls registry visibility for up to 10 minutes after publication, logging progress. A verification timeout is not proof that `npm publish` failed: check the registry and retry the same tag without bumping the version; already-published versions are not republished.
|
|
160
|
+
Failed validation never bumps the version. An unfinished tagged price release is retried with the same version before checking new prices; registry outages are not treated as missing versions. Publishing skips versions already on npm, prevents moving `latest` backwards, and polls registry visibility for up to 10 minutes after publication, logging progress. A verification timeout is not proof that `npm publish` failed: check the registry and retry the same tag without bumping the version; already-published versions are not republished. Exceptional LAB-to-Provider links, exact aliases and manual price overrides require review; ordinary new models no longer need allowlist entries. See the [release guide](docs/releasing.md) for setup, verification timing, and retries.
|
|
161
161
|
|
|
162
162
|
For a manual refresh, run `npm run prices:update` in a networked environment, review the generated diff and exceptions, then run the checks above. Builds and plugin refreshes do not contact models.dev.
|
|
163
163
|
|
package/README.zh-CN.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
- **会话树用量汇总:** 统计整棵会话树的输入、输出、推理和缓存 token,包含未打开的子代理,避免重复计算分叉继承历史。
|
|
29
29
|
- **上下文可见:** 查看当前会话的上下文占用、最近一次已上报请求及提示词构成估算。
|
|
30
|
-
- **按模型估算费用:**
|
|
30
|
+
- **按模型估算费用:** 按每次调用实际使用的模型计价,回退到每个模型或计费 SKU 唯一的内置官方价或参考价。估算费用不等于提供商账单。
|
|
31
31
|
- **性能一目了然:** 查看每秒 token 数(TPS)、首 token 时间(TTFT)及当前会话自身的对话耗时。实时 TPS 与已耗时估算以 `~` 标记。
|
|
32
32
|
- **原生终端界面:** 主会话使用侧边栏,子代理视图保留单行摘要,按需打开完整面板。
|
|
33
33
|
- **按需查看详情:** 通过 `/token-usage` 切换紧凑/详细统计,查看各模型的用量与费率,不向模型发送提示词。
|
|
@@ -129,8 +129,8 @@ OpenCode **2.3.0 现已通过完整检查**,包含插件详情与原生 `/usag
|
|
|
129
129
|
- `Run Time`/`Time` 仅显示耗时及估算/未更新标记,不附加运行状态文本或动画。已空闲父会话的耗时不会因子代理活跃而增长。关闭视图或切换会话时清理相应估算,无视图需要估算时停止共享耗时 ticker。不可用/未更新的耗时仍保留各自标记。
|
|
130
130
|
- 正常状态下确认累计值为零时,侧边栏、子代理摘要/浮窗及 `/token-usage` 紧凑/详细模式均隐藏整个 `Run Time`/`Time` 项,不留空行或空字段。当前轮实时估算非零时,首轮回答尚未完成也会显示时间。非零毫秒耗时、不可用值和未更新的耗时仍保留显示。
|
|
131
131
|
- 耗时随保留历史变化:切换 agent/模型与压缩保留过去轮次;分叉继承副本不计入分叉自身耗时。暂存回退不会删除轮次,但已提交回退删除消息后,也会移除这些消息对应的耗时;已删除的历史计时无法恢复。
|
|
132
|
-
- `Est. Cost` 按每条消息记录的实际模型分别计算。OpenCode
|
|
133
|
-
-
|
|
132
|
+
- `Est. Cost` 按每条消息记录的实际模型分别计算。OpenCode 的完整非零价格优先。已确认对应付费型号的 Free SKU,按该参考价计入总额,并在 By Model 标注 `Free usage reference`,不代表实际扣费。没有完整参考价时保留有效零价(已核实的计费例外除外)。费率整条回退,不混用,也不填补缺失类别。
|
|
133
|
+
- 离线快照用 [models.dev](https://models.dev/catalog.json) 的 LAB/标准模型身份生成。每个模型或计费 SKU 只保留一套费率:原厂非零价优先,再依次查找 OpenRouter、Vercel AI Gateway、Amazon Bedrock、LLM Gateway,其次是其他 Provider 中基础 Input + Output 最低的非零价,最后才是明确的零价。人工例外整条替换。免费参考价只通过精确 SKU 关联已有费率,不复制报价,也不靠删后缀猜价。运行时不下载价格,也不在供应商之间重新选价。
|
|
134
134
|
- 确认免费时显示 `$0.00`;正费用低于 `$0.001` 时显示 `<$0.001`,不超过 `$0.01` 的费用保留三位小数,更高费用保留两位。价格不可用时显示 `—`;只有部分消息可计算时在已知小计后标注 `partial`。快照不含网关加价、区域溢价、未列明的折扣、非文本计费、工具费和税费;Est. Cost 是估算而非账单。覆盖范围、来源和限制见[价格来源与限制](docs/pricing.md)。
|
|
135
135
|
- 实时 `TPS` 使用约 2 秒滑动窗口,合并 100ms 内的增量。只有同时满足三项条件才开始计算和显示:单次响应累计至少 20 个估算 Token(80 个 UTF-8 字节)、当前窗口至少 3 个合并批次、这些批次的有效跨度至少 500ms。首批增量计入响应累计门槛,但仅作测速基线,其字节不计为该时间戳之后生成的输出。各响应独立累计,不跨响应或子代理合并门槛。平滑按经过时间而非 delta 条数推进。门槛未满足时回退到历史 TPS,没有可用历史值则隐藏该行。2 秒没有新增量时,共享的内存超时任务使估算过期,不读取历史。过期后恢复输出时,重新建立基线与平滑状态,并重新满足批次数和跨度条件;同一响应的累计 Token 数保留。
|
|
136
136
|
- 重连时重置实时 TPS 窗口,并通过服务端活动会话列表对账全部已跟踪会话,包括离屏会话。未结束的流静默 60 秒后进行共享活动检查,不读取消息历史;确认会话已停止后,再保留 60 秒并回收流及其 TTFT 观察。仍在运行的工具、重试及首 token 前等待没有硬性寿命上限;活动查询失败时保留状态并重试。仅有提供商的 `streamed` 元数据不代表工具已结束。没有未结束流时停止检查。
|
|
@@ -155,9 +155,9 @@ lint 使用 ESLint 10 Flat Config 及 JavaScript/TypeScript 推荐规则,不
|
|
|
155
155
|
|
|
156
156
|
OpenCode SDK 包精确锁定为 `2.3.0`,OpenTUI 为 `0.8.4`,Solid 与编译器为 `1.9.16`。OpenTUI 为其原生 Node 运行时声明 Node.js `>=26.4.0`,因此 Node 22 安装时 npm 会输出 `EBADENGINE`;启用 `engine-strict` 时须使用满足该依赖引擎要求的 Node 版本。插件的 TUI 在 OpenCode 内运行,并非独立的 Node 22 渲染器。项目 Node.js 22+ 的最低要求不变;该依赖组合的检查见[验证记录](docs/verification.md)。
|
|
157
157
|
|
|
158
|
-
[价格更新工作流](.github/workflows/update-prices.yml) 每 4 小时检查 models.dev,也可在 `main` 上通过 **Run workflow**
|
|
158
|
+
[价格更新工作流](.github/workflows/update-prices.yml) 每 4 小时检查 models.dev,也可在 `main` 上通过 **Run workflow** 手动触发。快照无变化就不发布。选定费率或查询数据发生变化时,先通过 lint、类型检查、测试、构建和打包检查,再自动升级 patch 版本(例如 `0.4.4` → `0.4.5`),只提交 `src/prices.generated.ts`、`package.json` 和 `package-lock.json`,并原子推送 `main` 与版本标签。工作流创建 GitHub Release,显式触发该标签上的 [`publish.yml`](.github/workflows/publish.yml),通过 npm Trusted Publishing/OIDC 发布,无需长期 npm token。仓库必须允许 GitHub Actions 推送 `main` 和创建标签;npm 必须信任 `publish.yml` 并允许执行 `npm publish`。
|
|
159
159
|
|
|
160
|
-
验证失败不会升版本。已打标签但未完成的自动价格发布会优先重试同一版本,再检查新价格;registry 故障不会被当作版本不存在。发布时跳过 npm 已有版本、防止 `latest` 倒退,并在发布后最多轮询 10 分钟核验 registry 可见性,输出进度。校验超时不代表 `npm publish` 失败:先检查 registry
|
|
160
|
+
验证失败不会升版本。已打标签但未完成的自动价格发布会优先重试同一版本,再检查新价格;registry 故障不会被当作版本不存在。发布时跳过 npm 已有版本、防止 `latest` 倒退,并在发布后最多轮询 10 分钟核验 registry 可见性,输出进度。校验超时不代表 `npm publish` 失败:先检查 registry,再重试原标签,不另升版本;已发布版本不会重复发布。特殊的 LAB 与 Provider 关联、精确别名、人工价格例外仍需审核,普通新模型无需更新白名单。配置、校验时限和重试方法见[发布说明](docs/releasing.md)。
|
|
161
161
|
|
|
162
162
|
手动更新时,在联网的维护环境运行 `npm run prices:update`,审阅生成文件及例外差异,再执行上述检查。构建和插件刷新不会请求 models.dev。
|
|
163
163
|
|
package/dist/aliases.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/** Reviewed ownership when the API's Provider ID differs from its LAB ID.
|
|
2
|
+
* These do not grant ownership of any other LAB's models hosted there. */
|
|
3
|
+
export declare const PROVIDER_LABS: ReadonlyMap<string, string>;
|
|
4
|
+
/** Exact namespacing aliases for caller-supplied model IDs, not ownership. */
|
|
5
|
+
export declare const LAB_ALIASES: ReadonlyMap<string, string>;
|
|
6
|
+
/** Reviewed compatibility spellings, only when no real SKU takes precedence.
|
|
7
|
+
* Dated/versioned SKUs with separate upstream identities are not aliases. */
|
|
6
8
|
export declare const MODEL_ALIASES: Readonly<Record<string, string>>;
|
package/dist/aliases.js
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
/** Reviewed ownership when the API's Provider ID differs from its LAB ID.
|
|
2
|
+
* These do not grant ownership of any other LAB's models hosted there. */
|
|
3
|
+
export const PROVIDER_LABS = new Map([
|
|
4
|
+
["alibaba-cn", "alibaba"],
|
|
5
|
+
["amazon-bedrock", "amazon"], // AWS develops Nova and serves it through Bedrock.
|
|
6
|
+
["arcee", "arcee-ai"],
|
|
7
|
+
["byteplus", "bytedance-seed"], // International ModelArk.
|
|
8
|
+
["google-vertex", "google"], // Vertex also relays unrelated LABs.
|
|
9
|
+
["longcat", "meituan"],
|
|
10
|
+
["minimax-cn", "minimax"],
|
|
11
|
+
["moonshotai-cn", "moonshotai"],
|
|
12
|
+
["stepfun-ai", "stepfun"],
|
|
13
|
+
["tencent-tokenhub", "tencent"],
|
|
14
|
+
["volcengine", "bytedance-seed"],
|
|
15
|
+
["zai", "zhipuai"],
|
|
16
|
+
]);
|
|
17
|
+
/** Exact namespacing aliases for caller-supplied model IDs, not ownership. */
|
|
18
|
+
export const LAB_ALIASES = new Map([
|
|
19
|
+
...PROVIDER_LABS,
|
|
20
|
+
["mistralai", "mistral"],
|
|
21
|
+
["qwen", "alibaba"],
|
|
22
|
+
["x-ai", "xai"],
|
|
23
|
+
["z-ai", "zhipuai"],
|
|
24
|
+
]);
|
|
25
|
+
/** Reviewed compatibility spellings, only when no real SKU takes precedence.
|
|
26
|
+
* Dated/versioned SKUs with separate upstream identities are not aliases. */
|
|
16
27
|
export const MODEL_ALIASES = {
|
|
17
28
|
"alibaba/qwen3.5-plus-20260420": "alibaba/qwen3.5-plus-2026-04-20",
|
|
18
29
|
"alibaba/qwen3.8-max-0902": "alibaba/qwen3.8-max",
|
|
19
|
-
"
|
|
20
|
-
"deepseek/deepseek-v4-flash": "deepseek/deepseek-v4.1-flash",
|
|
21
|
-
"deepseek/deepseek-v4-flash-0731": "deepseek/deepseek-v4.1-flash",
|
|
22
|
-
"deepseek/deepseek-v4-flash-vision-exp": "deepseek/deepseek-v4.1-flash",
|
|
23
|
-
"deepseek/deepseek-v4-pro": "deepseek/deepseek-v4-pro-0813",
|
|
30
|
+
"anthropic/claude-opus-4.7": "anthropic/claude-opus-4-7",
|
|
24
31
|
"mistral/mistral-medium-3-5": "mistral/mistral-medium-2604",
|
|
25
32
|
"mistral/mistral-medium-3-5-26-04": "mistral/mistral-medium-2604",
|
|
26
33
|
"openai/gpt-chat-latest": "openai/chat-latest",
|
|
27
|
-
"sakana/fugu-max": "sakana/fugu-max
|
|
28
|
-
"sakana/fugu-ultra-v2": "sakana/fugu-ultra-v2
|
|
34
|
+
"sakana/fugu-max-v1.0": "sakana/fugu-max",
|
|
35
|
+
"sakana/fugu-ultra-v2.0": "sakana/fugu-ultra-v2",
|
|
29
36
|
"upstage/solar-pro4-260806": "upstage/solar-pro4",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
37
|
+
"bytedance-seed/seed-2-1-turbo": "bytedance-seed/seed-2.1-turbo",
|
|
38
|
+
"bytedance-seed/dola-seed-2-1-turbo": "bytedance-seed/seed-2.1-turbo",
|
|
39
|
+
"bytedance-seed/dola-seed-2-1-turbo-260628": "bytedance-seed/seed-2.1-turbo",
|
|
32
40
|
};
|
package/dist/overrides.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { Price } from "./usage.js";
|
|
2
|
-
/** models.dev has no manufacturer-of-model field. Only these first-party
|
|
3
|
-
* catalogs and model families can supply fallback prices. A manufacturer
|
|
4
|
-
* listing somebody else's model (e.g. Alibaba's Kimi) is not its origin. */
|
|
5
|
-
export declare const ORIGINAL_PROVIDERS: Readonly<Record<string, RegExp>>;
|
|
6
2
|
export interface PriceOverride {
|
|
3
|
+
/** Provider selling this tariff; id is its exact SKU or the lab model ID. */
|
|
7
4
|
providerID: string;
|
|
8
5
|
id: string;
|
|
6
|
+
canonicalID?: string;
|
|
9
7
|
prices: readonly Price[];
|
|
10
8
|
source: string;
|
|
11
9
|
reason: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
/** Only bind this tariff to exact provider SKUs, not generic aliases. */
|
|
11
|
+
scoped?: true;
|
|
12
|
+
/** Exact OpenCode provider/SKU whose zero is a verified non-tariff. */
|
|
13
|
+
zeroException?: string;
|
|
15
14
|
}
|
|
16
15
|
/** Rates absent from the first-party models.dev listing or contradicted by a
|
|
17
16
|
* specifically verified manufacturer tariff. Never use a reseller's quote. */
|
|
@@ -19,4 +18,4 @@ export declare const OVERRIDES_VERIFIED = "2026-09-23";
|
|
|
19
18
|
export declare const PRICE_OVERRIDES: readonly PriceOverride[];
|
|
20
19
|
/** A catalog zero may mean an unmetered subscription, or that cache storage is
|
|
21
20
|
* billed by time rather than per write token. Do not invent a free write rate. */
|
|
22
|
-
export declare function
|
|
21
|
+
export declare function adjustCatalogPrice(providerID: string, price: Price): Price;
|
package/dist/overrides.js
CHANGED
|
@@ -1,40 +1,9 @@
|
|
|
1
|
-
/** models.dev has no manufacturer-of-model field. Only these first-party
|
|
2
|
-
* catalogs and model families can supply fallback prices. A manufacturer
|
|
3
|
-
* listing somebody else's model (e.g. Alibaba's Kimi) is not its origin. */
|
|
4
|
-
export const ORIGINAL_PROVIDERS = {
|
|
5
|
-
ai21: /^jamba-/i,
|
|
6
|
-
alibaba: /^(?:qwen|qwq|qvq)/i,
|
|
7
|
-
anthropic: /^claude-/i,
|
|
8
|
-
arcee: /^trinity-/i,
|
|
9
|
-
cohere: /^(?:command-|north-)/i,
|
|
10
|
-
deepseek: /^deepseek-/i,
|
|
11
|
-
google: /^(?:gemini-|gemma-|deep-research-)/i,
|
|
12
|
-
inception: /^mercury-/i,
|
|
13
|
-
longcat: /^longcat-/i,
|
|
14
|
-
meta: /^muse-/i,
|
|
15
|
-
minimax: /^minimax-/i,
|
|
16
|
-
mistral: /^(?:open-mistral-|open-mixtral-|mistral-|ministral-|magistral-|codestral-|devstral-|labs-devstral-|pixtral-|voxtral-)/i,
|
|
17
|
-
moonshotai: /^kimi-/i,
|
|
18
|
-
nvidia: /^nvidia\/(?:nemotron-|llama-[\w.-]*nemotron-)/i,
|
|
19
|
-
openai: /^(?:gpt-|o\d|chat-latest$)/i,
|
|
20
|
-
perplexity: /^sonar(?:-|$)/i,
|
|
21
|
-
sakana: /^(?:fugu|sakana-namazu)/i,
|
|
22
|
-
"stepfun-ai": /^step-/i,
|
|
23
|
-
// TokenHub's hy3 zero is a subscription-plan quote, not a token tariff;
|
|
24
|
-
// hy3 pay-as-you-go is a reviewed exception below.
|
|
25
|
-
"tencent-tokenhub": /^hy4-preview$/i,
|
|
26
|
-
upstage: /^solar-/i,
|
|
27
|
-
volcengine: /^doubao-seed-/i,
|
|
28
|
-
xai: /^grok-/i,
|
|
29
|
-
xiaomi: /^mimo-/i,
|
|
30
|
-
zai: /^glm-/i,
|
|
31
|
-
};
|
|
32
1
|
/** Rates absent from the first-party models.dev listing or contradicted by a
|
|
33
2
|
* specifically verified manufacturer tariff. Never use a reseller's quote. */
|
|
34
3
|
export const OVERRIDES_VERIFIED = "2026-09-23";
|
|
35
4
|
export const PRICE_OVERRIDES = [
|
|
36
5
|
{
|
|
37
|
-
providerID: "openai", id: "chat-latest",
|
|
6
|
+
providerID: "openai", id: "chat-latest",
|
|
38
7
|
source: "https://developers.openai.com/api/docs/pricing", reason: "Official ChatGPT API SKU missing from the first-party catalog",
|
|
39
8
|
prices: [{ input: 5, output: 30, cache: { read: 0.5 } }],
|
|
40
9
|
},
|
|
@@ -49,7 +18,9 @@ export const PRICE_OVERRIDES = [
|
|
|
49
18
|
["gpt-6-sol", 4, 20, 0.4, 5, 8, 30, 0.8, 10],
|
|
50
19
|
["gpt-6-luna", 0.2, 1, 0.02, 0.25, 0.4, 1.5, 0.04, 0.5],
|
|
51
20
|
].map(([id, input, output, read, write, longInput, longOutput, longRead, longWrite]) => ({
|
|
52
|
-
providerID: "openai", id: `${id}-fast`,
|
|
21
|
+
providerID: "openai", id: `${id}-fast`,
|
|
22
|
+
canonicalID: id === "gpt-6-astra" ? `openai/${id}-fast` : `openai/${id}:fast`,
|
|
23
|
+
...(id === "gpt-6-astra" ? {} : { scoped: true }),
|
|
53
24
|
source: "https://developers.openai.com/api/docs/pricing",
|
|
54
25
|
reason: "Published first-party Fast rate and long-context boundary (not in mode.cost)",
|
|
55
26
|
prices: [
|
|
@@ -59,13 +30,13 @@ export const PRICE_OVERRIDES = [
|
|
|
59
30
|
],
|
|
60
31
|
})),
|
|
61
32
|
{
|
|
62
|
-
providerID: "deepseek", id: "deepseek-v4.1-flash",
|
|
33
|
+
providerID: "deepseek", id: "deepseek-v4.1-flash",
|
|
63
34
|
source: "https://api-docs.deepseek.com/quick_start/pricing",
|
|
64
35
|
reason: "Peak synchronous price; the hourly billing tier is not recorded in historical messages",
|
|
65
36
|
prices: [{ input: 0.3, output: 1.2, cache: { read: 0.006 } }],
|
|
66
37
|
},
|
|
67
38
|
{
|
|
68
|
-
providerID: "deepseek", id: "deepseek-v4-pro-0813",
|
|
39
|
+
providerID: "deepseek", id: "deepseek-v4-pro-0813",
|
|
69
40
|
source: "https://api-docs.deepseek.com/quick_start/pricing",
|
|
70
41
|
reason: "Peak synchronous price; the hourly billing tier is not recorded in historical messages",
|
|
71
42
|
prices: [{ input: 1.32, output: 3.96, cache: { read: 0.044 } }],
|
|
@@ -83,7 +54,7 @@ export const PRICE_OVERRIDES = [
|
|
|
83
54
|
prices: [{ input: 1, output: 2.7, cache: { read: 0.05, write: 1 } }],
|
|
84
55
|
},
|
|
85
56
|
{
|
|
86
|
-
providerID: "tencent-tokenhub", id: "hy3",
|
|
57
|
+
providerID: "tencent-tokenhub", id: "hy3", zeroException: "tencent-tokenhub/hy3",
|
|
87
58
|
source: "https://intl.cloud.tencent.com/document/product/1300/78937",
|
|
88
59
|
reason: "Published pay-as-you-go tariff, rather than the catalog's subscription-plan zero",
|
|
89
60
|
prices: [{ input: 0.132, output: 0.528, cache: { read: 0.033 } }],
|
|
@@ -101,9 +72,9 @@ export const PRICE_OVERRIDES = [
|
|
|
101
72
|
prices: [{ input: 1.5, output: 7.5, cache: { read: 0.15 } }],
|
|
102
73
|
},
|
|
103
74
|
{
|
|
104
|
-
providerID: "alibaba", id: "qwen3.7-flash",
|
|
75
|
+
providerID: "alibaba", id: "qwen3.7-flash",
|
|
105
76
|
source: "https://www.alibabacloud.com/help/en/model-studio/model-pricing",
|
|
106
|
-
reason: "
|
|
77
|
+
reason: "Published international pay-as-you-go schedule; aggregate cache writes cannot select implicit versus explicit pricing",
|
|
107
78
|
prices: [
|
|
108
79
|
{ input: 0.03, output: 0.13, cache: { read: 0.006 } },
|
|
109
80
|
{ tier: { type: "context", size: 32_000 }, input: 0.1, output: 0.4, cache: { read: 0.02 } },
|
|
@@ -111,19 +82,19 @@ export const PRICE_OVERRIDES = [
|
|
|
111
82
|
],
|
|
112
83
|
},
|
|
113
84
|
{
|
|
114
|
-
providerID: "alibaba", id: "qwen3.8-2.4t-a95b",
|
|
85
|
+
providerID: "alibaba", id: "qwen3.8-2.4t-a95b",
|
|
115
86
|
source: "https://www.alibabacloud.com/help/en/model-studio/model-pricing",
|
|
116
87
|
reason: "Manufacturer's international tariff; this SKU is absent from the international catalog",
|
|
117
88
|
prices: [{ input: 2, output: 6 }],
|
|
118
89
|
},
|
|
119
90
|
{
|
|
120
|
-
providerID: "alibaba", id: "qwen3.8-27b",
|
|
91
|
+
providerID: "alibaba", id: "qwen3.8-27b",
|
|
121
92
|
source: "https://www.alibabacloud.com/help/en/model-studio/model-pricing",
|
|
122
93
|
reason: "Manufacturer's international tariff; this SKU is absent from the international catalog",
|
|
123
94
|
prices: [{ input: 0.5, output: 3, cache: { read: 0.1 } }],
|
|
124
95
|
},
|
|
125
96
|
{
|
|
126
|
-
providerID: "alibaba", id: "qwen3.5-plus-2026-04-20",
|
|
97
|
+
providerID: "alibaba", id: "qwen3.5-plus-2026-04-20",
|
|
127
98
|
source: "https://www.alibabacloud.com/help/en/model-studio/model-pricing",
|
|
128
99
|
reason: "Manufacturer's international tariff; this SKU is absent from the international catalog",
|
|
129
100
|
prices: [
|
|
@@ -132,13 +103,13 @@ export const PRICE_OVERRIDES = [
|
|
|
132
103
|
],
|
|
133
104
|
},
|
|
134
105
|
{
|
|
135
|
-
providerID: "
|
|
106
|
+
providerID: "byteplus", id: "dola-seed-2-1-turbo", canonicalID: "bytedance-seed/seed-2.1-turbo",
|
|
136
107
|
source: "https://docs.byteplus.com/en/docs/ModelArk/1099320",
|
|
137
108
|
reason: "BytePlus manufacturer SKU uses a different ID from the regional Volcengine catalog",
|
|
138
109
|
prices: [{ input: 0.5, output: 2.5, cache: { read: 0.1 } }],
|
|
139
110
|
},
|
|
140
111
|
{
|
|
141
|
-
providerID: "sakana", id: "fugu-ultra-v2.0",
|
|
112
|
+
providerID: "sakana", id: "fugu-ultra-v2.0", canonicalID: "sakana/fugu-ultra-v2",
|
|
142
113
|
source: "https://console.sakana.ai/pricing",
|
|
143
114
|
reason: "Manufacturer versioned SKU not present under this ID; higher tier starts at 272K",
|
|
144
115
|
prices: [
|
|
@@ -147,16 +118,16 @@ export const PRICE_OVERRIDES = [
|
|
|
147
118
|
],
|
|
148
119
|
},
|
|
149
120
|
{
|
|
150
|
-
providerID: "sakana", id: "fugu-max-v1.0",
|
|
121
|
+
providerID: "sakana", id: "fugu-max-v1.0", canonicalID: "sakana/fugu-max",
|
|
151
122
|
source: "https://console.sakana.ai/pricing",
|
|
152
123
|
reason: "Manufacturer versioned SKU absent from models.dev",
|
|
153
124
|
prices: [{ input: 2, output: 6, cache: { read: 0.25 } }],
|
|
154
125
|
},
|
|
155
126
|
...[
|
|
156
|
-
["aion-3.0",
|
|
157
|
-
["aion-3.0-mini",
|
|
158
|
-
].map(([id,
|
|
159
|
-
providerID: "aion-labs", id,
|
|
127
|
+
["aion-3.0", 3, 6, 0.75],
|
|
128
|
+
["aion-3.0-mini", 0.7, 1.4, 0.18],
|
|
129
|
+
].map(([id, input, output, read]) => ({
|
|
130
|
+
providerID: "aion-labs", id,
|
|
160
131
|
source: "https://www.aionlabs.ai/docs/models",
|
|
161
132
|
reason: "First-party hosted API price; models.dev has no Aion manufacturer provider",
|
|
162
133
|
prices: [{ input, output, cache: { read } }],
|
|
@@ -164,7 +135,7 @@ export const PRICE_OVERRIDES = [
|
|
|
164
135
|
];
|
|
165
136
|
/** A catalog zero may mean an unmetered subscription, or that cache storage is
|
|
166
137
|
* billed by time rather than per write token. Do not invent a free write rate. */
|
|
167
|
-
export function
|
|
138
|
+
export function adjustCatalogPrice(providerID, price) {
|
|
168
139
|
const ambiguousWrite = (providerID === "zai" && price.cache?.write === 0)
|
|
169
140
|
|| (providerID === "alibaba" && price.cache?.write !== undefined);
|
|
170
141
|
if (ambiguousWrite && price.cache) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ModelRef, Price } from "./usage.js";
|
|
2
|
+
export interface SnapshotPrice {
|
|
3
|
+
lab: string;
|
|
4
|
+
id: string;
|
|
5
|
+
/** Omitted when the provider's ID equals the LAB's ID. */
|
|
6
|
+
sourceProvider?: string;
|
|
7
|
+
/** Unset for an official tariff (including reviewed overrides). */
|
|
8
|
+
reference?: true;
|
|
9
|
+
prices: readonly Price[];
|
|
10
|
+
/** Source URL for a reviewed override. Otherwise the catalog URL applies. */
|
|
11
|
+
source?: string;
|
|
12
|
+
/** Synthetic billing SKUs match known provider IDs only. */
|
|
13
|
+
scoped?: true;
|
|
14
|
+
zeroException?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface PriceSnapshot {
|
|
17
|
+
verified: string;
|
|
18
|
+
source: string;
|
|
19
|
+
entries: readonly SnapshotPrice[];
|
|
20
|
+
/** LAB/SKU -> exact provider/SKU bindings; the empty key inhibits generic lookup. */
|
|
21
|
+
bindings: Readonly<Record<string, readonly string[]>>;
|
|
22
|
+
/** Paid LAB/SKU -> exact Free provider/SKUs with a verified counterpart. No rate copies. */
|
|
23
|
+
freeReferences: Readonly<Record<string, readonly string[]>>;
|
|
24
|
+
/** LAB IDs and bare IDs that must not fall through to a different LAB. */
|
|
25
|
+
labs: readonly string[];
|
|
26
|
+
ambiguous: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
export declare const priceKey: (entry: Pick<SnapshotPrice, "lab" | "id">) => string;
|
|
29
|
+
export declare const sdkModes: Set<string>;
|
|
30
|
+
/** SDK cost is attached to a model ID, not to its selectable serving modes. */
|
|
31
|
+
export declare function billingMode(model: ModelRef): string | undefined;
|
|
32
|
+
/** Shared by the generator (to omit redundant bindings) and offline lookup.
|
|
33
|
+
* These spellings never establish a price candidate's identity. */
|
|
34
|
+
export declare function defaultIdentity(entries: readonly SnapshotPrice[], labs: readonly string[], ambiguous: readonly string[]): (providerID: string, raw: string) => string | undefined;
|
|
35
|
+
/** Exact identity resolution only. There is no runtime ranking of providers. */
|
|
36
|
+
export declare function snapshotLookup(snapshot: PriceSnapshot): (model: ModelRef) => SnapshotPrice | undefined;
|
|
37
|
+
/** The reference is separate from the Free SKU's own zero schedule. */
|
|
38
|
+
export declare function snapshotFreeReferenceLookup(snapshot: PriceSnapshot): (model: ModelRef) => SnapshotPrice | undefined;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { LAB_ALIASES, MODEL_ALIASES, PROVIDER_LABS } from "./aliases.js";
|
|
2
|
+
export const priceKey = (entry) => `${entry.lab}/${entry.id}`;
|
|
3
|
+
export const sdkModes = new Set(["fast", "flex", "priority", "pro", "ultrafast"]);
|
|
4
|
+
/** SDK cost is attached to a model ID, not to its selectable serving modes. */
|
|
5
|
+
export function billingMode(model) {
|
|
6
|
+
const mode = model.variant?.toLowerCase();
|
|
7
|
+
if (!mode || !sdkModes.has(mode))
|
|
8
|
+
return undefined;
|
|
9
|
+
const id = model.id.toLowerCase();
|
|
10
|
+
return !id.endsWith(`-${mode}`) && !id.endsWith(`:${mode}`) ? mode : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** Shared by the generator (to omit redundant bindings) and offline lookup.
|
|
13
|
+
* These spellings never establish a price candidate's identity. */
|
|
14
|
+
export function defaultIdentity(entries, labs, ambiguous) {
|
|
15
|
+
const knownLabs = new Set(labs);
|
|
16
|
+
const blocked = new Set(ambiguous);
|
|
17
|
+
const keys = new Set(entries.filter(entry => !entry.scoped).map(priceKey));
|
|
18
|
+
const bare = new Map();
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
const { id, scoped } = entry;
|
|
21
|
+
if (scoped)
|
|
22
|
+
continue;
|
|
23
|
+
bare.set(id, blocked.has(id) || bare.has(id) ? null : priceKey(entry));
|
|
24
|
+
}
|
|
25
|
+
const resolve = (key) => keys.has(key) ? key
|
|
26
|
+
: Object.hasOwn(MODEL_ALIASES, key) && keys.has(MODEL_ALIASES[key]) ? MODEL_ALIASES[key] : undefined;
|
|
27
|
+
return (providerID, raw) => {
|
|
28
|
+
const id = providerID === "google-vertex" ? raw.replace(/@default$/, "") : raw;
|
|
29
|
+
const lab = PROVIDER_LABS.get(providerID) ?? providerID;
|
|
30
|
+
const slash = id.indexOf("/");
|
|
31
|
+
if (slash >= 0) {
|
|
32
|
+
const slug = id.slice(0, slash);
|
|
33
|
+
const namespace = LAB_ALIASES.get(slug) ?? slug;
|
|
34
|
+
if (knownLabs.has(lab) && lab !== namespace)
|
|
35
|
+
return undefined;
|
|
36
|
+
return resolve(`${namespace}/${id.slice(slash + 1)}`);
|
|
37
|
+
}
|
|
38
|
+
if (providerID === "amazon-bedrock") {
|
|
39
|
+
const match = /^(?:(?:us|eu|apac|global)\.)?([a-z0-9-]+)\.(.+)$/.exec(id);
|
|
40
|
+
if (match)
|
|
41
|
+
return resolve(`${LAB_ALIASES.get(match[1]) ?? match[1]}/${match[2]}`);
|
|
42
|
+
}
|
|
43
|
+
if (knownLabs.has(lab))
|
|
44
|
+
return resolve(`${lab}/${id}`);
|
|
45
|
+
return bare.get(id) ?? undefined;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Exact identity resolution only. There is no runtime ranking of providers. */
|
|
49
|
+
export function snapshotLookup(snapshot) {
|
|
50
|
+
const index = new Map(snapshot.entries.map(entry => [priceKey(entry), entry]));
|
|
51
|
+
const bindings = new Map(Object.entries(snapshot.bindings).flatMap(([key, skus]) => skus.map(sku => [sku, key])));
|
|
52
|
+
const resolve = defaultIdentity(snapshot.entries, snapshot.labs, snapshot.ambiguous);
|
|
53
|
+
return (model) => {
|
|
54
|
+
const provider = model.providerID.toLowerCase();
|
|
55
|
+
const raw = model.id.toLowerCase();
|
|
56
|
+
const sku = `${provider}/${raw}`;
|
|
57
|
+
const mode = billingMode(model);
|
|
58
|
+
if (mode) {
|
|
59
|
+
const key = bindings.get(`${sku}@mode:${mode}`);
|
|
60
|
+
return key ? index.get(key) : undefined;
|
|
61
|
+
}
|
|
62
|
+
const key = bindings.get(sku) ?? resolve(provider, raw);
|
|
63
|
+
return key ? index.get(key) : undefined;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** The reference is separate from the Free SKU's own zero schedule. */
|
|
67
|
+
export function snapshotFreeReferenceLookup(snapshot) {
|
|
68
|
+
const index = new Map(snapshot.entries.map(entry => [priceKey(entry), entry]));
|
|
69
|
+
const references = new Map(Object.entries(snapshot.freeReferences).flatMap(([key, skus]) => {
|
|
70
|
+
const rate = index.get(key);
|
|
71
|
+
return rate ? skus.map(sku => [sku, rate]) : [];
|
|
72
|
+
}));
|
|
73
|
+
return (model) => billingMode(model) ? undefined
|
|
74
|
+
: references.get(`${model.providerID.toLowerCase()}/${model.id.toLowerCase()}`);
|
|
75
|
+
}
|