@rulvar/anthropic 1.122.0 → 1.124.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/dist/index.d.ts CHANGED
@@ -149,7 +149,14 @@ declare function mapStopReason(stopReason: string | null | undefined, stopDetail
149
149
  /**
150
150
  * Normalizes Messages API usage under the Usage invariant: Anthropic
151
151
  * reports input_tokens EXCLUDING cache reads and writes, so the canonical
152
- * inputTokens is the sum of all three.
152
+ * inputTokens is the sum of all three. The `cache_creation` breakdown
153
+ * (ephemeral_5m_input_tokens / ephemeral_1h_input_tokens) fills the
154
+ * canonical TTL split (RV810) when it agrees with the flat total, so the
155
+ * 1h premium prices at its own rate downstream; a breakdown that
156
+ * contradicts the flat total is dropped rather than shipped as a broken
157
+ * invariant (the flat total is the billable number, and the
158
+ * undifferentiated 5m-rate fold is the historical conservative default).
159
+ * With no flat field, the breakdown IS the total.
153
160
  */
154
161
  declare function normalizeAnthropicUsage(raw: Record<string, unknown> | undefined): Usage;
155
162
  interface TurnMapping {
package/dist/index.js CHANGED
@@ -429,18 +429,35 @@ function mapStopReason(stopReason, stopDetails) {
429
429
  /**
430
430
  * Normalizes Messages API usage under the Usage invariant: Anthropic
431
431
  * reports input_tokens EXCLUDING cache reads and writes, so the canonical
432
- * inputTokens is the sum of all three.
432
+ * inputTokens is the sum of all three. The `cache_creation` breakdown
433
+ * (ephemeral_5m_input_tokens / ephemeral_1h_input_tokens) fills the
434
+ * canonical TTL split (RV810) when it agrees with the flat total, so the
435
+ * 1h premium prices at its own rate downstream; a breakdown that
436
+ * contradicts the flat total is dropped rather than shipped as a broken
437
+ * invariant (the flat total is the billable number, and the
438
+ * undifferentiated 5m-rate fold is the historical conservative default).
439
+ * With no flat field, the breakdown IS the total.
433
440
  */
434
441
  function normalizeAnthropicUsage(raw) {
435
442
  const input = typeof raw?.input_tokens === "number" ? raw.input_tokens : 0;
436
443
  const output = typeof raw?.output_tokens === "number" ? raw.output_tokens : 0;
437
444
  const cacheRead = typeof raw?.cache_read_input_tokens === "number" ? raw.cache_read_input_tokens : 0;
438
- const cacheWrite = typeof raw?.cache_creation_input_tokens === "number" ? raw.cache_creation_input_tokens : 0;
445
+ const flatWrite = typeof raw?.cache_creation_input_tokens === "number" ? raw.cache_creation_input_tokens : void 0;
446
+ const breakdown = raw?.cache_creation;
447
+ const write5m = typeof breakdown?.ephemeral_5m_input_tokens === "number" ? breakdown.ephemeral_5m_input_tokens : void 0;
448
+ const write1h = typeof breakdown?.ephemeral_1h_input_tokens === "number" ? breakdown.ephemeral_1h_input_tokens : void 0;
449
+ const splitSum = write5m === void 0 && write1h === void 0 ? void 0 : (write5m ?? 0) + (write1h ?? 0);
450
+ const cacheWrite = flatWrite ?? splitSum ?? 0;
451
+ const splitAgrees = splitSum !== void 0 && splitSum === cacheWrite;
439
452
  return {
440
453
  inputTokens: input + cacheRead + cacheWrite,
441
454
  outputTokens: output,
442
455
  cacheReadTokens: cacheRead,
443
- cacheWriteTokens: cacheWrite
456
+ cacheWriteTokens: cacheWrite,
457
+ ...splitAgrees ? {
458
+ cacheWrite5mTokens: write5m ?? 0,
459
+ cacheWrite1hTokens: write1h ?? 0
460
+ } : {}
444
461
  };
445
462
  }
446
463
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/anthropic",
3
- "version": "1.122.0",
3
+ "version": "1.124.0",
4
4
  "description": "Rulvar first-class provider adapter over @anthropic-ai/sdk.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -23,13 +23,13 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@anthropic-ai/sdk": "^0.115.0",
26
- "@rulvar/core": "1.122.0"
26
+ "@rulvar/core": "1.124.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^22.20.1",
30
30
  "tsdown": "^0.22.14",
31
31
  "typescript": "~6.0.3",
32
- "@rulvar/testing": "1.122.0"
32
+ "@rulvar/testing": "1.124.0"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",