@mastra/observability 1.9.1-alpha.0 → 1.9.1-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.9.1-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed double-counting of Anthropic cache tokens in usage metrics ([#15316](https://github.com/mastra-ai/mastra/pull/15316))
8
+
3
9
  ## 1.9.1-alpha.0
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -18594,7 +18594,8 @@ function extractUsageMetrics(usage, providerMetadata) {
18594
18594
  if (!isDefined(inputDetails.cacheWrite) && isDefined(anthropic.cacheCreationInputTokens)) {
18595
18595
  inputDetails.cacheWrite = anthropic.cacheCreationInputTokens;
18596
18596
  }
18597
- if (!hasV3CachedTotals && (isDefined(inputDetails.cacheRead) || isDefined(inputDetails.cacheWrite))) {
18597
+ const inputAlreadyIncludesCache = hasV3CachedTotals || isDefined(usage.cachedInputTokens) && usage.cachedInputTokens > 0;
18598
+ if (!inputAlreadyIncludesCache && (isDefined(inputDetails.cacheRead) || isDefined(inputDetails.cacheWrite))) {
18598
18599
  inputTokens = (usage.inputTokens ?? 0) + (inputDetails.cacheRead ?? 0) + (inputDetails.cacheWrite ?? 0);
18599
18600
  }
18600
18601
  }