mohdel 0.113.0 → 0.114.1
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/js/core/events.js
CHANGED
|
@@ -87,6 +87,10 @@
|
|
|
87
87
|
* Input tokens written to a fresh prompt cache breakpoint, billed at
|
|
88
88
|
* `cacheWritePrice`. Absent when the provider has no separate
|
|
89
89
|
* cache-write counter.
|
|
90
|
+
* @property {number} [cacheWrite1hInputTokens]
|
|
91
|
+
* The 1h-TTL subset of `cacheWriteInputTokens` (Anthropic), billed at
|
|
92
|
+
* `cacheWrite1hPrice`; the 5m portion is the remainder. A request may mix
|
|
93
|
+
* TTLs. Absent when the turn has no 1h-TTL cache writes.
|
|
90
94
|
* @property {number} [cacheReadInputTokens]
|
|
91
95
|
* Input tokens served from prompt cache, billed at `cacheReadPrice`.
|
|
92
96
|
* Absent when the provider has no prompt caching.
|
|
@@ -27,8 +27,15 @@ import { getSpec, setCatalog } from './_catalog.js'
|
|
|
27
27
|
* Optional fields fall back to other prices when absent:
|
|
28
28
|
* - `thinkingPrice` → `outputPrice`
|
|
29
29
|
* - `cacheWritePrice` → `inputPrice` (graceful for non-caching providers)
|
|
30
|
+
* - `cacheWrite1hPrice` → `cacheWritePrice` (graceful when only one write tier is priced)
|
|
30
31
|
* - `cacheReadPrice` → `inputPrice`
|
|
31
32
|
*
|
|
33
|
+
* `cacheWrite1hInputTokens` is the 1h-TTL subset of `cacheWriteInputTokens`
|
|
34
|
+
* (Anthropic bills 1h writes at a higher rate than 5m). The 5m portion is
|
|
35
|
+
* `cacheWriteInputTokens - cacheWrite1hInputTokens`. When the 1h field is
|
|
36
|
+
* absent or the catalog has no `cacheWrite1hPrice`, the whole write bills at
|
|
37
|
+
* `cacheWritePrice` — identical to the single-tier behaviour.
|
|
38
|
+
*
|
|
32
39
|
* Token-counting convention: this function is purely additive across
|
|
33
40
|
* `inputTokens`, `cacheWriteInputTokens`, `cacheReadInputTokens`,
|
|
34
41
|
* `outputTokens`, and `thinkingTokens`. Adapters normalize provider-specific
|
|
@@ -36,7 +43,8 @@ import { getSpec, setCatalog } from './_catalog.js'
|
|
|
36
43
|
*
|
|
37
44
|
* @param {any} spec Catalog entry, or `undefined`.
|
|
38
45
|
* @param {{inputTokens?: number, outputTokens?: number, thinkingTokens?: number,
|
|
39
|
-
* cacheWriteInputTokens?: number,
|
|
46
|
+
* cacheWriteInputTokens?: number, cacheWrite1hInputTokens?: number,
|
|
47
|
+
* cacheReadInputTokens?: number}} usage
|
|
40
48
|
* @returns {number}
|
|
41
49
|
*/
|
|
42
50
|
export function computeCost (spec, usage) {
|
|
@@ -45,6 +53,8 @@ export function computeCost (spec, usage) {
|
|
|
45
53
|
const o = usage.outputTokens ?? 0
|
|
46
54
|
const t = usage.thinkingTokens ?? 0
|
|
47
55
|
const cw = usage.cacheWriteInputTokens ?? 0
|
|
56
|
+
const cw1h = Math.min(cw, usage.cacheWrite1hInputTokens ?? 0)
|
|
57
|
+
const cw5m = Math.max(0, cw - cw1h)
|
|
48
58
|
const cr = usage.cacheReadInputTokens ?? 0
|
|
49
59
|
const ip = resolveTier(spec.inputPrice, i)
|
|
50
60
|
const op = resolveTier(spec.outputPrice, i)
|
|
@@ -53,9 +63,11 @@ export function computeCost (spec, usage) {
|
|
|
53
63
|
const tpFinal = typeof tp === 'number' ? tp : op
|
|
54
64
|
const cwp = resolveTier(spec.cacheWritePrice, i)
|
|
55
65
|
const cwpFinal = typeof cwp === 'number' ? cwp : ip
|
|
66
|
+
const cw1hp = resolveTier(spec.cacheWrite1hPrice, i)
|
|
67
|
+
const cw1hpFinal = typeof cw1hp === 'number' ? cw1hp : cwpFinal
|
|
56
68
|
const crp = resolveTier(spec.cacheReadPrice, i)
|
|
57
69
|
const crpFinal = typeof crp === 'number' ? crp : ip
|
|
58
|
-
const total = (i * ip +
|
|
70
|
+
const total = (i * ip + cw5m * cwpFinal + cw1h * cw1hpFinal + cr * crpFinal + o * op + t * tpFinal) / 1_000_000
|
|
59
71
|
return round(total)
|
|
60
72
|
}
|
|
61
73
|
|
|
@@ -114,6 +114,7 @@ export async function * anthropic (envelope, deps = {}) {
|
|
|
114
114
|
let inputTokens = 0
|
|
115
115
|
let outputTokens = 0
|
|
116
116
|
let cacheWriteTokens = 0
|
|
117
|
+
let cacheWrite1hTokens = 0
|
|
117
118
|
let cacheReadTokens = 0
|
|
118
119
|
let thinkingChars = 0
|
|
119
120
|
let status = STATUS_COMPLETED
|
|
@@ -140,6 +141,12 @@ export async function * anthropic (envelope, deps = {}) {
|
|
|
140
141
|
if (event.message?.usage?.cache_creation_input_tokens) {
|
|
141
142
|
cacheWriteTokens = event.message.usage.cache_creation_input_tokens
|
|
142
143
|
}
|
|
144
|
+
// cache_creation breaks the write total down by TTL (5m + 1h).
|
|
145
|
+
// Surface the 1h subset so the cost layer can price it separately;
|
|
146
|
+
// a request may mix TTLs, so both tiers can be non-zero.
|
|
147
|
+
if (event.message?.usage?.cache_creation?.ephemeral_1h_input_tokens) {
|
|
148
|
+
cacheWrite1hTokens = event.message.usage.cache_creation.ephemeral_1h_input_tokens
|
|
149
|
+
}
|
|
143
150
|
if (event.message?.usage?.cache_read_input_tokens) {
|
|
144
151
|
cacheReadTokens = event.message.usage.cache_read_input_tokens
|
|
145
152
|
}
|
|
@@ -249,6 +256,7 @@ export async function * anthropic (envelope, deps = {}) {
|
|
|
249
256
|
outputTokens: messageOutputTokens,
|
|
250
257
|
thinkingTokens: estimatedThinkingTokens,
|
|
251
258
|
...(cacheWriteTokens > 0 && { cacheWriteInputTokens: cacheWriteTokens }),
|
|
259
|
+
...(cacheWrite1hTokens > 0 && { cacheWrite1hInputTokens: cacheWrite1hTokens }),
|
|
252
260
|
...(cacheReadTokens > 0 && { cacheReadInputTokens: cacheReadTokens }),
|
|
253
261
|
cost: costFor(
|
|
254
262
|
catalogKey(envelope.model),
|
|
@@ -257,6 +265,7 @@ export async function * anthropic (envelope, deps = {}) {
|
|
|
257
265
|
outputTokens: messageOutputTokens,
|
|
258
266
|
thinkingTokens: estimatedThinkingTokens,
|
|
259
267
|
cacheWriteInputTokens: cacheWriteTokens,
|
|
268
|
+
cacheWrite1hInputTokens: cacheWrite1hTokens,
|
|
260
269
|
cacheReadInputTokens: cacheReadTokens
|
|
261
270
|
}
|
|
262
271
|
),
|
|
@@ -104,6 +104,7 @@ export async function * gemini (envelope, deps = {}) {
|
|
|
104
104
|
let inputTokens = 0
|
|
105
105
|
let outputTokens = 0
|
|
106
106
|
let thinkingTokens = 0
|
|
107
|
+
let cacheReadTokens = 0
|
|
107
108
|
let status = STATUS_COMPLETED
|
|
108
109
|
/** @type {string | undefined} */
|
|
109
110
|
let warning
|
|
@@ -164,6 +165,9 @@ export async function * gemini (envelope, deps = {}) {
|
|
|
164
165
|
if (typeof chunk.usageMetadata.thoughtsTokenCount === 'number') {
|
|
165
166
|
thinkingTokens = chunk.usageMetadata.thoughtsTokenCount
|
|
166
167
|
}
|
|
168
|
+
if (typeof chunk.usageMetadata.cachedContentTokenCount === 'number') {
|
|
169
|
+
cacheReadTokens = chunk.usageMetadata.cachedContentTokenCount
|
|
170
|
+
}
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
} catch (e) {
|
|
@@ -186,18 +190,23 @@ export async function * gemini (envelope, deps = {}) {
|
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
const end = String(process.hrtime.bigint())
|
|
193
|
+
// Implicit caching reports cachedContentTokenCount as a SUBSET of
|
|
194
|
+
// promptTokenCount. Convert to mohdel's additive convention by subtracting
|
|
195
|
+
// the cached portion before pricing, matching the OpenAI adapter.
|
|
196
|
+
const regularInputTokens = Math.max(0, inputTokens - cacheReadTokens)
|
|
189
197
|
/** @type {import('#core/events.js').DoneEvent} */
|
|
190
198
|
const done = {
|
|
191
199
|
type: 'done',
|
|
192
200
|
result: {
|
|
193
201
|
status,
|
|
194
202
|
output: currentOutput() || null,
|
|
195
|
-
inputTokens,
|
|
203
|
+
inputTokens: regularInputTokens,
|
|
196
204
|
outputTokens,
|
|
197
205
|
thinkingTokens,
|
|
206
|
+
...(cacheReadTokens > 0 && { cacheReadInputTokens: cacheReadTokens }),
|
|
198
207
|
cost: costFor(
|
|
199
208
|
catalogKey(envelope.model),
|
|
200
|
-
{ inputTokens, outputTokens, thinkingTokens }
|
|
209
|
+
{ inputTokens: regularInputTokens, outputTokens, thinkingTokens, cacheReadInputTokens: cacheReadTokens }
|
|
201
210
|
),
|
|
202
211
|
timestamps: { start, first: first ?? end, end }
|
|
203
212
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mohdel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.114.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Christophe Le Bars",
|
|
@@ -87,16 +87,16 @@
|
|
|
87
87
|
"@opentelemetry/exporter-trace-otlp-grpc": "^0.219.0",
|
|
88
88
|
"@opentelemetry/sdk-node": "^0.219.0",
|
|
89
89
|
"chalk": "^5.4.0",
|
|
90
|
-
"mohdel-thin-gate-linux-x64-gnu": "0.
|
|
90
|
+
"mohdel-thin-gate-linux-x64-gnu": "0.114.1"
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
|
-
"@anthropic-ai/sdk": "^0.
|
|
93
|
+
"@anthropic-ai/sdk": "^0.105.0",
|
|
94
94
|
"@cerebras/cerebras_cloud_sdk": "^1.61.1",
|
|
95
|
-
"@google/genai": "^2.
|
|
95
|
+
"@google/genai": "^2.9.0",
|
|
96
96
|
"@opentelemetry/api": "^1.9.1",
|
|
97
97
|
"env-paths": "^4.0.0",
|
|
98
98
|
"groq-sdk": "^1.2.1",
|
|
99
|
-
"openai": "^6.
|
|
99
|
+
"openai": "^6.44.0",
|
|
100
100
|
"undici": "^7.24.5"
|
|
101
101
|
},
|
|
102
102
|
"lint-staged": {
|
|
@@ -107,6 +107,6 @@
|
|
|
107
107
|
"lint-staged": "^17.0.7",
|
|
108
108
|
"release-it": "^20.2.0",
|
|
109
109
|
"standard": "^17.1.2",
|
|
110
|
-
"vitest": "^4.1.
|
|
110
|
+
"vitest": "^4.1.9"
|
|
111
111
|
}
|
|
112
112
|
}
|