@ai-sdk/anthropic 4.0.102 → 4.0.104

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.
@@ -1044,6 +1044,16 @@ the changed content, and the next step fails. Editing or removing earlier
1044
1044
  messages between turns, or changing the system prompt or tools between turns,
1045
1045
  has the same effect.
1046
1046
 
1047
+ UI message streams can change this content as well. When tool errors are
1048
+ redacted (`redactToolErrors`, which defaults to `true` when you pass `onError`),
1049
+ `toUIMessageStream` sends the replacement text to the client for a failed tool
1050
+ call, while the model received the full error text during the multi-step call.
1051
+ When you convert those UI messages back with `convertToModelMessages`, the tool
1052
+ result differs from the one the model received, and the thinking blocks after it
1053
+ become invalid. By default, the client receives the same text as the model. See
1054
+ [Tool error text and message history](/docs/ai-sdk-ui/chatbot-tool-usage#tool-error-text-and-message-history)
1055
+ for the available options.
1056
+
1047
1057
  If your application changes this content, set
1048
1058
  `blockBinding.prefixMismatchBehavior` to `drop_block` (see below). The API then
1049
1059
  drops the invalid thinking blocks instead of rejecting the request. The model
@@ -2843,3 +2853,38 @@ Decision models can also be accessed through `customProvider` aliases or
2843
2853
  use Gateway by default, or an explicitly configured default provider with an
2844
2854
  `decisionModel` method. See
2845
2855
  [model aliases and registries](/docs/ai-sdk-core/decisions#model-aliases-and-registries).
2856
+
2857
+ ## Extraction Models
2858
+
2859
+ Create an experimental extraction model with `anthropic.extractionModel(modelId)`.
2860
+ It wraps an Anthropic language model and uses the Messages API's structured
2861
+ output to extract typed fields in one call.
2862
+
2863
+ ```ts
2864
+ import { anthropic } from '@ai-sdk/anthropic';
2865
+ import { experimental_extract } from 'ai';
2866
+
2867
+ const { answers } = await experimental_extract({
2868
+ model: anthropic.extractionModel('claude-sonnet-5-5'),
2869
+ referenceDate: '2026-11-11',
2870
+ state: 'Invoice INV-2041. Total due $1,250.00 by March 3.',
2871
+ fields: {
2872
+ invoiceNumber: { type: 'text', instructions: 'The invoice number' },
2873
+ total: { type: 'number', instructions: 'Total due', decimals: 2 },
2874
+ dueDate: { type: 'date', instructions: 'Payment due date' },
2875
+ },
2876
+ });
2877
+ ```
2878
+
2879
+ The adapter supports every field type and returns `null` when the state has no
2880
+ value for a field. It does not return `pNull`, `confidence`, `guess`, or
2881
+ `source`, since a prompted model cannot give calibrated estimates or exact
2882
+ offsets. Image and PDF files are passed to the language model, which must
2883
+ support them. The adapter requests `reasoning: 'none'` by default and forwards
2884
+ `providerOptions.anthropic`. See [Extractions](/docs/ai-sdk-core/extractions).
2885
+
2886
+ Anthropic's structured output allows at most 16 nullable properties per schema,
2887
+ so field maps with more than 16 fields are sent as parallel calls of up to 16
2888
+ fields each, and the answers are merged into one result. Usage is summed across
2889
+ the calls, and response and provider metadata come from the first call. If any
2890
+ call fails, the extraction fails and the other calls are cancelled.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.102",
3
+ "version": "4.0.104",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,8 +35,8 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider": "4.0.37",
39
- "@ai-sdk/provider-utils": "5.0.79"
38
+ "@ai-sdk/provider": "4.0.38",
39
+ "@ai-sdk/provider-utils": "5.0.81"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.4",
@@ -3,6 +3,7 @@ import {
3
3
  NoSuchModelError,
4
4
  type Experimental_BatchV4 as BatchV4,
5
5
  type Experimental_DecisionModelV4 as DecisionModelV4,
6
+ type Experimental_ExtractionModelV4 as ExtractionModelV4,
6
7
  type FilesV4,
7
8
  type LanguageModelV4,
8
9
  type ProviderV4,
@@ -20,6 +21,7 @@ import {
20
21
  type Resolvable,
21
22
  } from '@ai-sdk/provider-utils';
22
23
  import { Experimental_DecisionLanguageModel as DecisionLanguageModel } from '@ai-sdk/provider-utils/experimental-decision';
24
+ import { Experimental_ExtractionLanguageModel as ExtractionLanguageModel } from '@ai-sdk/provider-utils/experimental-extraction';
23
25
  import { AnthropicFiles } from './files/anthropic-files';
24
26
  import { AnthropicLanguageModel } from './anthropic-language-model';
25
27
  import { AnthropicBatch } from './anthropic-batch';
@@ -63,6 +65,9 @@ export interface AnthropicProvider extends ProviderV4 {
63
65
  doEvaluate: DecisionModelV4['doDecide'];
64
66
  };
65
67
 
68
+ /** Creates an experimental typed field extraction model using Messages. */
69
+ extractionModel(modelId: AnthropicModelId): ExtractionModelV4;
70
+
66
71
  experimental_batch(): BatchV4<{ text: AnthropicModelId }>;
67
72
 
68
73
  /**
@@ -243,6 +248,12 @@ export function createAnthropic(
243
248
  });
244
249
  provider.evaluationModel =
245
250
  provider.decisionModel as AnthropicProvider['evaluationModel'];
251
+ provider.extractionModel = (modelId: AnthropicModelId) =>
252
+ new ExtractionLanguageModel({
253
+ model: createChatModel(modelId),
254
+ provider: `${providerName.replace(/\.messages$/, '')}.extraction`,
255
+ maxFieldsPerCall: 16,
256
+ });
246
257
  provider.experimental_batch = createBatch;
247
258
 
248
259
  provider.embeddingModel = (modelId: string) => {