@ai-sdk/anthropic 4.0.103 → 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.
- package/CHANGELOG.md +8 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/docs/05-anthropic.mdx +35 -0
- package/package.json +2 -2
- package/src/anthropic-provider.ts +11 -0
package/docs/05-anthropic.mdx
CHANGED
|
@@ -2853,3 +2853,38 @@ Decision models can also be accessed through `customProvider` aliases or
|
|
|
2853
2853
|
use Gateway by default, or an explicitly configured default provider with an
|
|
2854
2854
|
`decisionModel` method. See
|
|
2855
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.
|
|
3
|
+
"version": "4.0.104",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ai-sdk/provider": "4.0.38",
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
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) => {
|