@ai-sdk/anthropic 4.0.103 → 4.0.105
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 +14 -0
- package/dist/index.d.ts +109 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +234 -131
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +9 -2
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +40 -0
- package/package.json +2 -2
- package/src/anthropic-language-model-options.ts +2 -27
- package/src/anthropic-model-catalog.ts +21 -6
- package/src/anthropic-provider.ts +11 -0
package/docs/05-anthropic.mdx
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Anthropic
|
|
3
3
|
description: Learn how to use Anthropic with AI Gateway and the direct provider.
|
|
4
|
+
keywords:
|
|
5
|
+
- claude
|
|
6
|
+
- claude sonnet
|
|
7
|
+
- claude opus
|
|
8
|
+
- claude haiku
|
|
4
9
|
---
|
|
5
10
|
|
|
6
11
|
# Anthropic Provider
|
|
@@ -2853,3 +2858,38 @@ Decision models can also be accessed through `customProvider` aliases or
|
|
|
2853
2858
|
use Gateway by default, or an explicitly configured default provider with an
|
|
2854
2859
|
`decisionModel` method. See
|
|
2855
2860
|
[model aliases and registries](/docs/ai-sdk-core/decisions#model-aliases-and-registries).
|
|
2861
|
+
|
|
2862
|
+
## Extraction Models
|
|
2863
|
+
|
|
2864
|
+
Create an experimental extraction model with `anthropic.extractionModel(modelId)`.
|
|
2865
|
+
It wraps an Anthropic language model and uses the Messages API's structured
|
|
2866
|
+
output to extract typed fields in one call.
|
|
2867
|
+
|
|
2868
|
+
```ts
|
|
2869
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
2870
|
+
import { experimental_extract } from 'ai';
|
|
2871
|
+
|
|
2872
|
+
const { answers } = await experimental_extract({
|
|
2873
|
+
model: anthropic.extractionModel('claude-sonnet-5-5'),
|
|
2874
|
+
referenceDate: '2026-11-11',
|
|
2875
|
+
state: 'Invoice INV-2041. Total due $1,250.00 by March 3.',
|
|
2876
|
+
fields: {
|
|
2877
|
+
invoiceNumber: { type: 'text', instructions: 'The invoice number' },
|
|
2878
|
+
total: { type: 'number', instructions: 'Total due', decimals: 2 },
|
|
2879
|
+
dueDate: { type: 'date', instructions: 'Payment due date' },
|
|
2880
|
+
},
|
|
2881
|
+
});
|
|
2882
|
+
```
|
|
2883
|
+
|
|
2884
|
+
The adapter supports every field type and returns `null` when the state has no
|
|
2885
|
+
value for a field. It does not return `pNull`, `confidence`, `guess`, or
|
|
2886
|
+
`source`, since a prompted model cannot give calibrated estimates or exact
|
|
2887
|
+
offsets. Image and PDF files are passed to the language model, which must
|
|
2888
|
+
support them. The adapter requests `reasoning: 'none'` by default and forwards
|
|
2889
|
+
`providerOptions.anthropic`. See [Extractions](/docs/ai-sdk-core/extractions).
|
|
2890
|
+
|
|
2891
|
+
Anthropic's structured output allows at most 16 nullable properties per schema,
|
|
2892
|
+
so field maps with more than 16 fields are sent as parallel calls of up to 16
|
|
2893
|
+
fields each, and the answers are merged into one result. Usage is summed across
|
|
2894
|
+
the calls, and response and provider metadata come from the first call. If any
|
|
2895
|
+
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.105",
|
|
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",
|
|
@@ -4,35 +4,10 @@ import {
|
|
|
4
4
|
type InferSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
6
6
|
import { z } from 'zod/v4';
|
|
7
|
+
import type { AnthropicModelIds } from './anthropic-model-catalog';
|
|
7
8
|
|
|
8
9
|
// https://docs.claude.com/en/docs/about-claude/models/overview
|
|
9
|
-
export type AnthropicModelId =
|
|
10
|
-
| 'claude-3-haiku-20240307'
|
|
11
|
-
| 'claude-haiku-4-5-20251001'
|
|
12
|
-
| 'claude-haiku-4-5'
|
|
13
|
-
| 'claude-haiku-5-5'
|
|
14
|
-
| 'claude-opus-4-0'
|
|
15
|
-
| 'claude-opus-4-20250514'
|
|
16
|
-
| 'claude-opus-4-1-20250805'
|
|
17
|
-
| 'claude-opus-4-1'
|
|
18
|
-
| 'claude-opus-4-5'
|
|
19
|
-
| 'claude-opus-4-5-20251101'
|
|
20
|
-
| 'claude-sonnet-4-0'
|
|
21
|
-
| 'claude-sonnet-4-20250514'
|
|
22
|
-
| 'claude-sonnet-4-5-20250929'
|
|
23
|
-
| 'claude-sonnet-4-5'
|
|
24
|
-
| 'claude-sonnet-4-6'
|
|
25
|
-
| 'claude-opus-4-6'
|
|
26
|
-
| 'claude-opus-4-7'
|
|
27
|
-
| 'claude-opus-4-8'
|
|
28
|
-
| 'claude-opus-5'
|
|
29
|
-
| 'claude-opus-5-5'
|
|
30
|
-
| 'claude-fable-5'
|
|
31
|
-
| 'claude-fable-5-1'
|
|
32
|
-
| 'claude-fable-5-2'
|
|
33
|
-
| 'claude-sonnet-5'
|
|
34
|
-
| 'claude-sonnet-5-5'
|
|
35
|
-
| (string & {});
|
|
10
|
+
export type AnthropicModelId = AnthropicModelIds['language'] | (string & {});
|
|
36
11
|
|
|
37
12
|
/**
|
|
38
13
|
* Anthropic file part provider options for document-specific features.
|
|
@@ -248,7 +248,7 @@ const runtimeRules: readonly {
|
|
|
248
248
|
},
|
|
249
249
|
];
|
|
250
250
|
|
|
251
|
-
const
|
|
251
|
+
const languageModelDefinitions = {
|
|
252
252
|
'claude-opus-5-5': { toolSearch: true, compaction: true, effort: true },
|
|
253
253
|
'claude-opus-5': { toolSearch: true, compaction: true, effort: true },
|
|
254
254
|
'claude-sonnet-5-5': { toolSearch: true, compaction: true, effort: true },
|
|
@@ -267,15 +267,25 @@ const documentedModels: Readonly<Record<string, DocumentedCapabilities>> = {
|
|
|
267
267
|
'claude-opus-4-1': { toolSearch: false, compaction: false, effort: false },
|
|
268
268
|
'claude-opus-4-0': { toolSearch: false, compaction: false, effort: false },
|
|
269
269
|
'claude-sonnet-4-0': { toolSearch: false, compaction: false, effort: false },
|
|
270
|
-
|
|
270
|
+
// Known IDs without declared capabilities retain the custom-model fallback.
|
|
271
|
+
'claude-3-haiku-20240307': undefined,
|
|
272
|
+
'claude-haiku-4-5-20251001': undefined,
|
|
273
|
+
'claude-opus-4-1-20250805': undefined,
|
|
274
|
+
'claude-opus-4-20250514': undefined,
|
|
275
|
+
'claude-opus-4-5-20251101': undefined,
|
|
276
|
+
'claude-sonnet-4-20250514': undefined,
|
|
277
|
+
'claude-sonnet-4-5-20250929': undefined,
|
|
278
|
+
} satisfies Readonly<Record<string, DocumentedCapabilities | undefined>>;
|
|
271
279
|
|
|
272
280
|
export const anthropicModelCatalog: Readonly<
|
|
273
281
|
Record<string, AnthropicLanguageModelEntry>
|
|
274
282
|
> = Object.fromEntries(
|
|
275
|
-
Object.entries(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
283
|
+
Object.entries(languageModelDefinitions)
|
|
284
|
+
.filter(([, definition]) => definition != null)
|
|
285
|
+
.map(([modelId, capabilities]) => [
|
|
286
|
+
modelId,
|
|
287
|
+
createAnthropicLanguageModelEntry(modelId, capabilities),
|
|
288
|
+
]),
|
|
279
289
|
);
|
|
280
290
|
|
|
281
291
|
export function getAnthropicLanguageModelEntry(
|
|
@@ -413,3 +423,8 @@ export function getAnthropicModelCapabilities(modelId: string) {
|
|
|
413
423
|
|
|
414
424
|
// Compatibility name also exported by the Anthropic runtime adapter.
|
|
415
425
|
export { getAnthropicModelCapabilities as getModelCapabilities };
|
|
426
|
+
|
|
427
|
+
/** Known model IDs, derived from the declarations used to build the catalog. */
|
|
428
|
+
export type AnthropicModelIds = {
|
|
429
|
+
language: keyof typeof languageModelDefinitions;
|
|
430
|
+
};
|
|
@@ -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) => {
|