@ai-sdk/anthropic 4.0.52 → 4.0.53

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,19 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.53
4
+
5
+ ### Patch Changes
6
+
7
+ - 5ec21a6: fix: reject unsupported batch request types
8
+ - 7469a3b: feat: support image generation requests in batches
9
+ - e4292e7: feat(anthropic): expand preserved thinking support to cover `prefix_mismatch_behavior: 'error'`
10
+ - Updated dependencies [5ec21a6]
11
+ - Updated dependencies [7469a3b]
12
+ - Updated dependencies [813bb36]
13
+ - Updated dependencies [c43e4b7]
14
+ - @ai-sdk/provider@4.0.14
15
+ - @ai-sdk/provider-utils@5.0.40
16
+
3
17
  ## 4.0.52
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -46,6 +46,17 @@ type AnthropicUsageIteration = {
46
46
  interface AnthropicMessageMetadata {
47
47
  usage: JSONObject;
48
48
  stopSequence: string | null;
49
+ /**
50
+ * Input blocks that Anthropic transformed before inference. This is
51
+ * populated when thinking binding controls drop a mismatched thinking block.
52
+ * Values are intentionally open-ended so new transformation types and
53
+ * reasons remain forward compatible.
54
+ */
55
+ inputTransformations?: Array<{
56
+ type: string;
57
+ path: string;
58
+ reason: string;
59
+ }>;
49
60
  /**
50
61
  * Details about why the request stopped. Present only when the API returns
51
62
  * a `refusal` stop reason together with a `stop_details` object (a
@@ -220,7 +231,10 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
220
231
  updates: "updates";
221
232
  }>>;
222
233
  blockBinding: z.ZodOptional<z.ZodObject<{
223
- prefixMismatchBehavior: z.ZodLiteral<"drop_block">;
234
+ prefixMismatchBehavior: z.ZodEnum<{
235
+ error: "error";
236
+ drop_block: "drop_block";
237
+ }>;
224
238
  }, z.core.$strip>>;
225
239
  }, z.core.$strip>, z.ZodObject<{
226
240
  type: z.ZodLiteral<"enabled">;
@@ -230,7 +244,10 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
230
244
  }, z.core.$strip>]>, z.ZodObject<{
231
245
  type: z.ZodOptional<z.ZodNever>;
232
246
  blockBinding: z.ZodObject<{
233
- prefixMismatchBehavior: z.ZodLiteral<"drop_block">;
247
+ prefixMismatchBehavior: z.ZodEnum<{
248
+ error: "error";
249
+ drop_block: "drop_block";
250
+ }>;
234
251
  }, z.core.$strip>;
235
252
  }, z.core.$strip>]>>;
236
253
  disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
package/dist/index.js CHANGED
@@ -228,6 +228,11 @@ var anthropicMcpToolResultContentSchema = z3.union([
228
228
  ])
229
229
  )
230
230
  ]);
231
+ var anthropicInputTransformationSchema = z3.object({
232
+ type: z3.string(),
233
+ path: z3.string(),
234
+ reason: z3.string()
235
+ });
231
236
  var anthropicResponseSchema = lazySchema3(
232
237
  () => zodSchema3(
233
238
  z3.object({
@@ -482,6 +487,7 @@ var anthropicResponseSchema = lazySchema3(
482
487
  stop_reason: z3.string().nullish(),
483
488
  stop_sequence: z3.string().nullish(),
484
489
  stop_details: anthropicStopDetailsSchema.nullish(),
490
+ input_transformations: z3.array(anthropicInputTransformationSchema).nullish(),
485
491
  usage: z3.looseObject({
486
492
  input_tokens: z3.number(),
487
493
  output_tokens: z3.number(),
@@ -566,6 +572,7 @@ var anthropicChunkSchema = lazySchema3(
566
572
  ])
567
573
  ).nullish(),
568
574
  stop_reason: z3.string().nullish(),
575
+ input_transformations: z3.array(anthropicInputTransformationSchema).nullish(),
569
576
  container: z3.object({
570
577
  expires_at: z3.string(),
571
578
  id: z3.string()
@@ -903,6 +910,7 @@ var anthropicChunkSchema = lazySchema3(
903
910
  })
904
911
  ).nullish()
905
912
  }),
913
+ input_transformations: z3.array(anthropicInputTransformationSchema).nullish(),
906
914
  context_management: z3.object({
907
915
  applied_edits: z3.array(
908
916
  z3.union([
@@ -1051,7 +1059,7 @@ var anthropicLanguageModelOptions = z4.object({
1051
1059
  * prefix. Requires the `thinking-binding-controls-2026-08-01` beta.
1052
1060
  */
1053
1061
  blockBinding: z4.object({
1054
- prefixMismatchBehavior: z4.literal("drop_block")
1062
+ prefixMismatchBehavior: z4.enum(["error", "drop_block"])
1055
1063
  }).optional()
1056
1064
  }),
