@ai-sdk/anthropic 3.0.117 → 3.0.118
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 +6 -0
- package/dist/index.d.mts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +18 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +18 -1
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +11 -4
- package/package.json +1 -1
- package/src/anthropic-message-metadata.ts +12 -0
- package/src/anthropic-messages-api.ts +15 -0
- package/src/anthropic-messages-language-model.ts +15 -0
- package/src/anthropic-messages-options.ts +1 -1
package/docs/05-anthropic.mdx
CHANGED
|
@@ -473,12 +473,13 @@ const result = streamText({
|
|
|
473
473
|
##### Thinking Block Binding
|
|
474
474
|
|
|
475
475
|
Fable 5.1 can recover from a thinking-block prefix mismatch by dropping the
|
|
476
|
-
mismatched block. Set `blockBinding.prefixMismatchBehavior` to `drop_block
|
|
477
|
-
You can provide block binding by itself
|
|
478
|
-
thinking mode, or combine it with adaptive
|
|
476
|
+
mismatched block. Set `blockBinding.prefixMismatchBehavior` to `drop_block`, or
|
|
477
|
+
set it to `error` to reject the request. You can provide block binding by itself
|
|
478
|
+
to preserve the model's default thinking mode, or combine it with adaptive
|
|
479
|
+
thinking.
|
|
479
480
|
|
|
480
481
|
```ts highlight="7-11"
|
|
481
|
-
const
|
|
482
|
+
const result = await generateText({
|
|
482
483
|
model: anthropic('claude-fable-5-1'),
|
|
483
484
|
prompt: 'Continue from this conversation.',
|
|
484
485
|
providerOptions: {
|
|
@@ -491,8 +492,14 @@ const { text } = await generateText({
|
|
|
491
492
|
} satisfies AnthropicLanguageModelOptions,
|
|
492
493
|
},
|
|
493
494
|
});
|
|
495
|
+
|
|
496
|
+
console.log(result.providerMetadata?.anthropic?.inputTransformations);
|
|
494
497
|
```
|
|
495
498
|
|
|
499
|
+
Dropped blocks are reported in
|
|
500
|
+
`providerMetadata.anthropic.inputTransformations` with their `type`, `path`, and
|
|
501
|
+
`reason`.
|
|
502
|
+
|
|
496
503
|
#### Budget-Based Thinking
|
|
497
504
|
|
|
498
505
|
For earlier models (`claude-opus-4-20250514`, `claude-sonnet-4-20250514`, `claude-sonnet-4-5-20250929`),
|
package/package.json
CHANGED
|
@@ -53,6 +53,18 @@ export interface AnthropicMessageMetadata {
|
|
|
53
53
|
cacheCreationInputTokens: number | null;
|
|
54
54
|
stopSequence: string | null;
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Input blocks that Anthropic transformed before inference. This is
|
|
58
|
+
* populated when thinking binding controls drop a mismatched thinking block.
|
|
59
|
+
* Values are intentionally open-ended so new transformation types and
|
|
60
|
+
* reasons remain forward compatible.
|
|
61
|
+
*/
|
|
62
|
+
inputTransformations?: Array<{
|
|
63
|
+
type: string;
|
|
64
|
+
path: string;
|
|
65
|
+
reason: string;
|
|
66
|
+
}>;
|
|
67
|
+
|
|
56
68
|
/**
|
|
57
69
|
* Details about why the request stopped. Present only when the API returns
|
|
58
70
|
* a `refusal` stop reason together with a `stop_details` object (a
|
|
@@ -645,6 +645,12 @@ const anthropicToolCallCallerSchema = z.union([
|
|
|
645
645
|
}),
|
|
646
646
|
]);
|
|
647
647
|
|
|
648
|
+
const anthropicInputTransformationSchema = z.object({
|
|
649
|
+
type: z.string(),
|
|
650
|
+
path: z.string(),
|
|
651
|
+
reason: z.string(),
|
|
652
|
+
});
|
|
653
|
+
|
|
648
654
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
649
655
|
// this approach limits breakages when the API changes and increases efficiency
|
|
650
656
|
export const anthropicMessagesResponseSchema = lazySchema(() =>
|
|
@@ -934,6 +940,9 @@ export const anthropicMessagesResponseSchema = lazySchema(() =>
|
|
|
934
940
|
stop_reason: z.string().nullish(),
|
|
935
941
|
stop_sequence: z.string().nullish(),
|
|
936
942
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
943
|
+
input_transformations: z
|
|
944
|
+
.array(anthropicInputTransformationSchema)
|
|
945
|
+
.nullish(),
|
|
937
946
|
usage: z.looseObject({
|
|
938
947
|
input_tokens: z.number(),
|
|
939
948
|
output_tokens: z.number(),
|
|
@@ -1033,6 +1042,9 @@ export const anthropicMessagesChunkSchema = lazySchema(() =>
|
|
|
1033
1042
|
)
|
|
1034
1043
|
.nullish(),
|
|
1035
1044
|
stop_reason: z.string().nullish(),
|
|
1045
|
+
input_transformations: z
|
|
1046
|
+
.array(anthropicInputTransformationSchema)
|
|
1047
|
+
.nullish(),
|
|
1036
1048
|
container: z
|
|
1037
1049
|
.object({
|
|
1038
1050
|
expires_at: z.string(),
|
|
@@ -1409,6 +1421,9 @@ export const anthropicMessagesChunkSchema = lazySchema(() =>
|
|
|
1409
1421
|
)
|
|
1410
1422
|
.nullish(),
|
|
1411
1423
|
}),
|
|
1424
|
+
input_transformations: z
|
|
1425
|
+
.array(anthropicInputTransformationSchema)
|
|
1426
|
+
.nullish(),
|
|
1412
1427
|
context_management: z
|
|
1413
1428
|
.object({
|
|
1414
1429
|
applied_edits: z.array(
|
|
@@ -1435,6 +1435,9 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
1435
1435
|
response.usage.cache_creation_input_tokens ?? null,
|
|
1436
1436
|
stopSequence: response.stop_sequence ?? null,
|
|
1437
1437
|
...(stopDetails != null ? { stopDetails } : {}),
|
|
1438
|
+
...(response.input_transformations != null
|
|
1439
|
+
? { inputTransformations: response.input_transformations }
|
|
1440
|
+
: {}),
|
|
1438
1441
|
|
|
1439
1442
|
iterations: response.usage.iterations
|
|
1440
1443
|
? response.usage.iterations.map(
|
|
@@ -1572,6 +1575,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
1572
1575
|
let cacheCreationInputTokens: number | null = null;
|
|
1573
1576
|
let stopSequence: string | null = null;
|
|
1574
1577
|
let stopDetails: AnthropicMessageMetadata['stopDetails'] = undefined;
|
|
1578
|
+
let inputTransformations: AnthropicMessageMetadata['inputTransformations'];
|
|
1575
1579
|
let container: AnthropicMessageMetadata['container'] | null = null;
|
|
1576
1580
|
let isJsonResponseFromTool = false;
|
|
1577
1581
|
let isMessageOpen = false;
|
|
@@ -2433,6 +2437,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
2433
2437
|
cacheCreationInputTokens =
|
|
2434
2438
|
value.message.usage.cache_creation_input_tokens ?? null;
|
|
2435
2439
|
|
|
2440
|
+
if (value.message.input_transformations != null) {
|
|
2441
|
+
inputTransformations = value.message.input_transformations;
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2436
2444
|
if (value.message.container != null) {
|
|
2437
2445
|
container = {
|
|
2438
2446
|
expiresAt: value.message.container.expires_at,
|
|
@@ -2563,6 +2571,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
2563
2571
|
);
|
|
2564
2572
|
}
|
|
2565
2573
|
|
|
2574
|
+
if (value.input_transformations != null) {
|
|
2575
|
+
inputTransformations = value.input_transformations;
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2566
2578
|
rawUsage = {
|
|
2567
2579
|
...rawUsage,
|
|
2568
2580
|
...(value.usage as JSONObject),
|
|
@@ -2580,6 +2592,9 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
2580
2592
|
cacheCreationInputTokens,
|
|
2581
2593
|
stopSequence,
|
|
2582
2594
|
...(stopDetails != null ? { stopDetails } : {}),
|
|
2595
|
+
...(inputTransformations != null
|
|
2596
|
+
? { inputTransformations }
|
|
2597
|
+
: {}),
|
|
2583
2598
|
iterations: usage.iterations
|
|
2584
2599
|
? usage.iterations.map(
|
|
2585
2600
|
iter =>
|
|
@@ -117,7 +117,7 @@ export type AnthropicSystemMessageProviderOptions = z.infer<
|
|
|
117
117
|
>;
|
|
118
118
|
|
|
119
119
|
const anthropicThinkingBlockBinding = z.object({
|
|
120
|
-
prefixMismatchBehavior: z.
|
|
120
|
+
prefixMismatchBehavior: z.enum(['error', 'drop_block']),
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
export const anthropicLanguageModelOptions = z.object({
|