@ai-sdk/anthropic 4.0.48 → 4.0.50

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.
@@ -768,14 +768,7 @@ type AnthropicLanguageModelConfig = {
768
768
  transformRequestBody?: (args: Record<string, any>, betas: Set<string>) => Record<string, any>;
769
769
  supportedUrls?: () => LanguageModelV4['supportedUrls'];
770
770
  generateId?: () => string;
771
- /**
772
- * When false, the model will use JSON tool fallback for structured outputs.
773
- */
774
771
  supportsNativeStructuredOutput?: boolean;
775
- /**
776
- * When false, `strict` on tool definitions will be ignored and a warning emitted.
777
- * Defaults to true.
778
- */
779
772
  supportsStrictTools?: boolean;
780
773
  };
781
774
  declare class AnthropicLanguageModel implements LanguageModelV4 {
@@ -794,15 +787,14 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
794
787
  constructor(modelId: AnthropicModelId, config: AnthropicLanguageModelConfig);
795
788
  supportsUrl(url: URL): boolean;
796
789
  get provider(): string;
797
- /**
798
- * Extracts the dynamic provider name from the config.provider string.
799
- * e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
800
- */
801
- private get providerOptionsName();
802
790
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
803
- protected getArgs({ userSuppliedBetas, prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, stream, }: LanguageModelV4CallOptions & {
804
- stream: boolean;
805
- userSuppliedBetas: Set<string>;
791
+ static prepareRequest({ modelId, config, options: { userSuppliedBetas, prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, stream, }, }: {
792
+ modelId: AnthropicModelId;
793
+ config: AnthropicLanguageModelConfig;
794
+ options: LanguageModelV4CallOptions & {
795
+ stream: boolean;
796
+ userSuppliedBetas: Set<string>;
797
+ };
806
798
  }): Promise<{
807
799
  args: {
808
800
  tools: AnthropicTool[] | undefined;
@@ -915,6 +907,7 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
915
907
  providerOptionsName: string;
916
908
  usedCustomProviderKey: boolean;
917
909
  }>;
910
+ private getArgs;
918
911
  private getHeaders;
919
912
  private getBetasFromHeaders;
920
913
  private buildRequestUrl;
@@ -3746,6 +3746,10 @@ function getAnthropicCallerMetadata(caller) {
3746
3746
  const callerInfo = getAnthropicCallerInfo(caller);
3747
3747
  return callerInfo == null ? {} : { providerMetadata: { anthropic: { caller: callerInfo } } };
3748
3748
  }
3749
+ function getProviderOptionsName(provider) {
3750
+ const dotIndex = provider.indexOf(".");
3751
+ return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
3752
+ }
3749
3753
  var AnthropicLanguageModel = class _AnthropicLanguageModel {
3750
3754
  constructor(modelId, config) {
3751
3755
  this.specificationVersion = "v4";
@@ -3769,36 +3773,31 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3769
3773
  get provider() {
3770
3774
  return this.config.provider;
3771
3775
  }
3772
- /**
3773
- * Extracts the dynamic provider name from the config.provider string.
3774
- * e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
3775
- */
3776
- get providerOptionsName() {
3777
- const provider = this.config.provider;
3778
- const dotIndex = provider.indexOf(".");
3779
- return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
3780
- }
3781
3776
  get supportedUrls() {
3782
3777
  var _a, _b, _c;
3783
3778
  return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
3784
3779
  }
3785
- async getArgs({
3786
- userSuppliedBetas,
3787
- prompt,
3788
- maxOutputTokens,
3789
- temperature,
3790
- topP,
3791
- topK,
3792
- frequencyPenalty,
3793
- presencePenalty,
3794
- stopSequences,
3795
- responseFormat,
3796
- seed,
3797
- tools,
3798
- toolChoice,
3799
- reasoning,
3800
- providerOptions,
3801
- stream
3780
+ static async prepareRequest({
3781
+ modelId,
3782
+ config,
3783
+ options: {
3784
+ userSuppliedBetas,
3785
+ prompt,
3786
+ maxOutputTokens,
3787
+ temperature,
3788
+ topP,
3789
+ topK,
3790
+ frequencyPenalty,
3791
+ presencePenalty,
3792
+ stopSequences,
3793
+ responseFormat,
3794
+ seed,
3795
+ tools,
3796
+ toolChoice,
3797
+ reasoning,
3798
+ providerOptions,
3799
+ stream
3800
+ }
3802
3801
  }) {
3803
3802
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3804
3803
  const warnings = [];
@@ -3835,7 +3834,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3835
3834
  });
3836
3835
  }
3837
3836
  }
3838
- const providerOptionsName = this.providerOptionsName;
3837
+ const providerOptionsName = getProviderOptionsName(config.provider);
3839
3838
  const canonicalOptions = await parseProviderOptions2({
3840
3839
  provider: "anthropic",
3841
3840
  providerOptions,
@@ -3860,12 +3859,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3860
3859
  supportsXhighEffort,
3861
3860
  rejectsThinkingDisabledAboveHighEffort,
3862
3861
  isKnownModel
3863
- } = getModelCapabilities(this.modelId);
3862
+ } = getModelCapabilities(modelId);
3864
3863
  if (!isKnownModel && maxOutputTokens == null) {
3865
3864
  warnings.push({
3866
3865
  type: "compatibility",
3867
3866
  feature: "maxOutputTokens",
3868
- details: `The model "${this.modelId}" is unknown. The max output tokens have been limited to ${maxOutputTokensForModel}. Set maxOutputTokens explicitly to override this limit.`
3867
+ details: `The model "${modelId}" is unknown. The max output tokens have been limited to ${maxOutputTokensForModel}. Set maxOutputTokens explicitly to override this limit.`
3869
3868
  });
3870
3869
  }
3871
3870
  if (rejectsSamplingParameters) {
@@ -3873,7 +3872,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3873
3872
  warnings.push({
3874
3873
  type: "unsupported",
3875
3874
  feature: "temperature",
3876
- details: `temperature is not supported by ${this.modelId} and will be ignored`
3875
+ details: `temperature is not supported by ${modelId} and will be ignored`
3877
3876
  });
3878
3877
  temperature = void 0;
3879
3878
  }
@@ -3881,7 +3880,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3881
3880
  warnings.push({
3882
3881
  type: "unsupported",
3883
3882
  feature: "topK",
3884
- details: `topK is not supported by ${this.modelId} and will be ignored`
3883
+ details: `topK is not supported by ${modelId} and will be ignored`
3885
3884
  });
3886
3885
  topK = void 0;
3887
3886
  }
@@ -3889,14 +3888,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3889
3888
  warnings.push({
3890
3889
  type: "unsupported",
3891
3890
  feature: "topP",
3892
- details: `topP is not supported by ${this.modelId} and will be ignored`
3891
+ details: `topP is not supported by ${modelId} and will be ignored`
3893
3892
  });
3894
3893
  topP = void 0;
3895
3894
  }
3896
3895
  }
3897
- const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
3898
- const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
3899
- const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
3896
+ const isAnthropicModel = isKnownModel || modelId.includes("claude-");
3897
+ const supportsStructuredOutput = ((_a = config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
3898
+ const supportsStrictTools = ((_b = config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
3900
3899
  const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
3901
3900
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
3902
3901
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
@@ -3966,7 +3965,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3966
3965
  warnings.push({
3967
3966
  type: "unsupported",
3968
3967
  feature: "providerOptions.anthropic.effort",
3969
- details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
3968
+ details: `effort '${anthropicOptions.effort}' is not supported by ${modelId} when thinking is disabled. The effort has been lowered to 'high'.`
3970
3969
  });
3971
3970
  anthropicOptions.effort = "high";
3972
3971
  }
@@ -3979,7 +3978,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3979
3978
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3980
3979
  const baseArgs = {
3981
3980
  // model id:
3982
- model: this.modelId,
3981
+ model: modelId,
3983
3982
  // standardized settings:
3984
3983
  max_tokens: maxTokens,
3985
3984
  temperature,
@@ -4179,7 +4178,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4179
4178
  warnings.push({
4180
4179
  type: "unsupported",
4181
4180
  feature: "maxOutputTokens",
4182
- details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
4181
+ details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
4183
4182
  });
4184
4183
  }
4185
4184
  baseArgs.max_tokens = maxOutputTokensForModel;
@@ -4270,6 +4269,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4270
4269
  usedCustomProviderKey
4271
4270
  };
4272
4271
  }
4272
+ getArgs(options) {
4273
+ return _AnthropicLanguageModel.prepareRequest({
4274
+ modelId: this.modelId,
4275
+ config: this.config,
4276
+ options
4277
+ });
4278
+ }
4273
4279
  async getHeaders({
4274
4280
  betas,
4275
4281
  headers
@@ -5802,7 +5808,7 @@ function getModelCapabilities(modelId) {
5802
5808
  rejectsThinkingDisabledAboveHighEffort: false,
5803
5809
  isKnownModel: true
5804
5810
  };
5805
- } else if (modelId.includes("claude-sonnet-4-")) {
5811
+ } else if (/claude-sonnet-4(?:-|@)/.test(modelId)) {
5806
5812
  return {
5807
5813
  maxOutputTokens: 64e3,
5808
5814
  supportsStructuredOutput: false,
@@ -5812,7 +5818,7 @@ function getModelCapabilities(modelId) {
5812
5818
  rejectsThinkingDisabledAboveHighEffort: false,
5813
5819
  isKnownModel: true
5814
5820
  };
5815
- } else if (modelId.includes("claude-opus-4-")) {
5821
+ } else if (/claude-opus-4(?:-|@)/.test(modelId)) {
5816
5822
  return {
5817
5823
  maxOutputTokens: 32e3,
5818
5824
  supportsStructuredOutput: false,