@chenlongapps/opencode-token-usage 0.3.2 → 0.3.4
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 +3 -2
- package/README.zh-CN.md +3 -2
- package/ROADMAP.md +1 -0
- package/dist/pricing.d.ts +57 -1
- package/dist/pricing.js +95 -5
- package/dist/usage.d.ts +3 -2
- package/dist/usage.js +8 -4
- package/docs/pricing.md +29 -10
- package/docs/verification.md +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<a href="https://www.npmjs.com/package/@chenlongapps/opencode-token-usage" target="_blank" rel="noopener noreferrer"><img alt="npm" src="https://img.shields.io/npm/v/%40chenlongapps%2Fopencode-token-usage?style=flat-square&logo=npm" /></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/@chenlongapps/opencode-token-usage" target="_blank" rel="noopener noreferrer"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@chenlongapps/opencode-token-usage" /></a>
|
|
7
8
|
<a href="https://opencode.ai/" target="_blank" rel="noopener noreferrer"><img alt="OpenCode 2" src="https://img.shields.io/badge/OpenCode-2-5A67D8?style=flat-square" /></a>
|
|
8
9
|
<a href="https://github.com/chenlongapps/opencode-token-usage/actions/workflows/ci.yml" target="_blank" rel="noopener noreferrer"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/chenlongapps/opencode-token-usage/ci.yml?style=flat-square&branch=main&label=ci" /></a>
|
|
9
10
|
<a href="LICENSE" target="_blank" rel="noopener noreferrer"><img alt="MIT License" src="https://img.shields.io/badge/license-MIT-yellow?style=flat-square" /></a>
|
|
@@ -60,8 +61,8 @@ For remote sessions, add the package name to `plugins` in your local `~/.config/
|
|
|
60
61
|
- A fork is a separate session tree. Inherited message copies are attributed only to their original source to prevent double counting.
|
|
61
62
|
- `Context` only searches messages after the most recent compaction with `status === "completed"` and is hidden when reliable usage or a model context limit is unavailable.
|
|
62
63
|
- `Steps` counts every assistant message in the tree, whether or not it reported usage, and reuses the fork-copy de-duplication so inherited history is never counted twice.
|
|
63
|
-
- `Cost` prices every message with its recorded model. A complete
|
|
64
|
-
- Gateway models can use
|
|
64
|
+
- `Cost` prices every message with its recorded model. A complete non-zero price resolved by OpenCode takes precedence. If OpenCode reports a complete zero price, a complete official snapshot price overrides it; incomplete prices fall back for the whole message without mixing rates.
|
|
65
|
+
- Gateway models can use fallback prices through exact model IDs, documented aliases, and known wrappers. A terminal `-free` or `:free` is removed only for an exact base ID lookup; other suffixes are not stripped. The fallback excludes gateway markups, regional premiums, unlisted discounts, tool fees, and taxes, so Cost is an estimate rather than a provider bill.
|
|
65
66
|
- Confirmed free usage displays `$0.00`; unavailable prices display `—`; known subtotals with unpriced messages are marked `partial`. See the [built-in price snapshot](docs/pricing.md) for coverage, sources, and limitations.
|
|
66
67
|
- Initial read failures display `Unavailable`. Later failures retain the last complete snapshot, display `Not updated`, and retry automatically.
|
|
67
68
|
|
package/README.zh-CN.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<a href="https://www.npmjs.com/package/@chenlongapps/opencode-token-usage" target="_blank" rel="noopener noreferrer"><img alt="npm" src="https://img.shields.io/npm/v/%40chenlongapps%2Fopencode-token-usage?style=flat-square&logo=npm" /></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/@chenlongapps/opencode-token-usage" target="_blank" rel="noopener noreferrer"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@chenlongapps/opencode-token-usage" /></a>
|
|
7
8
|
<a href="https://opencode.ai/" target="_blank" rel="noopener noreferrer"><img alt="OpenCode 2" src="https://img.shields.io/badge/OpenCode-2-5A67D8?style=flat-square" /></a>
|
|
8
9
|
<a href="https://github.com/chenlongapps/opencode-token-usage/actions/workflows/ci.yml" target="_blank" rel="noopener noreferrer"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/chenlongapps/opencode-token-usage/ci.yml?style=flat-square&branch=main&label=ci" /></a>
|
|
9
10
|
<a href="LICENSE" target="_blank" rel="noopener noreferrer"><img alt="MIT License" src="https://img.shields.io/badge/license-MIT-yellow?style=flat-square" /></a>
|
|
@@ -60,8 +61,8 @@ opencode plugin add @chenlongapps/opencode-token-usage
|
|
|
60
61
|
- 分叉会话是独立会话树。继承消息副本只归原始来源,避免重复计费。
|
|
61
62
|
- `Context` 仅搜索最后一次 `status === "completed"` 的 compaction 之后;没有可靠用量或模型上限时隐藏。
|
|
62
63
|
- `Steps` 统计树中全部 assistant 消息,无论是否已上报用量;复用分叉副本去重,继承历史不会重复计数。
|
|
63
|
-
- `Cost` 按每条消息记录的实际模型分别计算。OpenCode
|
|
64
|
-
-
|
|
64
|
+
- `Cost` 按每条消息记录的实际模型分别计算。OpenCode 当前解析出的完整非零价格优先;若 OpenCode 给出完整零价,且内置价格快照可以完整计价,则采用快照价格。价格不完整时整条消息回退,不混用两套费率。
|
|
65
|
+
- 网关模型通过精确模型 ID、明确别名和已知包装格式匹配;也会尝试移除终尾 `-free` 或 `:free` 后精确查找基础 ID,其他后缀不会剥离。快照不包含网关加价、区域溢价、未列明的折扣、工具费和税费,因此 Cost 是估算而非提供商账单。
|
|
65
66
|
- 确认免费时显示 `$0.00`;价格不可用时显示 `—`;只有部分消息可计算时在已知小计后标注 `partial`。覆盖范围、来源和限制见[内置官方价格快照](docs/pricing.md)。
|
|
66
67
|
- 首次读取失败显示 `Unavailable`;后续失败保留上次完整快照、标注 `Not updated` 并自动重试。
|
|
67
68
|
|
package/ROADMAP.md
CHANGED
package/dist/pricing.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ export interface OfficialPriceEntry {
|
|
|
6
6
|
released: string;
|
|
7
7
|
/** Exact alternate IDs used by supported gateways or manufacturer aliases. */
|
|
8
8
|
aliases?: readonly string[];
|
|
9
|
-
/**
|
|
9
|
+
/** Provider IDs where this rate is available, when it is not a general model rate. */
|
|
10
|
+
providers?: readonly string[];
|
|
11
|
+
/** Published API token rates in USD per million tokens. */
|
|
10
12
|
prices: readonly Price[];
|
|
11
13
|
/** Manufacturer pricing page used to verify the rates. */
|
|
12
14
|
source: string;
|
|
@@ -36,6 +38,29 @@ export declare const OFFICIAL_PRICE_SNAPSHOT: {
|
|
|
36
38
|
read: number;
|
|
37
39
|
};
|
|
38
40
|
})[];
|
|
41
|
+
providers?: never;
|
|
42
|
+
aliases?: never;
|
|
43
|
+
} | {
|
|
44
|
+
id: string;
|
|
45
|
+
providers: string[];
|
|
46
|
+
released: string;
|
|
47
|
+
source: string;
|
|
48
|
+
prices: ({
|
|
49
|
+
input: number;
|
|
50
|
+
output: number;
|
|
51
|
+
cache: {
|
|
52
|
+
read: number;
|
|
53
|
+
};
|
|
54
|
+
tier?: never;
|
|
55
|
+
} | {
|
|
56
|
+
tier: {
|
|
57
|
+
type: "context";
|
|
58
|
+
size: number;
|
|
59
|
+
};
|
|
60
|
+
input?: never;
|
|
61
|
+
output?: never;
|
|
62
|
+
cache?: never;
|
|
63
|
+
})[];
|
|
39
64
|
aliases?: never;
|
|
40
65
|
} | {
|
|
41
66
|
id: string;
|
|
@@ -53,9 +78,37 @@ export declare const OFFICIAL_PRICE_SNAPSHOT: {
|
|
|
53
78
|
input: number;
|
|
54
79
|
output: number;
|
|
55
80
|
})[];
|
|
81
|
+
providers?: never;
|
|
82
|
+
aliases?: never;
|
|
83
|
+
} | {
|
|
84
|
+
id: string;
|
|
85
|
+
released: string;
|
|
86
|
+
source: string;
|
|
87
|
+
prices: ({
|
|
88
|
+
input: number;
|
|
89
|
+
output: number;
|
|
90
|
+
cache: {
|
|
91
|
+
read: number;
|
|
92
|
+
write: number;
|
|
93
|
+
};
|
|
94
|
+
tier?: never;
|
|
95
|
+
} | {
|
|
96
|
+
tier: {
|
|
97
|
+
type: "context";
|
|
98
|
+
size: number;
|
|
99
|
+
};
|
|
100
|
+
input: number;
|
|
101
|
+
output: number;
|
|
102
|
+
cache: {
|
|
103
|
+
read: number;
|
|
104
|
+
write: number;
|
|
105
|
+
};
|
|
106
|
+
})[];
|
|
107
|
+
providers?: never;
|
|
56
108
|
aliases?: never;
|
|
57
109
|
} | {
|
|
58
110
|
id: string;
|
|
111
|
+
providers: string[];
|
|
59
112
|
released: string;
|
|
60
113
|
source: string;
|
|
61
114
|
prices: ({
|
|
@@ -92,6 +145,7 @@ export declare const OFFICIAL_PRICE_SNAPSHOT: {
|
|
|
92
145
|
write: number;
|
|
93
146
|
};
|
|
94
147
|
}[];
|
|
148
|
+
providers?: never;
|
|
95
149
|
} | {
|
|
96
150
|
id: string;
|
|
97
151
|
aliases: string[];
|
|
@@ -109,6 +163,7 @@ export declare const OFFICIAL_PRICE_SNAPSHOT: {
|
|
|
109
163
|
input: number;
|
|
110
164
|
output: number;
|
|
111
165
|
})[];
|
|
166
|
+
providers?: never;
|
|
112
167
|
} | {
|
|
113
168
|
id: string;
|
|
114
169
|
aliases: string[];
|
|
@@ -132,6 +187,7 @@ export declare const OFFICIAL_PRICE_SNAPSHOT: {
|
|
|
132
187
|
read: number;
|
|
133
188
|
};
|
|
134
189
|
})[];
|
|
190
|
+
providers?: never;
|
|
135
191
|
})[];
|
|
136
192
|
};
|
|
137
193
|
/**
|
package/dist/pricing.js
CHANGED
|
@@ -2,7 +2,7 @@ export const OFFICIAL_PRICE_SNAPSHOT = {
|
|
|
2
2
|
verified: "2026-09-23",
|
|
3
3
|
newModelCutoff: "2026-03-22",
|
|
4
4
|
entries: [
|
|
5
|
-
// OpenAI
|
|
5
|
+
// OpenAI API rates. Tier sizes are exclusive thresholds, so
|
|
6
6
|
// 272,000 implements the official ">272K input tokens" boundary.
|
|
7
7
|
{
|
|
8
8
|
id: "gpt-5.5", released: "2026-04-23", source: "https://developers.openai.com/api/docs/pricing",
|
|
@@ -11,6 +11,14 @@ export const OFFICIAL_PRICE_SNAPSHOT = {
|
|
|
11
11
|
{ tier: { type: "context", size: 272_000 }, input: 10, output: 45, cache: { read: 1 } },
|
|
12
12
|
],
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
id: "gpt-5.5-fast", providers: ["openai"], released: "2026-04-23", source: "https://developers.openai.com/api/docs/pricing",
|
|
16
|
+
prices: [
|
|
17
|
+
{ input: 12.5, output: 75, cache: { read: 1.25 } },
|
|
18
|
+
// OpenAI publishes no Fast rate for GPT-5.5 above 272K input tokens.
|
|
19
|
+
{ tier: { type: "context", size: 272_000 } },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
14
22
|
{
|
|
15
23
|
id: "gpt-5.5-pro", released: "2026-04-23", source: "https://developers.openai.com/api/docs/pricing",
|
|
16
24
|
prices: [
|
|
@@ -60,6 +68,50 @@ export const OFFICIAL_PRICE_SNAPSHOT = {
|
|
|
60
68
|
{ tier: { type: "context", size: 272_000 }, input: 0.2, output: 0.75, cache: { read: 0.02, write: 0.25 } },
|
|
61
69
|
],
|
|
62
70
|
},
|
|
71
|
+
{
|
|
72
|
+
// OpenAI Fast processing is a separate exact ID and restricted to the
|
|
73
|
+
// first-party provider so ordinary or gateway model IDs keep standard rates.
|
|
74
|
+
id: "gpt-6-luna-fast", providers: ["openai"], released: "2026-09-22", source: "https://developers.openai.com/api/docs/pricing",
|
|
75
|
+
prices: [
|
|
76
|
+
{ input: 0.2, output: 1, cache: { read: 0.02, write: 0.25 } },
|
|
77
|
+
{ tier: { type: "context", size: 272_000 }, input: 0.4, output: 1.5, cache: { read: 0.04, write: 0.5 } },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "gpt-5.6-sol-fast", providers: ["openai"], released: "2026-07-09", source: "https://developers.openai.com/api/docs/pricing",
|
|
82
|
+
prices: [
|
|
83
|
+
{ input: 8, output: 40, cache: { read: 0.8, write: 10 } },
|
|
84
|
+
{ tier: { type: "context", size: 272_000 }, input: 16, output: 60, cache: { read: 1.6, write: 20 } },
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "gpt-5.6-terra-fast", providers: ["openai"], released: "2026-07-09", source: "https://developers.openai.com/api/docs/pricing",
|
|
89
|
+
prices: [
|
|
90
|
+
{ input: 4, output: 24, cache: { read: 0.4, write: 5 } },
|
|
91
|
+
{ tier: { type: "context", size: 272_000 }, input: 8, output: 36, cache: { read: 0.8, write: 10 } },
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "gpt-5.6-luna-fast", providers: ["openai"], released: "2026-07-09", source: "https://developers.openai.com/api/docs/pricing",
|
|
96
|
+
prices: [
|
|
97
|
+
{ input: 0.4, output: 2.4, cache: { read: 0.04, write: 0.5 } },
|
|
98
|
+
{ tier: { type: "context", size: 272_000 }, input: 0.8, output: 3.6, cache: { read: 0.08, write: 1 } },
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "gpt-6-astra-fast", providers: ["openai"], released: "2026-09-04", source: "https://developers.openai.com/api/docs/pricing",
|
|
103
|
+
prices: [
|
|
104
|
+
{ input: 20, output: 100, cache: { read: 2, write: 25 } },
|
|
105
|
+
{ tier: { type: "context", size: 272_000 }, input: 40, output: 150, cache: { read: 4, write: 50 } },
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "gpt-6-sol-fast", providers: ["openai"], released: "2026-09-22", source: "https://developers.openai.com/api/docs/pricing",
|
|
110
|
+
prices: [
|
|
111
|
+
{ input: 4, output: 20, cache: { read: 0.4, write: 5 } },
|
|
112
|
+
{ tier: { type: "context", size: 272_000 }, input: 8, output: 30, cache: { read: 0.8, write: 10 } },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
63
115
|
// The official ChatGPT SKU `chat-latest`. OpenRouter serves it under the
|
|
64
116
|
// slug `openai/gpt-chat-latest`, which is registered as an exact alias.
|
|
65
117
|
{
|
|
@@ -89,6 +141,20 @@ export const OFFICIAL_PRICE_SNAPSHOT = {
|
|
|
89
141
|
id: "claude-opus-5", released: "2026-07-24", source: "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
90
142
|
prices: [{ input: 5, output: 25, cache: { read: 0.5, write: 6.25 } }],
|
|
91
143
|
},
|
|
144
|
+
{
|
|
145
|
+
// Fast mode is first-party Claude API only. Cache multipliers apply to
|
|
146
|
+
// the Fast input price; aggregate cache writes use the 5-minute rate.
|
|
147
|
+
id: "claude-opus-5-fast", providers: ["anthropic"], released: "2026-07-24", source: "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
148
|
+
prices: [{ input: 10, output: 50, cache: { read: 1, write: 12.5 } }],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: "claude-opus-4-8-fast", providers: ["anthropic"], released: "2026-05-28", source: "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
152
|
+
prices: [{ input: 10, output: 50, cache: { read: 1, write: 12.5 } }],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
id: "claude-opus-5-5-fast", providers: ["anthropic"], released: "2026-09-22", source: "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
156
|
+
prices: [{ input: 8, output: 40, cache: { read: 0.4, write: 10 } }],
|
|
157
|
+
},
|
|
92
158
|
{
|
|
93
159
|
id: "claude-fable-5-1", aliases: ["claude-fable-5.1"], released: "2026-09-01",
|
|
94
160
|
source: "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
@@ -175,9 +241,7 @@ export const OFFICIAL_PRICE_SNAPSHOT = {
|
|
|
175
241
|
source: "https://cohere.com/pricing",
|
|
176
242
|
prices: [{ input: 2.5, output: 10 }],
|
|
177
243
|
},
|
|
178
|
-
// Meta Model API standard-tier rates.
|
|
179
|
-
// discounted program that permits training on prompts and completions, so
|
|
180
|
-
// it is intentionally not part of the standard snapshot.
|
|
244
|
+
// Meta Model API standard-tier rates.
|
|
181
245
|
{
|
|
182
246
|
id: "muse-spark-1.1", released: "2026-07-09", source: "https://ai.developer.meta.com/docs/pricing-rate-limits",
|
|
183
247
|
prices: [{ input: 1.25, output: 4.25, cache: { read: 0.15 } }],
|
|
@@ -190,6 +254,17 @@ export const OFFICIAL_PRICE_SNAPSHOT = {
|
|
|
190
254
|
id: "muse-spark-1.3", released: "2026-09-02", source: "https://ai.developer.meta.com/docs/pricing-rate-limits",
|
|
191
255
|
prices: [{ input: 1.25, output: 4.25, cache: { read: 0.15 } }],
|
|
192
256
|
},
|
|
257
|
+
// Meta Contributor rates are conditional on allowing Meta to use prompts
|
|
258
|
+
// and completions for training. OpenCode's contributor-free model IDs
|
|
259
|
+
// resolve here after removing their terminal -free suffix.
|
|
260
|
+
{
|
|
261
|
+
id: "muse-spark-1.2-contributor", released: "2026-08-05", source: "https://ai.developer.meta.com/docs/pricing-rate-limits",
|
|
262
|
+
prices: [{ input: 0.1, output: 0.2, cache: { read: 0.002 } }],
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: "muse-spark-1.3-contributor", released: "2026-09-02", source: "https://ai.developer.meta.com/docs/pricing-rate-limits",
|
|
266
|
+
prices: [{ input: 0.1, output: 0.2, cache: { read: 0.002 } }],
|
|
267
|
+
},
|
|
193
268
|
// Inception's current Mercury 2.5 API page shows an 80% launch discount;
|
|
194
269
|
// the snapshot records the billed standard-platform rates on verification
|
|
195
270
|
// day rather than the crossed-out list prices. No cache-write token rate is
|
|
@@ -493,10 +568,25 @@ export function officialPrice(model) {
|
|
|
493
568
|
const dot = id.lastIndexOf(".");
|
|
494
569
|
if (dot >= 0)
|
|
495
570
|
candidates.push(id.slice(dot + 1));
|
|
496
|
-
|
|
571
|
+
const available = (candidate) => {
|
|
497
572
|
const entry = index.get(candidate);
|
|
573
|
+
return entry && (!entry.providers || entry.providers.some(provider => provider.toLowerCase() === model.providerID.toLowerCase()))
|
|
574
|
+
? entry
|
|
575
|
+
: undefined;
|
|
576
|
+
};
|
|
577
|
+
for (const candidate of candidates) {
|
|
578
|
+
const entry = available(candidate);
|
|
498
579
|
if (entry)
|
|
499
580
|
return entry;
|
|
500
581
|
}
|
|
582
|
+
for (const candidate of candidates) {
|
|
583
|
+
for (const suffix of ["-free", ":free"]) {
|
|
584
|
+
if (!candidate.endsWith(suffix))
|
|
585
|
+
continue;
|
|
586
|
+
const entry = available(candidate.slice(0, -suffix.length));
|
|
587
|
+
if (entry)
|
|
588
|
+
return entry;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
501
591
|
return undefined;
|
|
502
592
|
}
|
package/dist/usage.d.ts
CHANGED
|
@@ -83,8 +83,9 @@ export declare function estimate(tokens: Tokens, prices?: readonly Price[]): {
|
|
|
83
83
|
defaultPrice: boolean;
|
|
84
84
|
};
|
|
85
85
|
export type CostStatus = "empty" | "complete" | "partial" | "unavailable";
|
|
86
|
-
/** Prices every call with its recorded model.
|
|
87
|
-
*
|
|
86
|
+
/** Prices every call with its recorded model. A complete non-zero OpenCode
|
|
87
|
+
* price wins; a complete snapshot price can replace a complete OpenCode zero.
|
|
88
|
+
* Incomplete OpenCode prices fall back to the snapshot as a whole. */
|
|
88
89
|
export declare function summarize(messages: Iterable<UsageMessage>, catalog?: PriceCatalog): {
|
|
89
90
|
tokens: Tokens;
|
|
90
91
|
total: number;
|
package/dist/usage.js
CHANGED
|
@@ -22,8 +22,9 @@ export function estimate(tokens, prices = []) {
|
|
|
22
22
|
&& (rate === undefined || !Number.isFinite(rate) || rate < 0))),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
/** Prices every call with its recorded model.
|
|
26
|
-
*
|
|
25
|
+
/** Prices every call with its recorded model. A complete non-zero OpenCode
|
|
26
|
+
* price wins; a complete snapshot price can replace a complete OpenCode zero.
|
|
27
|
+
* Incomplete OpenCode prices fall back to the snapshot as a whole. */
|
|
27
28
|
export function summarize(messages, catalog = new Map()) {
|
|
28
29
|
const tokens = normalize();
|
|
29
30
|
let cost = 0;
|
|
@@ -50,8 +51,11 @@ export function summarize(messages, catalog = new Map()) {
|
|
|
50
51
|
continue;
|
|
51
52
|
}
|
|
52
53
|
let value = estimate(t, catalog.get(modelKey(message.model)));
|
|
53
|
-
if (value.defaultPrice)
|
|
54
|
-
|
|
54
|
+
if (value.defaultPrice || value.cost === 0) {
|
|
55
|
+
const snapshot = estimate(t, officialPrice(message.model)?.prices);
|
|
56
|
+
if (!snapshot.defaultPrice)
|
|
57
|
+
value = snapshot;
|
|
58
|
+
}
|
|
55
59
|
if (value.defaultPrice)
|
|
56
60
|
missingCosts++;
|
|
57
61
|
else {
|
package/docs/pricing.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# 内置官方价格快照
|
|
2
2
|
|
|
3
|
-
插件自 v0.3.0 起,在 OpenCode
|
|
3
|
+
插件自 v0.3.0 起,在 OpenCode 当前模型目录没有可用于某条消息的完整价格时,使用本页所列的公开 API 价格补全。若 OpenCode 给出完整零价,而快照能完整计价,则使用快照价格。快照核验于 **2026-09-23**,共收录 86 个模型,金额均为美元 / 100 万 token。
|
|
4
4
|
|
|
5
5
|
## 规则
|
|
6
6
|
|
|
7
7
|
- 每条 assistant 与 compaction 消息按自身记录的 `providerID`、模型 ID 和 token 用量分别计算。
|
|
8
|
-
- OpenCode
|
|
9
|
-
- 网关模型只通过精确厂商 ID、精确别名及已知包装格式匹配,例如 `openai/gpt-5.6-luna`、`us.anthropic.claude-opus-5` 和 `claude-opus-5@default
|
|
10
|
-
- 目录首版只新增 2026-03-22 至 2026-09-22
|
|
11
|
-
-
|
|
8
|
+
- OpenCode 当前解析出的完整适用非零价格优先。若完整适用价格为零,则尝试使用内置价格;只有快照能完整覆盖该消息实际使用的 token 类别时才覆盖零价,否则保留 OpenCode 的零价。OpenCode 价格不完整时,整条消息回退到内置价格,不混用两套费率。
|
|
9
|
+
- 网关模型只通过精确厂商 ID、精确别名及已知包装格式匹配,例如 `openai/gpt-5.6-luna`、`us.anthropic.claude-opus-5` 和 `claude-opus-5@default`。匹配这些现有形式后,也会尝试仅移除模型 ID 的末尾 `-free` 或 `:free` 再精确匹配基础 ID,例如 `mimo-v2.6-flash-free`、`meta/muse-spark-1.3:free` 和 `muse-spark-1.3-contributor-free`;`-pro`、`-fast`、`-free-preview` 等其他后缀不会剥离。单独列出的 Fast 型号仅按完整 ID 和厂商支持的 provider 精确匹配,不会回退到标准费率。不按相似名称猜测。
|
|
10
|
+
- 目录首版只新增 2026-03-22 至 2026-09-22 发布、具有明确 token 费率的模型。后续版本只限制新增窗口,已经收录的条目不会因超过半年而自动删除。
|
|
11
|
+
- 采用同步 API 的公开价;Meta Contributor 条件价按单独标注的来源记录。仅收录下表明确列出的 Fast 型号,不含 Batch、Flex、其他 Fast/Priority、区域溢价、网关加价、企业折扣、工具费和税费,因此 Cost 仍是估算,不代表账单。
|
|
12
12
|
- 任一有用量消息仍无法定价时,已知小计标记 `partial`;全部无法定价时显示 `—`。明确零价才显示 `$0.00`。
|
|
13
13
|
- 促销价按核验日官网显示的费率收录(如 `gpt-5.6-sol`、MiniMax-M3 的"长期 5 折"标价),不用划线原价。
|
|
14
14
|
|
|
@@ -19,16 +19,23 @@
|
|
|
19
19
|
| 模型 | 发布日期 | Input | Output | Cache Read | Cache Write | 长上下文档位 |
|
|
20
20
|
| --- | --- | ---: | ---: | ---: | ---: | --- |
|
|
21
21
|
| `gpt-5.5` | 2026-04-23 | 5 | 30 | 0.5 | — | >272K:10 / 45 / 1 / — |
|
|
22
|
+
| `gpt-5.5-fast`(Fast) | 2026-04-23 | 12.5 | 75 | 1.25 | — | >272K:无官方 Fast 费率 |
|
|
22
23
|
| `gpt-5.5-pro` | 2026-04-23 | 30 | 180 | — | — | >272K:60 / 270 / — / — |
|
|
23
24
|
| `gpt-5.6-sol` | 2026-07-09 | 4 | 20 | 0.4 | 5 | >272K:8 / 30 / 0.8 / 10 |
|
|
25
|
+
| `gpt-5.6-sol-fast`(Fast) | 2026-07-09 | 8 | 40 | 0.8 | 10 | >272K:16 / 60 / 1.6 / 20 |
|
|
24
26
|
| `gpt-5.6-terra` | 2026-07-09 | 2 | 12 | 0.2 | 2.5 | >272K:4 / 18 / 0.4 / 5 |
|
|
27
|
+
| `gpt-5.6-terra-fast`(Fast) | 2026-07-09 | 4 | 24 | 0.4 | 5 | >272K:8 / 36 / 0.8 / 10 |
|
|
25
28
|
| `gpt-5.6-luna` | 2026-07-09 | 0.2 | 1.2 | 0.02 | 0.25 | >272K:0.4 / 1.8 / 0.04 / 0.5 |
|
|
29
|
+
| `gpt-5.6-luna-fast`(Fast) | 2026-07-09 | 0.4 | 2.4 | 0.04 | 0.5 | >272K:0.8 / 3.6 / 0.08 / 1 |
|
|
26
30
|
| `gpt-6-astra` | 2026-09-04 | 10 | 50 | 1 | 12.5 | >272K:20 / 75 / 2 / 25 |
|
|
31
|
+
| `gpt-6-astra-fast`(Fast) | 2026-09-04 | 20 | 100 | 2 | 25 | >272K:40 / 150 / 4 / 50 |
|
|
27
32
|
| `gpt-6-sol` | 2026-09-22 | 2 | 10 | 0.2 | 2.5 | >272K:4 / 15 / 0.4 / 5 |
|
|
33
|
+
| `gpt-6-sol-fast`(Fast) | 2026-09-22 | 4 | 20 | 0.4 | 5 | >272K:8 / 30 / 0.8 / 10 |
|
|
28
34
|
| `gpt-6-luna` | 2026-09-22 | 0.1 | 0.5 | 0.01 | 0.125 | >272K:0.2 / 0.75 / 0.02 / 0.25 |
|
|
35
|
+
| `gpt-6-luna-fast`(Fast) | 2026-09-22 | 0.2 | 1 | 0.02 | 0.25 | >272K:0.4 / 1.5 / 0.04 / 0.5 |
|
|
29
36
|
| `chat-latest`(别名 `gpt-chat-latest`) | 2026-05-05 | 5 | 30 | 0.5 | — | — |
|
|
30
37
|
|
|
31
|
-
`gpt-6-sol` 和 `gpt-6-luna` 的发布日期见 [OpenAI API 更新日志](https://developers.openai.com/api/docs/changelog)。表内 OpenAI 长上下文价格在传入 token 超过 272,000
|
|
38
|
+
`gpt-6-sol` 和 `gpt-6-luna` 的发布日期见 [OpenAI API 更新日志](https://developers.openai.com/api/docs/changelog)。表内 OpenAI 长上下文价格在传入 token 超过 272,000 时对整条请求生效。Fast 条目对应官方 Fast processing 费率;API 通过基础模型配合 `service_tier: "fast"` 选择该档,因此只有以对应 `-fast` ID 记录的 OpenAI 消息使用 Fast 价格,其他 provider 不匹配这些条目。官方未公布 `gpt-5.5` Fast 长上下文费率,故超过 272,000 个传入 token 时标记为不可估价,不沿用短上下文价。`gpt-5.6-sol` 的当前标准价是限期促销价;快照采用核验日官网显示的费率。`chat-latest` 是官方 ChatGPT SKU,OpenRouter 上的 `gpt-chat-latest` 作为精确别名指向同一条目。
|
|
32
39
|
|
|
33
40
|
## Anthropic
|
|
34
41
|
|
|
@@ -38,16 +45,21 @@
|
|
|
38
45
|
| --- | --- | ---: | ---: | ---: | ---: |
|
|
39
46
|
| `claude-opus-4-7` | 2026-04-14 | 5 | 25 | 0.5 | 6.25 |
|
|
40
47
|
| `claude-opus-4-8` | 2026-05-28 | 5 | 25 | 0.5 | 6.25 |
|
|
48
|
+
| `claude-opus-4-8-fast`(Fast) | 2026-05-28 | 10 | 50 | 1 | 12.5 |
|
|
41
49
|
| `claude-fable-5` | 2026-06-07 | 10 | 50 | 1 | 12.5 |
|
|
42
50
|
| `claude-sonnet-5` | 2026-06-29 | 2 | 10 | 0.2 | 2.5 |
|
|
43
51
|
| `claude-opus-5` | 2026-07-24 | 5 | 25 | 0.5 | 6.25 |
|
|
52
|
+
| `claude-opus-5-fast`(Fast) | 2026-07-24 | 10 | 50 | 1 | 12.5 |
|
|
44
53
|
| `claude-fable-5-1` | 2026-09-01 | 10 | 50 | 0.25 | 12.5 |
|
|
45
54
|
| `claude-opus-5-5` | 2026-09-22 | 4 | 20 | 0.2 | 5 |
|
|
55
|
+
| `claude-opus-5-5-fast`(Fast) | 2026-09-22 | 8 | 40 | 0.4 | 10 |
|
|
46
56
|
|
|
47
57
|
Cache Write 采用官方 5 分钟写入价。OpenCode 的聚合字段不区分 5 分钟与 1 小时 TTL,无法从历史消息可靠应用 1 小时写入价。OpenRouter 的 `claude-opus-4.7`、`claude-opus-4.8`、`claude-opus-5.5` 圆点写法注册为对应条目的精确别名。
|
|
48
58
|
|
|
49
59
|
`claude-opus-5-5` 的 Cache Read 是官方 0.05 倍基础输入价的特殊乘率(多数 Claude 模型为 0.1 倍),按官方标价 $0.20 / M 收录。
|
|
50
60
|
|
|
61
|
+
表中 Claude Fast 条目仅适用于 Claude API 一方。Fast mode 的 Cache Read 和 5 分钟 Cache Write 分别按 Fast 输入价乘以官方缓存倍率计算;OpenCode 聚合的 Cache Write 无法区分 TTL,因此按 5 分钟写入价估算。Opus 5.5 的 Cache Read 为 Fast 输入价的 0.05 倍,其余表列 Fast 型号为 0.1 倍。
|
|
62
|
+
|
|
51
63
|
## Google
|
|
52
64
|
|
|
53
65
|
来源:[Gemini Developer API Pricing](https://ai.google.dev/gemini-api/docs/pricing)
|
|
@@ -199,7 +211,14 @@ Step 5 Preview 官方明确说明 cache-miss Input 包含首次缓存写入,
|
|
|
199
211
|
| `muse-spark-1.2` | 2026-08-05 | 1.25 | 4.25 | 0.15 |
|
|
200
212
|
| `muse-spark-1.3` | 2026-09-02 | 1.25 | 4.25 | 0.15 |
|
|
201
213
|
|
|
202
|
-
|
|
214
|
+
Contributor tier 以允许 Meta 使用提示词和回答进行训练为条件,按独立 tier 记录。官方没有公布 cache write token 价。
|
|
215
|
+
|
|
216
|
+
| Contributor 模型 | 发布日期 | Input | Output | Cache Read | Cache Write |
|
|
217
|
+
| --- | --- | ---: | ---: | ---: | ---: |
|
|
218
|
+
| `muse-spark-1.2-contributor` | 2026-08-05 | 0.10 | 0.20 | 0.002 | — |
|
|
219
|
+
| `muse-spark-1.3-contributor` | 2026-09-02 | 0.10 | 0.20 | 0.002 | — |
|
|
220
|
+
|
|
221
|
+
OpenCode Zen 的 `muse-spark-1.2-contributor-free` 和 `muse-spark-1.3-contributor-free` 会精确匹配各自 Contributor 条目;Cost 因此按 Meta Contributor 费率估算。
|
|
203
222
|
|
|
204
223
|
## Inception
|
|
205
224
|
|
|
@@ -277,8 +296,8 @@ Fugu Ultra 的编排 token 已包含在 API 返回的 input/output 用量中,
|
|
|
277
296
|
|
|
278
297
|
- Realtime、音频、图片、视频、embedding、按页、按分钟和按工具调用收费的模型无法仅由当前五类 token 用量准确计算。
|
|
279
298
|
- `grok-4.20`、`grok-4.20-multi-agent` 发布于 2026-03-09,早于目录收录窗口起点 2026-03-22。
|
|
280
|
-
- Fast/Priority
|
|
281
|
-
-
|
|
282
|
-
- 无法从厂商官方页面确认标准 token 价格的模型不猜价,包括 OpenRouter stealth/alpha 匿名模型、`z-ai/glm-5v-turbo`、`qwen3.6-plus-preview`、腾讯 `hy3-preview` 与 `hy-mt2-*`、`kwaipilot/kat-coder-pro-v2.5` 及其 Air
|
|
299
|
+
- Fast/Priority 等其他未列出的加速档(例如 `claude-opus-4-7-fast`、`gpt-5.5-pro-fast`、`gpt-6-astra-pro` 和 MiniMax priority 档)不收录;上表列出当前快照中官方定价页明确支持的 GPT 与 Claude Fast 型号。
|
|
300
|
+
- 其他免费模型(Gemma 系列、`cohere/north-mini-code` 等开源或网关零价款)不设价格条目。
|
|
301
|
+
- 无法从厂商官方页面确认标准 token 价格的模型不猜价,包括 OpenRouter stealth/alpha 匿名模型、`z-ai/glm-5v-turbo`、`qwen3.6-plus-preview`、腾讯 `hy3-preview` 与 `hy-mt2-*`、`kwaipilot/kat-coder-pro-v2.5` 及其 Air 版本、除上表 OpenCode Zen SKU 外的 `inclusionai/ling-3.0-*`、`bytedance-seed/seed-2.0-code` 等。这些模型目前只能查到 OpenRouter、AtlasCloud、DeepInfra 等网关或第三方报价,不能据此推断厂商标准价。
|
|
283
302
|
- 浮动别名(`-latest` 指针与 OpenRouter `~` 前缀条目)随底层模型漂移,不收录固定价。
|
|
284
303
|
- 只有询价、托管部署价或无法从厂商官方页面确认标准 token 价格的模型不猜价。
|
package/docs/verification.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# 验证记录
|
|
2
2
|
|
|
3
|
+
## v0.3.3(GPT 与 Claude Fast 价格)
|
|
4
|
+
|
|
5
|
+
验证日期:2026-09-23。根据 [OpenAI API Pricing](https://developers.openai.com/api/docs/pricing) 与 [Claude Platform Pricing](https://platform.claude.com/docs/en/about-claude/pricing),为当前快照中官方支持 Fast mode 的 GPT-5.5、GPT-5.6 Sol/Terra/Luna、GPT-6 Astra/Sol/Luna,以及 Claude Opus 4.8/5/5.5 分别加入独立 Fast 条目。Fast 费率按官方长上下文档位与缓存倍率记录;GPT-5.5 Fast 未公布长上下文费率,超过 272,000 个传入 token 时显示不可估价。条目分别限制到官方支持 Fast mode 的 OpenAI 与 Anthropic provider;快照由 76 个模型增至 86 个。
|
|
6
|
+
|
|
7
|
+
| 检查 | 结果 |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| `npm run typecheck` | 通过 |
|
|
10
|
+
| `npm test` | 51 项通过,覆盖 Fast 费率、缓存倍率、长上下文边界及普通版价格隔离 |
|
|
11
|
+
| `npm run build` | 通过 |
|
|
12
|
+
|
|
13
|
+
本轮只改动价格目录、对应测试及价格说明,未重跑打包集成 smoke 测试。
|
|
14
|
+
|
|
3
15
|
## v0.3.2(GPT-6 Sol / Luna 价格更新,SDK 2.0.11)
|
|
4
16
|
|
|
5
17
|
验证日期:2026-09-23。根据 [OpenAI API 更新日志](https://developers.openai.com/api/docs/changelog),`gpt-6-sol` 和 `gpt-6-luna` 于 2026-09-22 发布;[官方定价页](https://developers.openai.com/api/docs/pricing)列出两者的 Standard 短、长上下文四类 token 费率。内置快照由 72 个模型增至 74 个。根据 [Sol](https://developers.openai.com/api/docs/models/gpt-6-sol) 与 [Luna](https://developers.openai.com/api/docs/models/gpt-6-luna) 模型说明,传入 token 超过 272,000 时才使用长上下文价格;同轮也将已有 OpenAI 条目的边界从 271,999 校正为 272,000。
|