opencode-token-tracker 1.3.0 → 1.3.2
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 +30 -1
- package/dist/bin/opencode-tokens.js +71 -34
- package/dist/index.js +49 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -183,6 +183,35 @@ Create a config file at `~/.config/opencode/token-tracker.json`:
|
|
|
183
183
|
}
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
+
### Pricing Fields Explained
|
|
187
|
+
|
|
188
|
+
All prices are in **USD per 1 million tokens**:
|
|
189
|
+
|
|
190
|
+
| Field | Description | Example |
|
|
191
|
+
|-------|-------------|---------|
|
|
192
|
+
| `input` | Cost for input/prompt tokens | `15` = $15 per 1M tokens |
|
|
193
|
+
| `output` | Cost for output/completion tokens | `75` = $75 per 1M tokens |
|
|
194
|
+
| `cacheRead` | Cost for cached input tokens (optional) | `1.5` = $1.5 per 1M tokens |
|
|
195
|
+
| `cacheWrite` | Cost for cache write tokens (optional) | `18.75` = $18.75 per 1M tokens |
|
|
196
|
+
|
|
197
|
+
**How to find pricing for your model:**
|
|
198
|
+
|
|
199
|
+
1. Check the provider's official pricing page:
|
|
200
|
+
- [Anthropic Claude](https://www.anthropic.com/pricing)
|
|
201
|
+
- [OpenAI](https://openai.com/pricing)
|
|
202
|
+
- [DeepSeek](https://platform.deepseek.com/api-docs/pricing)
|
|
203
|
+
- [Google Gemini](https://ai.google.dev/pricing)
|
|
204
|
+
|
|
205
|
+
2. Or run `opencode-tokens pricing` to see built-in prices
|
|
206
|
+
|
|
207
|
+
**Common scenarios:**
|
|
208
|
+
|
|
209
|
+
| Scenario | Config |
|
|
210
|
+
|----------|--------|
|
|
211
|
+
| Subscription service (GitHub Copilot, Cursor) | `{ "input": 0, "output": 0 }` |
|
|
212
|
+
| Free/local model | `{ "input": 0, "output": 0 }` |
|
|
213
|
+
| Custom API with known pricing | Look up provider's pricing page |
|
|
214
|
+
|
|
186
215
|
### Pricing Override
|
|
187
216
|
|
|
188
217
|
Pricing is resolved in this order (first match wins):
|
|
@@ -207,7 +236,7 @@ If you're using GitHub Copilot or other subscription-based services, set their c
|
|
|
207
236
|
|
|
208
237
|
#### Example: Custom model pricing
|
|
209
238
|
|
|
210
|
-
Override or add pricing for specific models:
|
|
239
|
+
Override or add pricing for specific models (prices in USD per 1M tokens):
|
|
211
240
|
|
|
212
241
|
```json
|
|
213
242
|
{
|
|
@@ -5,37 +5,46 @@ import { homedir } from "os";
|
|
|
5
5
|
const CONFIG_DIR = join(homedir(), ".config", "opencode");
|
|
6
6
|
const CONFIG_FILE = join(CONFIG_DIR, "token-tracker.json");
|
|
7
7
|
const LOG_FILE = join(CONFIG_DIR, "logs", "token-tracker", "tokens.jsonl");
|
|
8
|
+
// Built-in pricing (USD per 1M tokens) - Updated 2026-02-05
|
|
9
|
+
// Keep in sync with index.ts BUILTIN_PRICING
|
|
8
10
|
const BUILTIN_PRICING = {
|
|
9
|
-
// Anthropic Claude
|
|
10
|
-
"claude-opus-4.5": { input:
|
|
11
|
+
// Anthropic Claude (https://www.anthropic.com/pricing#api)
|
|
12
|
+
"claude-opus-4.5": { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
11
13
|
"claude-sonnet-4.5": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
12
14
|
"claude-sonnet-4": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
13
|
-
"claude-haiku-4.5": { input:
|
|
14
|
-
"claude-haiku-4": { input:
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
15
|
+
"claude-haiku-4.5": { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 },
|
|
16
|
+
"claude-haiku-4": { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 },
|
|
17
|
+
"claude-opus-4.1": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
|
|
18
|
+
"claude-opus-4": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
|
|
19
|
+
"claude-haiku-3": { input: 0.25, output: 1.25, cacheRead: 0.03, cacheWrite: 0.3 },
|
|
20
|
+
// OpenAI GPT (https://openai.com/api/pricing/)
|
|
21
|
+
"gpt-5.2": { input: 1.75, output: 14, cacheRead: 0.175 },
|
|
22
|
+
"gpt-5.2-pro": { input: 21, output: 168 },
|
|
23
|
+
"gpt-5-mini": { input: 0.25, output: 2, cacheRead: 0.025 },
|
|
18
24
|
"gpt-5.1": { input: 2, output: 8 },
|
|
19
25
|
"gpt-5": { input: 5, output: 15 },
|
|
20
|
-
"gpt-4.1": { input:
|
|
21
|
-
"gpt-4.1-mini": { input: 0.
|
|
22
|
-
"gpt-4.1-nano": { input: 0.
|
|
26
|
+
"gpt-4.1": { input: 3, output: 12, cacheRead: 0.75 },
|
|
27
|
+
"gpt-4.1-mini": { input: 0.8, output: 3.2, cacheRead: 0.2 },
|
|
28
|
+
"gpt-4.1-nano": { input: 0.2, output: 0.8, cacheRead: 0.05 },
|
|
23
29
|
"gpt-4o": { input: 2.5, output: 10 },
|
|
24
30
|
"gpt-4o-mini": { input: 0.15, output: 0.6 },
|
|
25
31
|
"o3": { input: 10, output: 40 },
|
|
26
32
|
"o3-mini": { input: 1.1, output: 4.4 },
|
|
33
|
+
"o4-mini": { input: 4, output: 16, cacheRead: 1 },
|
|
27
34
|
"o1": { input: 15, output: 60 },
|
|
28
35
|
"o1-mini": { input: 1.1, output: 4.4 },
|
|
29
|
-
// DeepSeek
|
|
30
|
-
"deepseek-chat": { input: 0.
|
|
31
|
-
"deepseek-reasoner": { input: 0.
|
|
32
|
-
// Google Gemini
|
|
33
|
-
"gemini-3-pro": { input:
|
|
34
|
-
"gemini-3-pro-preview": { input:
|
|
35
|
-
"gemini-3-flash": { input: 0.
|
|
36
|
-
"gemini-
|
|
37
|
-
"gemini-2.5-
|
|
38
|
-
"gemini-2.
|
|
36
|
+
// DeepSeek (https://api-docs.deepseek.com/quick_start/pricing)
|
|
37
|
+
"deepseek-chat": { input: 0.28, output: 0.42, cacheRead: 0.028 },
|
|
38
|
+
"deepseek-reasoner": { input: 0.28, output: 0.42, cacheRead: 0.028 },
|
|
39
|
+
// Google Gemini (https://cloud.google.com/vertex-ai/generative-ai/pricing)
|
|
40
|
+
"gemini-3-pro": { input: 2, output: 12, cacheRead: 0.2 },
|
|
41
|
+
"gemini-3-pro-preview": { input: 2, output: 12, cacheRead: 0.2 },
|
|
42
|
+
"gemini-3-flash": { input: 0.5, output: 2, cacheRead: 0.05 },
|
|
43
|
+
"gemini-3-flash-preview": { input: 0.5, output: 2, cacheRead: 0.05 },
|
|
44
|
+
"gemini-2.5-pro": { input: 1.25, output: 10, cacheRead: 0.125 },
|
|
45
|
+
"gemini-2.5-flash": { input: 0.1, output: 0.4, cacheRead: 0.01 },
|
|
46
|
+
"gemini-2.5-flash-lite": { input: 0.1, output: 0.4, cacheRead: 0.01 },
|
|
47
|
+
"gemini-2.0-flash": { input: 0.15, output: 0.6, cacheRead: 0.015 },
|
|
39
48
|
// Fallback
|
|
40
49
|
"_default": { input: 1, output: 4 },
|
|
41
50
|
};
|
|
@@ -276,15 +285,15 @@ function cmdStats(period, breakdown) {
|
|
|
276
285
|
function cmdPricing() {
|
|
277
286
|
const config = loadConfig();
|
|
278
287
|
console.log(`
|
|
279
|
-
Built-in Pricing Table (USD per 1M tokens)
|
|
288
|
+
Built-in Pricing Table (USD per 1M tokens) - Updated 2026-02-05
|
|
280
289
|
══════════════════════════════════════════════════════════════════
|
|
281
290
|
`);
|
|
282
291
|
// Group by provider
|
|
283
292
|
const groups = {
|
|
284
|
-
"Anthropic Claude": ["claude-opus-4.5", "claude-sonnet-4.5", "claude-sonnet-4", "claude-haiku-4.5", "claude-haiku-4"],
|
|
285
|
-
"OpenAI": ["gpt-5.2", "gpt-5.2-
|
|
293
|
+
"Anthropic Claude": ["claude-opus-4.5", "claude-sonnet-4.5", "claude-sonnet-4", "claude-haiku-4.5", "claude-haiku-4", "claude-opus-4.1", "claude-opus-4", "claude-haiku-3"],
|
|
294
|
+
"OpenAI": ["gpt-5.2", "gpt-5.2-pro", "gpt-5-mini", "gpt-5.1", "gpt-5", "gpt-4.1", "gpt-4.1-mini", "gpt-4.1-nano", "gpt-4o", "gpt-4o-mini", "o3", "o3-mini", "o4-mini", "o1", "o1-mini"],
|
|
286
295
|
"DeepSeek": ["deepseek-chat", "deepseek-reasoner"],
|
|
287
|
-
"Google Gemini": ["gemini-3-pro", "gemini-3-pro-preview", "gemini-3-flash", "gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"],
|
|
296
|
+
"Google Gemini": ["gemini-3-pro", "gemini-3-pro-preview", "gemini-3-flash", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.5-flash-lite", "gemini-2.0-flash"],
|
|
288
297
|
};
|
|
289
298
|
const modelWidth = 20;
|
|
290
299
|
const priceWidth = 10;
|
|
@@ -407,19 +416,47 @@ function cmdConfig(action) {
|
|
|
407
416
|
for (const model of unknownModels) {
|
|
408
417
|
exampleConfig.models[model] = { input: 1, output: 4 };
|
|
409
418
|
}
|
|
419
|
+
// Print explanation first
|
|
420
|
+
console.log(`
|
|
421
|
+
Pricing Configuration Guide
|
|
422
|
+
══════════════════════════════════════════════════════════════════
|
|
423
|
+
|
|
424
|
+
All prices are in USD per 1 MILLION tokens.
|
|
425
|
+
|
|
426
|
+
Fields:
|
|
427
|
+
input Cost for input/prompt tokens sent to the model
|
|
428
|
+
output Cost for output/completion tokens from the model
|
|
429
|
+
cacheRead Cost for cached input tokens (optional, usually cheaper)
|
|
430
|
+
cacheWrite Cost for cache write tokens (optional)
|
|
431
|
+
|
|
432
|
+
Examples:
|
|
433
|
+
{ "input": 15, "output": 75 } = $15 per 1M input, $75 per 1M output
|
|
434
|
+
{ "input": 0, "output": 0 } = Free (subscription or local model)
|
|
435
|
+
|
|
436
|
+
Common scenarios:
|
|
437
|
+
- GitHub Copilot, Cursor, etc. → Set to 0 (subscription-based)
|
|
438
|
+
- Local/self-hosted models → Set to 0
|
|
439
|
+
- Direct API usage → Look up provider's pricing page
|
|
440
|
+
|
|
441
|
+
Where to find pricing:
|
|
442
|
+
- Anthropic: https://www.anthropic.com/pricing
|
|
443
|
+
- OpenAI: https://openai.com/pricing
|
|
444
|
+
- DeepSeek: https://platform.deepseek.com/api-docs/pricing
|
|
445
|
+
- Google: https://ai.google.dev/pricing
|
|
446
|
+
- Or run: opencode-tokens pricing
|
|
447
|
+
|
|
448
|
+
────────────────────────────────────────────────────────────────
|
|
449
|
+
Example config based on your usage:
|
|
450
|
+
`);
|
|
451
|
+
console.log(JSON.stringify(exampleConfig, null, 2));
|
|
410
452
|
if (action === "generate") {
|
|
411
453
|
const json = JSON.stringify(exampleConfig, null, 2);
|
|
412
454
|
writeFileSync(CONFIG_FILE, json);
|
|
413
|
-
console.log(`\n Config file generated: ${CONFIG_FILE}\n`);
|
|
414
|
-
console.log(json);
|
|
415
|
-
console.log();
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
455
|
console.log(`
|
|
419
|
-
|
|
420
|
-
────────────────────────────────────────────────────────────────
|
|
456
|
+
Config file created: ${CONFIG_FILE}
|
|
421
457
|
`);
|
|
422
|
-
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
423
460
|
console.log(`
|
|
424
461
|
To create this config file, run:
|
|
425
462
|
opencode-tokens config generate
|
|
@@ -444,8 +481,8 @@ function cmdConfig(action) {
|
|
|
444
481
|
console.log();
|
|
445
482
|
}
|
|
446
483
|
console.log(` Commands:`);
|
|
447
|
-
console.log(` opencode-tokens config init Show example config
|
|
448
|
-
console.log(` opencode-tokens config generate Create config file
|
|
484
|
+
console.log(` opencode-tokens config init Show example config with explanation`);
|
|
485
|
+
console.log(` opencode-tokens config generate Create config file`);
|
|
449
486
|
console.log();
|
|
450
487
|
}
|
|
451
488
|
function cmdHelp() {
|
package/dist/index.js
CHANGED
|
@@ -14,38 +14,66 @@ const DEFAULT_CONFIG = {
|
|
|
14
14
|
showOnIdle: true,
|
|
15
15
|
},
|
|
16
16
|
};
|
|
17
|
-
// Built-in pricing table (USD per 1M tokens) -
|
|
17
|
+
// Built-in pricing table (USD per 1M tokens) - Updated 2026-02-05
|
|
18
|
+
// Sources:
|
|
19
|
+
// - Anthropic: https://www.anthropic.com/pricing#api
|
|
20
|
+
// - OpenAI: https://openai.com/api/pricing/
|
|
21
|
+
// - DeepSeek: https://api-docs.deepseek.com/quick_start/pricing
|
|
22
|
+
// - Google: https://cloud.google.com/vertex-ai/generative-ai/pricing
|
|
18
23
|
const BUILTIN_PRICING = {
|
|
19
|
-
// Anthropic Claude
|
|
20
|
-
|
|
24
|
+
// Anthropic Claude (https://www.anthropic.com/pricing#api)
|
|
25
|
+
// Opus 4.5: $5 input, $25 output, cache write $6.25, cache read $0.50
|
|
26
|
+
"claude-opus-4.5": { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
27
|
+
// Sonnet 4.5: $3 input, $15 output (≤200K), cache write $3.75, cache read $0.30
|
|
21
28
|
"claude-sonnet-4.5": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
29
|
+
// Sonnet 4: $3 input, $15 output
|
|
22
30
|
"claude-sonnet-4": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
23
|
-
|
|
24
|
-
"claude-haiku-4": { input:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
31
|
+
// Haiku 4.5: $1 input, $5 output, cache write $1.25, cache read $0.10
|
|
32
|
+
"claude-haiku-4.5": { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 },
|
|
33
|
+
"claude-haiku-4": { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 },
|
|
34
|
+
// Legacy models
|
|
35
|
+
"claude-opus-4.1": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
|
|
36
|
+
"claude-opus-4": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
|
|
37
|
+
"claude-haiku-3": { input: 0.25, output: 1.25, cacheRead: 0.03, cacheWrite: 0.3 },
|
|
38
|
+
// OpenAI GPT (https://openai.com/api/pricing/)
|
|
39
|
+
// GPT-5.2: $1.75 input, $14 output (flagship)
|
|
40
|
+
"gpt-5.2": { input: 1.75, output: 14, cacheRead: 0.175 },
|
|
41
|
+
"gpt-5.2-pro": { input: 21, output: 168 },
|
|
42
|
+
"gpt-5-mini": { input: 0.25, output: 2, cacheRead: 0.025 },
|
|
28
43
|
"gpt-5.1": { input: 2, output: 8 },
|
|
29
44
|
"gpt-5": { input: 5, output: 15 },
|
|
30
|
-
|
|
31
|
-
"gpt-4.1
|
|
32
|
-
"gpt-4.1-
|
|
45
|
+
// GPT-4.1 series (fine-tuning prices, base may differ)
|
|
46
|
+
"gpt-4.1": { input: 3, output: 12, cacheRead: 0.75 },
|
|
47
|
+
"gpt-4.1-mini": { input: 0.8, output: 3.2, cacheRead: 0.2 },
|
|
48
|
+
"gpt-4.1-nano": { input: 0.2, output: 0.8, cacheRead: 0.05 },
|
|
49
|
+
// GPT-4o series (may be deprecated)
|
|
33
50
|
"gpt-4o": { input: 2.5, output: 10 },
|
|
34
51
|
"gpt-4o-mini": { input: 0.15, output: 0.6 },
|
|
52
|
+
// Reasoning models
|
|
35
53
|
"o3": { input: 10, output: 40 },
|
|
36
54
|
"o3-mini": { input: 1.1, output: 4.4 },
|
|
55
|
+
"o4-mini": { input: 4, output: 16, cacheRead: 1 },
|
|
37
56
|
"o1": { input: 15, output: 60 },
|
|
38
57
|
"o1-mini": { input: 1.1, output: 4.4 },
|
|
39
|
-
// DeepSeek
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"gemini-
|
|
47
|
-
"gemini-
|
|
48
|
-
|
|
58
|
+
// DeepSeek (https://api-docs.deepseek.com/quick_start/pricing)
|
|
59
|
+
// DeepSeek-V3.2: unified pricing for both chat and reasoner
|
|
60
|
+
// $0.28 input (cache miss), $0.028 input (cache hit), $0.42 output
|
|
61
|
+
"deepseek-chat": { input: 0.28, output: 0.42, cacheRead: 0.028 },
|
|
62
|
+
"deepseek-reasoner": { input: 0.28, output: 0.42, cacheRead: 0.028 },
|
|
63
|
+
// Google Gemini (https://cloud.google.com/vertex-ai/generative-ai/pricing)
|
|
64
|
+
// Gemini 3 Pro Preview: $2 input, $12 output (≤200K)
|
|
65
|
+
"gemini-3-pro": { input: 2, output: 12, cacheRead: 0.2 },
|
|
66
|
+
"gemini-3-pro-preview": { input: 2, output: 12, cacheRead: 0.2 },
|
|
67
|
+
// Gemini 3 Flash Preview: $0.5 input
|
|
68
|
+
"gemini-3-flash": { input: 0.5, output: 2, cacheRead: 0.05 },
|
|
69
|
+
"gemini-3-flash-preview": { input: 0.5, output: 2, cacheRead: 0.05 },
|
|
70
|
+
// Gemini 2.5 Pro: $1.25 input, $10 output (≤200K)
|
|
71
|
+
"gemini-2.5-pro": { input: 1.25, output: 10, cacheRead: 0.125 },
|
|
72
|
+
// Gemini 2.5 Flash Lite: $0.1 input
|
|
73
|
+
"gemini-2.5-flash": { input: 0.1, output: 0.4, cacheRead: 0.01 },
|
|
74
|
+
"gemini-2.5-flash-lite": { input: 0.1, output: 0.4, cacheRead: 0.01 },
|
|
75
|
+
// Gemini 2.0 Flash: $0.15 input
|
|
76
|
+
"gemini-2.0-flash": { input: 0.15, output: 0.6, cacheRead: 0.015 },
|
|
49
77
|
// Fallback for unknown models
|
|
50
78
|
"_default": { input: 1, output: 4 },
|
|
51
79
|
};
|
package/package.json
CHANGED