@ai-sdk/anthropic 3.0.126 → 3.0.128

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.
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
- type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
5
+ type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-haiku-5-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -62,6 +62,11 @@ declare function getModelCapabilities(modelId: string): {
62
62
  * are rejected with a 400.
63
63
  */
64
64
  rejectsThinkingDisabled: boolean;
65
+ /**
66
+ * Budget-based thinking (`thinking.type` `enabled` with `budget_tokens`) is
67
+ * rejected with a 400. Only adaptive thinking is supported.
68
+ */
69
+ rejectsBudgetThinking: boolean;
65
70
  /**
66
71
  * Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
67
72
  */
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
- type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
5
+ type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-haiku-5-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -62,6 +62,11 @@ declare function getModelCapabilities(modelId: string): {
62
62
  * are rejected with a 400.
63
63
  */
64
64
  rejectsThinkingDisabled: boolean;
65
+ /**
66
+ * Budget-based thinking (`thinking.type` `enabled` with `budget_tokens`) is
67
+ * rejected with a 400. Only adaptive thinking is supported.
68
+ */
69
+ rejectsBudgetThinking: boolean;
65
70
  /**
66
71
  * Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
67
72
  */
@@ -60,6 +60,20 @@ var anthropicStopDetailsSchema = import_v42.z.object({
60
60
  explanation: import_v42.z.string().nullish(),
61
61
  recommended_model: import_v42.z.string().nullish()
62
62
  });
63
+ var anthropicSafeguardResultSchema = import_v42.z.object({
64
+ type: import_v42.z.string(),
65
+ status: import_v42.z.object({
66
+ type: import_v42.z.string(),
67
+ tool_uses: import_v42.z.record(
68
+ import_v42.z.string(),
69
+ import_v42.z.object({
70
+ type: import_v42.z.string(),
71
+ outcome: import_v42.z.string().nullish(),
72
+ explanation: import_v42.z.string().nullish()
73
+ })
74
+ ).nullish()
75
+ })
76
+ });
63
77
  var anthropicToolCallCallerSchema = import_v42.z.union([
64
78
  import_v42.z.object({
65
79
  type: import_v42.z.literal("code_execution_20250825"),
@@ -360,6 +374,7 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
360
374
  stop_sequence: import_v42.z.string().nullish(),
361
375
  stop_details: anthropicStopDetailsSchema.nullish(),
362
376
  input_transformations: import_v42.z.array(anthropicInputTransformationSchema).nullish(),
377
+ safeguard_results: import_v42.z.array(anthropicSafeguardResultSchema).nullish(),
363
378
  usage: import_v42.z.looseObject({
364
379
  input_tokens: import_v42.z.number(),
365
380
  output_tokens: import_v42.z.number(),
@@ -769,6 +784,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
769
784
  stop_reason: import_v42.z.string().nullish(),
770
785
  stop_sequence: import_v42.z.string().nullish(),
771
786
  stop_details: anthropicStopDetailsSchema.nullish(),
787
+ safeguard_results: import_v42.z.array(anthropicSafeguardResultSchema).nullish(),
772
788
  container: import_v42.z.object({
773
789
  expires_at: import_v42.z.string(),
774
790
  id: import_v42.z.string(),
@@ -1127,6 +1143,22 @@ var anthropicLanguageModelOptions = import_v43.z.object({
1127
1143
  * Allow a provider to receive the full `betas` set if it needs it.
1128
1144
  */
1129
1145
  anthropicBeta: import_v43.z.array(import_v43.z.string()).optional(),
1146
+ /**
1147
+ * Server-side safeguards to run as part of the request.
1148
+ *
1149
+ * `dangerous_tool_use` asks the API to classify every `tool_use` block in
1150
+ * the response for dangerous actions (the check Claude Code's auto mode
1151
+ * relies on). The per-call verdicts are returned in
1152
+ * `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
1153
+ * `classifierContext` is passed through to the API as `classifier_context`.
1154
+ * The `dangerous-tool-use-2026-09-03` beta is added automatically.
1155
+ */
1156
+ safeguards: import_v43.z.array(
1157
+ import_v43.z.object({
1158
+ type: import_v43.z.literal("dangerous_tool_use"),
1159
+ classifierContext: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional()
1160
+ })
1161
+ ).optional(),
1130
1162
  contextManagement: import_v43.z.object({
1131
1163
  edits: import_v43.z.array(
1132
1164
  import_v43.z.discriminatedUnion("type", [
@@ -3784,6 +3816,7 @@ var AnthropicMessagesLanguageModel = class {
3784
3816
  rejectsSamplingParameters,
3785
3817
  rejectsThinkingDisabledAboveHighEffort,
3786
3818
  rejectsThinkingDisabled,
3819
+ rejectsBudgetThinking,
3787
3820
  rejectsForcedToolUse,
3788
3821
  supportsBetweenToolsThinking,
3789
3822
  isKnownModel
@@ -3901,15 +3934,16 @@ var AnthropicMessagesLanguageModel = class {
3901
3934
  details: `thinking cannot be disabled for ${this.modelId}; it always uses adaptive thinking. The thinking setting has been removed. Lower 'effort' to reduce thinking.`
3902
3935
  });
3903
3936
  anthropicOptions.thinking = void 0;
3904
- } else if (requestedType === "enabled") {
3905
- warnings.push({
3906
- type: "unsupported",
3907
- feature: "providerOptions.anthropic.thinking",
3908
- details: `budget-based thinking is not supported by ${this.modelId}; it always uses adaptive thinking. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`
3909
- });
3910
- anthropicOptions.thinking = { type: "adaptive" };
3911
3937
  }
3912
3938
  }
3939
+ if (rejectsBudgetThinking && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "type" in anthropicOptions.thinking && anthropicOptions.thinking.type === "enabled") {
3940
+ warnings.push({
3941
+ type: "unsupported",
3942
+ feature: "providerOptions.anthropic.thinking",
3943
+ details: rejectsThinkingDisabled ? `budget-based thinking is not supported by ${this.modelId}; it always uses adaptive thinking. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.` : `budget-based thinking is not supported by ${this.modelId}. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`
3944
+ });
3945
+ anthropicOptions.thinking = { type: "adaptive" };
3946
+ }
3913
3947
  const thinking = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
3914
3948
  const thinkingType = thinking != null && "type" in thinking ? thinking.type : void 0;
3915
3949
  if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
@@ -4027,6 +4061,14 @@ var AnthropicMessagesLanguageModel = class {
4027
4061
  // prompt:
4028
4062
  system: messagesPrompt.system,
4029
4063
  messages: messagesPrompt.messages,
4064
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
4065
+ safeguards: anthropicOptions.safeguards.map((safeguard) => ({
4066
+ type: safeguard.type,
4067
+ ...safeguard.classifierContext !== void 0 && {
4068
+ classifier_context: safeguard.classifierContext
4069
+ }
4070
+ }))
4071
+ },
4030
4072
  ...contextManagement && {
4031
4073
  context_management: {
4032
4074
  edits: contextManagement.edits.map((edit) => {
@@ -4139,6 +4181,9 @@ var AnthropicMessagesLanguageModel = class {
4139
4181
  if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
4140
4182
  betas.add("mcp-client-2025-04-04");
4141
4183
  }
4184
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
4185
+ betas.add("dangerous-tool-use-2026-09-03");
4186
+ }
4142
4187
  if (contextManagement) {
4143
4188
  betas.add("context-management-2025-06-27");
4144
4189
  if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
@@ -4762,6 +4807,7 @@ var AnthropicMessagesLanguageModel = class {
4762
4807
  stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
4763
4808
  ...stopDetails != null ? { stopDetails } : {},
4764
4809
  ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
4810
+ ...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
4765
4811
  iterations: response.usage.iterations ? response.usage.iterations.map(
4766
4812
  (iter) => ({
4767
4813
  type: iter.type,
@@ -4852,6 +4898,7 @@ var AnthropicMessagesLanguageModel = class {
4852
4898
  let stopSequence = null;
4853
4899
  let stopDetails = void 0;
4854
4900
  let inputTransformations;
4901
+ let safeguardResults;
4855
4902
  let container = null;
4856
4903
  let isJsonResponseFromTool = false;
4857
4904
  let isMessageOpen = false;
@@ -5673,6 +5720,9 @@ var AnthropicMessagesLanguageModel = class {
5673
5720
  if (value.input_transformations != null) {
5674
5721
  inputTransformations = value.input_transformations;
5675
5722
  }
5723
+ if (value.delta.safeguard_results != null) {
5724
+ safeguardResults = value.delta.safeguard_results;
5725
+ }
5676
5726
  rawUsage = {
5677
5727
  ...rawUsage,
5678
5728
  ...value.usage
@@ -5688,6 +5738,7 @@ var AnthropicMessagesLanguageModel = class {
5688
5738
  stopSequence,
5689
5739
  ...stopDetails != null ? { stopDetails } : {},
5690
5740
  ...inputTransformations != null ? { inputTransformations } : {},
5741
+ ...safeguardResults != null ? { safeguardResults } : {},
5691
5742
  iterations: usage.iterations ? usage.iterations.map(
5692
5743
  (iter) => ({
5693
5744
  type: iter.type,
@@ -5771,6 +5822,7 @@ function getModelCapabilities(modelId) {
5771
5822
  rejectsSamplingParameters: true,
5772
5823
  rejectsThinkingDisabledAboveHighEffort: true,
5773
5824
  rejectsThinkingDisabled: true,
5825
+ rejectsBudgetThinking: true,
5774
5826
  rejectsForcedToolUse: true,
5775
5827
  supportsBetweenToolsThinking: true,
5776
5828
  isKnownModel: true
@@ -5782,10 +5834,23 @@ function getModelCapabilities(modelId) {
5782
5834
  rejectsSamplingParameters: true,
5783
5835
  rejectsThinkingDisabledAboveHighEffort: true,
5784
5836
  rejectsThinkingDisabled: true,
5837
+ rejectsBudgetThinking: true,
5785
5838
  rejectsForcedToolUse: true,
5786
5839
  supportsBetweenToolsThinking: false,
5787
5840
  isKnownModel: true
5788
5841
  };
5842
+ } else if (modelId.includes("claude-haiku-5-5")) {
5843
+ return {
5844
+ maxOutputTokens: 128e3,
5845
+ supportsStructuredOutput: true,
5846
+ rejectsSamplingParameters: true,
5847
+ rejectsThinkingDisabledAboveHighEffort: true,
5848
+ rejectsThinkingDisabled: false,
5849
+ rejectsBudgetThinking: true,
5850
+ rejectsForcedToolUse: false,
5851
+ supportsBetweenToolsThinking: false,
5852
+ isKnownModel: true
5853
+ };
5789
5854
  } else if (modelId.includes("claude-opus-5")) {
5790
5855
  return {
5791
5856
  maxOutputTokens: 128e3,
@@ -5793,6 +5858,7 @@ function getModelCapabilities(modelId) {
5793
5858
  rejectsSamplingParameters: true,
5794
5859
  rejectsThinkingDisabledAboveHighEffort: true,
5795
5860
  rejectsThinkingDisabled: false,
5861
+ rejectsBudgetThinking: false,
5796
5862
  rejectsForcedToolUse: false,
5797
5863
  supportsBetweenToolsThinking: false,
5798
5864
  isKnownModel: true
@@ -5804,6 +5870,7 @@ function getModelCapabilities(modelId) {
5804
5870
  rejectsSamplingParameters: true,
5805
5871
  rejectsThinkingDisabledAboveHighEffort: false,
5806
5872
  rejectsThinkingDisabled: true,
5873
+ rejectsBudgetThinking: true,
5807
5874
  rejectsForcedToolUse: true,
5808
5875
  supportsBetweenToolsThinking: false,
5809
5876
  isKnownModel: true
@@ -5815,6 +5882,7 @@ function getModelCapabilities(modelId) {
5815
5882
  rejectsSamplingParameters: true,
5816
5883
  rejectsThinkingDisabledAboveHighEffort: false,
5817
5884
  rejectsThinkingDisabled: true,
5885
+ rejectsBudgetThinking: true,
5818
5886
  rejectsForcedToolUse: false,
5819
5887
  supportsBetweenToolsThinking: false,
5820
5888
  isKnownModel: true
@@ -5826,6 +5894,7 @@ function getModelCapabilities(modelId) {
5826
5894
  rejectsSamplingParameters: true,
5827
5895
  rejectsThinkingDisabledAboveHighEffort: false,
5828
5896
  rejectsThinkingDisabled: false,
5897
+ rejectsBudgetThinking: false,
5829
5898
  rejectsForcedToolUse: false,
5830
5899
  supportsBetweenToolsThinking: false,
5831
5900
  isKnownModel: true
@@ -5837,6 +5906,7 @@ function getModelCapabilities(modelId) {
5837
5906
  rejectsSamplingParameters: false,
5838
5907
  rejectsThinkingDisabledAboveHighEffort: false,
5839
5908
  rejectsThinkingDisabled: false,
5909
+ rejectsBudgetThinking: false,
5840
5910
  rejectsForcedToolUse: false,
5841
5911
  supportsBetweenToolsThinking: false,
5842
5912
  isKnownModel: true
@@ -5848,6 +5918,7 @@ function getModelCapabilities(modelId) {
5848
5918
  rejectsSamplingParameters: false,
5849
5919
  rejectsThinkingDisabledAboveHighEffort: false,
5850
5920
  rejectsThinkingDisabled: false,
5921
+ rejectsBudgetThinking: false,
5851
5922
  rejectsForcedToolUse: false,
5852
5923
  supportsBetweenToolsThinking: false,
5853
5924
  isKnownModel: true
@@ -5859,6 +5930,7 @@ function getModelCapabilities(modelId) {
5859
5930
  rejectsSamplingParameters: false,
5860
5931
  rejectsThinkingDisabledAboveHighEffort: false,
5861
5932
  rejectsThinkingDisabled: false,
5933
+ rejectsBudgetThinking: false,
5862
5934
  rejectsForcedToolUse: false,
5863
5935
  supportsBetweenToolsThinking: false,
5864
5936
  isKnownModel: true
@@ -5870,6 +5942,7 @@ function getModelCapabilities(modelId) {
5870
5942
  rejectsSamplingParameters: false,
5871
5943
  rejectsThinkingDisabledAboveHighEffort: false,
5872
5944
  rejectsThinkingDisabled: false,
5945
+ rejectsBudgetThinking: false,
5873
5946
  rejectsForcedToolUse: false,
5874
5947
  supportsBetweenToolsThinking: false,
5875
5948
  isKnownModel: true
@@ -5881,6 +5954,7 @@ function getModelCapabilities(modelId) {
5881
5954
  rejectsSamplingParameters: false,
5882
5955
  rejectsThinkingDisabledAboveHighEffort: false,
5883
5956
  rejectsThinkingDisabled: false,
5957
+ rejectsBudgetThinking: false,
5884
5958
  rejectsForcedToolUse: false,
5885
5959
  supportsBetweenToolsThinking: false,
5886
5960
  isKnownModel: true
@@ -5892,6 +5966,7 @@ function getModelCapabilities(modelId) {
5892
5966
  rejectsSamplingParameters: false,
5893
5967
  rejectsThinkingDisabledAboveHighEffort: false,
5894
5968
  rejectsThinkingDisabled: false,
5969
+ rejectsBudgetThinking: false,
5895
5970
  rejectsForcedToolUse: false,
5896
5971
  supportsBetweenToolsThinking: false,
5897
5972
  isKnownModel: true
@@ -5903,6 +5978,7 @@ function getModelCapabilities(modelId) {
5903
5978
  rejectsSamplingParameters: false,
5904
5979
  rejectsThinkingDisabledAboveHighEffort: false,
5905
5980
  rejectsThinkingDisabled: false,
5981
+ rejectsBudgetThinking: false,
5906
5982
  rejectsForcedToolUse: false,
5907
5983
  supportsBetweenToolsThinking: false,
5908
5984
  isKnownModel: false
@@ -5914,6 +5990,7 @@ function getModelCapabilities(modelId) {
5914
5990
  rejectsSamplingParameters: true,
5915
5991
  rejectsThinkingDisabledAboveHighEffort: true,
5916
5992
  rejectsThinkingDisabled: false,
5993
+ rejectsBudgetThinking: false,
5917
5994
  rejectsForcedToolUse: false,
5918
5995
  supportsBetweenToolsThinking: false,
5919
5996
  isKnownModel: false
@@ -5925,6 +6002,7 @@ function getModelCapabilities(modelId) {
5925
6002
  rejectsSamplingParameters: false,
5926
6003
  rejectsThinkingDisabledAboveHighEffort: false,
5927
6004
  rejectsThinkingDisabled: false,
6005
+ rejectsBudgetThinking: false,
5928
6006
  rejectsForcedToolUse: false,
5929
6007
  supportsBetweenToolsThinking: false,
5930
6008
  isKnownModel: false