@ai-sdk/anthropic 3.0.0-beta.86 → 3.0.0-beta.88

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.
@@ -13,6 +13,10 @@ type AnthropicMessagesConfig = {
13
13
  transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
14
14
  supportedUrls?: () => LanguageModelV3['supportedUrls'];
15
15
  generateId?: () => string;
16
+ /**
17
+ * When false, the model will use JSON tool fallback for structured outputs.
18
+ */
19
+ supportsNativeStructuredOutput?: boolean;
16
20
  };
17
21
  declare class AnthropicMessagesLanguageModel implements LanguageModelV3 {
18
22
  readonly specificationVersion = "v3";
@@ -13,6 +13,10 @@ type AnthropicMessagesConfig = {
13
13
  transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
14
14
  supportedUrls?: () => LanguageModelV3['supportedUrls'];
15
15
  generateId?: () => string;
16
+ /**
17
+ * When false, the model will use JSON tool fallback for structured outputs.
18
+ */
19
+ supportsNativeStructuredOutput?: boolean;
16
20
  };
17
21
  declare class AnthropicMessagesLanguageModel implements LanguageModelV3 {
18
22
  readonly specificationVersion = "v3";
@@ -1031,6 +1031,9 @@ async function prepareTools({
1031
1031
  )
1032
1032
  } : {}
1033
1033
  });
1034
+ if (supportsStructuredOutput === true) {
1035
+ betas.add("structured-outputs-2025-11-13");
1036
+ }
1034
1037
  if (tool.inputExamples != null) {
1035
1038
  betas.add("advanced-tool-use-2025-11-20");
1036
1039
  }
@@ -2181,7 +2184,7 @@ var AnthropicMessagesLanguageModel = class {
2181
2184
  providerOptions,
2182
2185
  stream
2183
2186
  }) {
2184
- var _a, _b, _c, _d, _e, _f;
2187
+ var _a, _b, _c, _d, _e, _f, _g;
2185
2188
  const warnings = [];
2186
2189
  if (frequencyPenalty != null) {
2187
2190
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2223,10 +2226,11 @@ var AnthropicMessagesLanguageModel = class {
2223
2226
  });
2224
2227
  const {
2225
2228
  maxOutputTokens: maxOutputTokensForModel,
2226
- supportsStructuredOutput,
2229
+ supportsStructuredOutput: modelSupportsStructuredOutput,
2227
2230
  isKnownModel
2228
2231
  } = getModelCapabilities(this.modelId);
2229
- const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "auto";
2232
+ const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2233
+ const structureOutputMode = (_b = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _b : "auto";
2230
2234
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2231
2235
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
2232
2236
  type: "function",
@@ -2258,13 +2262,13 @@ var AnthropicMessagesLanguageModel = class {
2258
2262
  });
2259
2263
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
2260
2264
  prompt,
2261
- sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
2265
+ sendReasoning: (_c = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _c : true,
2262
2266
  warnings,
2263
2267
  cacheControlValidator,
2264
2268
  toolNameMapping
2265
2269
  });
2266
- const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
2267
- let thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
2270
+ const isThinking = ((_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type) === "enabled";
2271
+ let thinkingBudget = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens;
2268
2272
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2269
2273
  const baseArgs = {
2270
2274
  // model id:
@@ -2306,7 +2310,7 @@ var AnthropicMessagesLanguageModel = class {
2306
2310
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2307
2311
  container: {
2308
2312
  id: anthropicOptions.container.id,
2309
- skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
2313
+ skills: (_f = anthropicOptions.container.skills) == null ? void 0 : _f.map((skill) => ({
2310
2314
  type: skill.type,
2311
2315
  skill_id: skill.skillId,
2312
2316
  version: skill.version
@@ -2425,10 +2429,11 @@ var AnthropicMessagesLanguageModel = class {
2425
2429
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2426
2430
  betas.add("effort-2025-11-24");
2427
2431
  }
2428
- if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
2432
+ if (stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true)) {
2429
2433
  betas.add("fine-grained-tool-streaming-2025-05-14");
2430
2434
  }
2431
- if (useStructuredOutput) {
2435
+ const usingNativeOutputFormat = useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
2436
+ if (usingNativeOutputFormat) {
2432
2437
  betas.add("structured-outputs-2025-11-13");
2433
2438
  }
2434
2439
  const {