@ai-sdk/anthropic 3.0.102 → 3.0.103

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "3.0.102",
3
+ "version": "3.0.103",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -938,6 +938,11 @@ export const anthropicMessagesResponseSchema = lazySchema(() =>
938
938
  usage: z.looseObject({
939
939
  input_tokens: z.number(),
940
940
  output_tokens: z.number(),
941
+ output_tokens_details: z
942
+ .object({
943
+ thinking_tokens: z.number().nullish(),
944
+ })
945
+ .nullish(),
941
946
  cache_creation_input_tokens: z.number().nullish(),
942
947
  cache_read_input_tokens: z.number().nullish(),
943
948
  iterations: z
@@ -1416,6 +1421,11 @@ export const anthropicMessagesChunkSchema = lazySchema(() =>
1416
1421
  usage: z.looseObject({
1417
1422
  input_tokens: z.number().nullish(),
1418
1423
  output_tokens: z.number(),
1424
+ output_tokens_details: z
1425
+ .object({
1426
+ thinking_tokens: z.number().nullish(),
1427
+ })
1428
+ .nullish(),
1419
1429
  cache_creation_input_tokens: z.number().nullish(),
1420
1430
  cache_read_input_tokens: z.number().nullish(),
1421
1431
  iterations: z
@@ -2455,6 +2455,9 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
2455
2455
  usage.input_tokens = value.usage.input_tokens;
2456
2456
  }
2457
2457
  usage.output_tokens = value.usage.output_tokens;
2458
+ if (value.usage.output_tokens_details != null) {
2459
+ usage.output_tokens_details = value.usage.output_tokens_details;
2460
+ }
2458
2461
 
2459
2462
  if (value.usage.cache_read_input_tokens != null) {
2460
2463
  usage.cache_read_input_tokens =
@@ -28,6 +28,9 @@ export type AnthropicUsageIteration = {
28
28
  export type AnthropicMessagesUsage = {
29
29
  input_tokens: number;
30
30
  output_tokens: number;
31
+ output_tokens_details?: {
32
+ thinking_tokens?: number | null;
33
+ } | null;
31
34
  cache_creation_input_tokens?: number | null;
32
35
  cache_read_input_tokens?: number | null;
33
36
  /**
@@ -50,6 +53,8 @@ export function convertAnthropicMessagesUsage({
50
53
  }): LanguageModelV3Usage {
51
54
  const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
52
55
  const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
56
+ const reasoningTokens =
57
+ usage.output_tokens_details?.thinking_tokens ?? undefined;
53
58
 
54
59
  // When iterations is present (compaction or advisor), sum across executor
55
60
  // iterations to get the true executor totals. The top-level input_tokens
@@ -101,8 +106,9 @@ export function convertAnthropicMessagesUsage({
101
106
  },
102
107
  outputTokens: {
103
108
  total: outputTokens,
104
- text: undefined,
105
- reasoning: undefined,
109
+ text:
110
+ reasoningTokens == null ? undefined : outputTokens - reasoningTokens,
111
+ reasoning: reasoningTokens,
106
112
  },
107
113
  raw: rawUsage ?? usage,
108
114
  };