@ai-sdk/anthropic 4.0.20 → 4.0.21

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": "4.0.20",
3
+ "version": "4.0.21",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -43,8 +43,8 @@
43
43
  "tsup": "^8.5.1",
44
44
  "typescript": "5.8.3",
45
45
  "zod": "3.25.76",
46
- "@vercel/ai-tsconfig": "0.0.0",
47
- "@ai-sdk/test-server": "2.0.0"
46
+ "@ai-sdk/test-server": "2.0.0",
47
+ "@vercel/ai-tsconfig": "0.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "zod": "^3.25.76 || ^4.1.8"
@@ -949,6 +949,11 @@ export const anthropicResponseSchema = lazySchema(() =>
949
949
  usage: z.looseObject({
950
950
  input_tokens: z.number(),
951
951
  output_tokens: z.number(),
952
+ output_tokens_details: z
953
+ .object({
954
+ thinking_tokens: z.number().nullish(),
955
+ })
956
+ .nullish(),
952
957
  cache_creation_input_tokens: z.number().nullish(),
953
958
  cache_read_input_tokens: z.number().nullish(),
954
959
  iterations: z
@@ -1427,6 +1432,11 @@ export const anthropicChunkSchema = lazySchema(() =>
1427
1432
  usage: z.looseObject({
1428
1433
  input_tokens: z.number().nullish(),
1429
1434
  output_tokens: z.number(),
1435
+ output_tokens_details: z
1436
+ .object({
1437
+ thinking_tokens: z.number().nullish(),
1438
+ })
1439
+ .nullish(),
1430
1440
  cache_creation_input_tokens: z.number().nullish(),
1431
1441
  cache_read_input_tokens: z.number().nullish(),
1432
1442
  iterations: z
@@ -2504,6 +2504,9 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
2504
2504
  usage.input_tokens = value.usage.input_tokens;
2505
2505
  }
2506
2506
  usage.output_tokens = value.usage.output_tokens;
2507
+ if (value.usage.output_tokens_details != null) {
2508
+ usage.output_tokens_details = value.usage.output_tokens_details;
2509
+ }
2507
2510
 
2508
2511
  if (value.usage.cache_read_input_tokens != null) {
2509
2512
  usage.cache_read_input_tokens =
@@ -28,6 +28,9 @@ export type AnthropicUsageIteration = {
28
28
  export type AnthropicUsage = {
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 convertAnthropicUsage({
50
53
  }): LanguageModelV4Usage {
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 convertAnthropicUsage({
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
  };