1057
1065
  z4.object({
@@ -1066,7 +1074,7 @@ var anthropicLanguageModelOptions = z4.object({
1066
1074
  z4.object({
1067
1075
  type: z4.never().optional(),
1068
1076
  blockBinding: z4.object({
1069
- prefixMismatchBehavior: z4.literal("drop_block")
1077
+ prefixMismatchBehavior: z4.enum(["error", "drop_block"])
1070
1078
  })
1071
1079
  })
1072
1080
  ]).optional(),
@@ -4822,6 +4830,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4822
4830
  usage: response.usage,
4823
4831
  stopSequence: (_a2 = response.stop_sequence) != null ? _a2 : null,
4824
4832
  ...stopDetails != null ? { stopDetails } : {},
4833
+ ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
4825
4834
  iterations: response.usage.iterations ? response.usage.iterations.map(
4826
4835
  (iter) => ({
4827
4836
  type: iter.type,
@@ -4909,6 +4918,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4909
4918
  let rawUsage = void 0;
4910
4919
  let stopSequence = null;
4911
4920
  let stopDetails = void 0;
4921
+ let inputTransformations;
4912
4922
  let container = null;
4913
4923
  let isJsonResponseFromTool = false;
4914
4924
  let isMessageOpen = false;
@@ -5578,6 +5588,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5578
5588
  rawUsage = {
5579
5589
  ...value.message.usage
5580
5590
  };
5591
+ if (value.message.input_transformations != null) {
5592
+ inputTransformations = value.message.input_transformations;
5593
+ }
5581
5594
  if (value.message.container != null) {
5582
5595
  container = {
5583
5596
  expiresAt: value.message.container.expires_at,
@@ -5677,6 +5690,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5677
5690
  value.context_management
5678
5691
  );
5679
5692
  }
5693
+ if (value.input_transformations != null) {
5694
+ inputTransformations = value.input_transformations;
5695
+ }
5680
5696
  rawUsage = {
5681
5697
  ...rawUsage,
5682
5698
  ...value.usage
@@ -5690,6 +5706,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5690
5706
  usage: rawUsage != null ? rawUsage : null,
5691
5707
  stopSequence,
5692
5708
  ...stopDetails != null ? { stopDetails } : {},
5709
+ ...inputTransformations != null ? { inputTransformations } : {},
5693
5710
  iterations: usage.iterations ? usage.iterations.map(
5694
5711
  (iter) => ({
5695
5712
  type: iter.type,
@@ -6088,6 +6105,17 @@ var anthropicBatchResultLineSchema = lazySchema14(
6088
6105
  })
6089
6106
  )
6090
6107
  );
6108
+ function assertTextBatchRequests(requests) {
6109
+ for (const request of requests) {
6110
+ const requestType = request.type;
6111
+ if (requestType !== "text") {
6112
+ throw new UnsupportedFunctionalityError3({
6113
+ functionality: `batch request type: ${requestType}`,
6114
+ message: `The Anthropic Message Batches API does not support batch requests with type "${requestType}".`
6115
+ });
6116
+ }
6117
+ }
6118
+ }
6091
6119
  var AnthropicBatch = class {
6092
6120
  constructor(options) {
6093
6121
  this.options = options;
@@ -6105,6 +6133,7 @@ var AnthropicBatch = class {
6105
6133
  webhookUrl
6106
6134
  }) {
6107
6135
  var _a, _b, _c, _d;
6136
+ assertTextBatchRequests(requests);
6108
6137
  validateRequestIds(requests);
6109
6138
  const explicitBatchBetas = new Set(
6110
6139
  await getAnthropicBatchProviderBetas({
@@ -6820,6 +6849,7 @@ function convertAnthropicMessageMetadata(response) {
6820
6849
  usage: response.usage,
6821
6850
  stopSequence: (_a = response.stop_sequence) != null ? _a : null,
6822
6851
  ...stopDetails != null ? { stopDetails } : {},
6852
+ ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
6823
6853
  iterations: response.usage.iterations ? response.usage.iterations.map(
6824
6854
  (iteration) => ({
6825
6855
  type: iteration.type,
@@ -7622,7 +7652,7 @@ var AnthropicSkills = class {
7622
7652
  };
7623
7653
 
7624
7654
  // src/version.ts
7625
- var VERSION = true ? "4.0.52" : "0.0.0-test";
7655
+ var VERSION = true ? "4.0.53" : "0.0.0-test";
7626
7656
 
7627
7657
  // src/anthropic-provider.ts
7628
7658
  var ANTHROPIC_API_URL = "https://api.anthropic.com";