@diogonzafe/tokenwatch 0.1.1 → 0.1.3
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 +25 -29
- package/dist/index.cjs +1128 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1128 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/prices.json +1116 -13
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# tokenwatch
|
|
1
|
+
# @diogonzafe/tokenwatch
|
|
2
2
|
|
|
3
3
|
Transparent TypeScript wrapper that intercepts LLM API calls and tracks cost in real-time by session, user and model — without changing anything in your existing code.
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ Supports **OpenAI**, **Anthropic**, **Google Gemini** and **DeepSeek**.
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install tokenwatch
|
|
10
|
+
npm install @diogonzafe/tokenwatch
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Peer dependencies (install only what you use):
|
|
@@ -24,7 +24,7 @@ npm install better-sqlite3 # optional — only for storage: 'sqlite'
|
|
|
24
24
|
## Setup
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
|
-
import { createTracker } from 'tokenwatch'
|
|
27
|
+
import { createTracker } from '@diogonzafe/tokenwatch'
|
|
28
28
|
|
|
29
29
|
const tracker = await createTracker({
|
|
30
30
|
// All fields are optional
|
|
@@ -33,7 +33,7 @@ const tracker = await createTracker({
|
|
|
33
33
|
webhookUrl: 'https://...', // Discord / Slack webhook
|
|
34
34
|
syncPrices: true, // fetch fresh prices from GitHub (default: true)
|
|
35
35
|
customPrices: {
|
|
36
|
-
'my-model': { input: 0.
|
|
36
|
+
'my-model': { input: 0.50, output: 1.50 } // USD per 1M tokens
|
|
37
37
|
}
|
|
38
38
|
})
|
|
39
39
|
```
|
|
@@ -44,7 +44,7 @@ const tracker = await createTracker({
|
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
46
|
import OpenAI from 'openai'
|
|
47
|
-
import { wrapOpenAI } from 'tokenwatch'
|
|
47
|
+
import { wrapOpenAI } from '@diogonzafe/tokenwatch'
|
|
48
48
|
|
|
49
49
|
const openai = wrapOpenAI(new OpenAI(), tracker)
|
|
50
50
|
|
|
@@ -80,7 +80,7 @@ for await (const chunk of stream) {
|
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
82
|
import Anthropic from '@anthropic-ai/sdk'
|
|
83
|
-
import { wrapAnthropic } from 'tokenwatch'
|
|
83
|
+
import { wrapAnthropic } from '@diogonzafe/tokenwatch'
|
|
84
84
|
|
|
85
85
|
const anthropic = wrapAnthropic(new Anthropic(), tracker)
|
|
86
86
|
|
|
@@ -99,7 +99,7 @@ const res = await anthropic.messages.create({
|
|
|
99
99
|
|
|
100
100
|
```ts
|
|
101
101
|
import { GoogleGenerativeAI } from '@google/generative-ai'
|
|
102
|
-
import { wrapGemini } from 'tokenwatch'
|
|
102
|
+
import { wrapGemini } from '@diogonzafe/tokenwatch'
|
|
103
103
|
|
|
104
104
|
const genAI = wrapGemini(new GoogleGenerativeAI(process.env.GEMINI_API_KEY!), tracker)
|
|
105
105
|
|
|
@@ -115,7 +115,7 @@ DeepSeek uses an OpenAI-compatible API — just set `baseURL`:
|
|
|
115
115
|
|
|
116
116
|
```ts
|
|
117
117
|
import OpenAI from 'openai'
|
|
118
|
-
import { wrapDeepSeek } from 'tokenwatch'
|
|
118
|
+
import { wrapDeepSeek } from '@diogonzafe/tokenwatch'
|
|
119
119
|
|
|
120
120
|
const deepseek = wrapDeepSeek(
|
|
121
121
|
new OpenAI({
|
|
@@ -171,6 +171,23 @@ Prices are in **USD per 1 million tokens**.
|
|
|
171
171
|
|
|
172
172
|
---
|
|
173
173
|
|
|
174
|
+
## Pricing Data
|
|
175
|
+
|
|
176
|
+
`prices.json` bundles 200+ models across all providers. Each entry includes prices and context window size:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"gpt-4o": { "input": 2.50, "output": 10.00, "maxInputTokens": 128000 },
|
|
181
|
+
"claude-sonnet-4-6": { "input": 3.00, "output": 15.00, "maxInputTokens": 1000000 },
|
|
182
|
+
"gemini-2.5-pro": { "input": 1.25, "output": 10.00, "maxInputTokens": 1048576 },
|
|
183
|
+
"deepseek-chat": { "input": 0.28, "output": 0.42, "maxInputTokens": 131072 }
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Prices are updated every Monday via a GitHub Action that pulls from the [LiteLLM community model registry](https://github.com/BerriAI/litellm). New models are auto-discovered — no manual updates needed.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
174
191
|
## SQLite Storage
|
|
175
192
|
|
|
176
193
|
For persistent tracking across restarts:
|
|
@@ -214,27 +231,6 @@ npx tokenwatch help # show help
|
|
|
214
231
|
|
|
215
232
|
---
|
|
216
233
|
|
|
217
|
-
## Bundled Models
|
|
218
|
-
|
|
219
|
-
| Model | Input ($/1M) | Output ($/1M) |
|
|
220
|
-
|---|---|---|
|
|
221
|
-
| gpt-4o | $2.50 | $10.00 |
|
|
222
|
-
| gpt-4o-mini | $0.15 | $0.60 |
|
|
223
|
-
| gpt-5 | $1.25 | $10.00 |
|
|
224
|
-
| gpt-5-mini | $0.25 | $2.00 |
|
|
225
|
-
| gpt-5-nano | $0.05 | $0.40 |
|
|
226
|
-
| claude-opus-4-6 | $5.00 | $25.00 |
|
|
227
|
-
| claude-sonnet-4-6 | $3.00 | $15.00 |
|
|
228
|
-
| claude-haiku-4-5 | $1.00 | $5.00 |
|
|
229
|
-
| gemini-2.5-pro | $1.25 | $10.00 |
|
|
230
|
-
| gemini-2.5-flash | $0.30 | $2.50 |
|
|
231
|
-
| deepseek-chat | $0.28 | $0.42 |
|
|
232
|
-
| deepseek-reasoner | $0.55 | $2.19 |
|
|
233
|
-
|
|
234
|
-
Prices are automatically updated every Monday via GitHub Action.
|
|
235
|
-
|
|
236
|
-
---
|
|
237
|
-
|
|
238
234
|
## Behaviour Guarantees
|
|
239
235
|
|
|
240
236
|
- `__sessionId` and `__userId` are **stripped before** the request reaches the API
|