@ai-sdk/anthropic 3.0.25 → 3.0.26
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 +6 -0
- package/dist/index.d.mts +20 -20
- package/dist/index.d.ts +20 -20
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +37 -9
- package/package.json +1 -1
- package/src/anthropic-provider.ts +20 -20
package/docs/05-anthropic.mdx
CHANGED
|
@@ -56,6 +56,13 @@ You can use the following optional settings to customize the Anthropic provider
|
|
|
56
56
|
|
|
57
57
|
API key that is being sent using the `x-api-key` header.
|
|
58
58
|
It defaults to the `ANTHROPIC_API_KEY` environment variable.
|
|
59
|
+
Only one of `apiKey` or `authToken` is required.
|
|
60
|
+
|
|
61
|
+
- **authToken** _string_
|
|
62
|
+
|
|
63
|
+
Auth token that is being sent using the `Authorization: Bearer` header.
|
|
64
|
+
It defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable.
|
|
65
|
+
Only one of `apiKey` or `authToken` is required.
|
|
59
66
|
|
|
60
67
|
- **headers** _Record<string,string>_
|
|
61
68
|
|
|
@@ -78,6 +85,12 @@ Some models have multi-modal capabilities.
|
|
|
78
85
|
const model = anthropic('claude-3-haiku-20240307');
|
|
79
86
|
```
|
|
80
87
|
|
|
88
|
+
You can also use the following aliases for model creation:
|
|
89
|
+
|
|
90
|
+
- `anthropic.languageModel('claude-3-haiku-20240307')` - Creates a language model
|
|
91
|
+
- `anthropic.chat('claude-3-haiku-20240307')` - Alias for `languageModel`
|
|
92
|
+
- `anthropic.messages('claude-3-haiku-20240307')` - Alias for `languageModel`
|
|
93
|
+
|
|
81
94
|
You can use Anthropic language models to generate text with the `generateText` function:
|
|
82
95
|
|
|
83
96
|
```ts
|
|
@@ -317,7 +330,7 @@ import { generateText } from 'ai';
|
|
|
317
330
|
const errorMessage = '... long error message ...';
|
|
318
331
|
|
|
319
332
|
const result = await generateText({
|
|
320
|
-
model: anthropic('claude-
|
|
333
|
+
model: anthropic('claude-sonnet-4-5'),
|
|
321
334
|
messages: [
|
|
322
335
|
{
|
|
323
336
|
role: 'user',
|
|
@@ -345,7 +358,7 @@ You can also use cache control on system messages by providing multiple system m
|
|
|
345
358
|
|
|
346
359
|
```ts highlight="3,7-9"
|
|
347
360
|
const result = await generateText({
|
|
348
|
-
model: anthropic('claude-
|
|
361
|
+
model: anthropic('claude-sonnet-4-5'),
|
|
349
362
|
messages: [
|
|
350
363
|
{
|
|
351
364
|
role: 'system',
|
|
@@ -444,7 +457,7 @@ For more on prompt caching with Anthropic, see [Anthropic's Cache Control docume
|
|
|
444
457
|
The Bash Tool allows running bash commands. Here's how to create and use it:
|
|
445
458
|
|
|
446
459
|
```ts
|
|
447
|
-
const bashTool = anthropic.tools.
|
|
460
|
+
const bashTool = anthropic.tools.bash_20250124({
|
|
448
461
|
execute: async ({ command, restart }) => {
|
|
449
462
|
// Implement your bash command execution logic here
|
|
450
463
|
// Return the result of the command execution
|
|
@@ -457,7 +470,10 @@ Parameters:
|
|
|
457
470
|
- `command` (string): The bash command to run. Required unless the tool is being restarted.
|
|
458
471
|
- `restart` (boolean, optional): Specifying true will restart this tool.
|
|
459
472
|
|
|
460
|
-
<Note>
|
|
473
|
+
<Note>
|
|
474
|
+
Two versions are available: `bash_20250124` (recommended) and `bash_20241022`.
|
|
475
|
+
Only certain Claude versions are supported.
|
|
476
|
+
</Note>
|
|
461
477
|
|
|
462
478
|
### Memory Tool
|
|
463
479
|
|
|
@@ -491,8 +507,14 @@ const tools = {
|
|
|
491
507
|
```
|
|
492
508
|
|
|
493
509
|
<Note>
|
|
494
|
-
Different models support different versions of the tool
|
|
495
|
-
|
|
510
|
+
Different models support different versions of the tool:
|
|
511
|
+
|
|
512
|
+
- `textEditor_20250728` - For Claude Sonnet 4, Opus 4, and Opus 4.1 (recommended)
|
|
513
|
+
- `textEditor_20250124` - For Claude Sonnet 3.7
|
|
514
|
+
- `textEditor_20241022` - For Claude Sonnet 3.5
|
|
515
|
+
|
|
516
|
+
Note: `textEditor_20250429` is deprecated. Use `textEditor_20250728` instead.
|
|
517
|
+
|
|
496
518
|
</Note>
|
|
497
519
|
|
|
498
520
|
Parameters:
|
|
@@ -848,6 +870,12 @@ const result = await generateText({
|
|
|
848
870
|
});
|
|
849
871
|
```
|
|
850
872
|
|
|
873
|
+
<Note>
|
|
874
|
+
Two versions are available: `codeExecution_20250825` (recommended, supports
|
|
875
|
+
Python and Bash with enhanced file operations) and `codeExecution_20250522`
|
|
876
|
+
(supports Bash only).
|
|
877
|
+
</Note>
|
|
878
|
+
|
|
851
879
|
#### Error Handling
|
|
852
880
|
|
|
853
881
|
Code execution errors are handled differently depending on whether you're using streaming or non-streaming:
|
|
@@ -1034,14 +1062,14 @@ const result = await generateText({
|
|
|
1034
1062
|
|
|
1035
1063
|
### PDF support
|
|
1036
1064
|
|
|
1037
|
-
Anthropic
|
|
1065
|
+
Anthropic Claude models support reading PDF files.
|
|
1038
1066
|
You can pass PDF files as part of the message content using the `file` type:
|
|
1039
1067
|
|
|
1040
1068
|
Option 1: URL-based PDF document
|
|
1041
1069
|
|
|
1042
1070
|
```ts
|
|
1043
1071
|
const result = await generateText({
|
|
1044
|
-
model: anthropic('claude-
|
|
1072
|
+
model: anthropic('claude-sonnet-4-5'),
|
|
1045
1073
|
messages: [
|
|
1046
1074
|
{
|
|
1047
1075
|
role: 'user',
|
|
@@ -1067,7 +1095,7 @@ Option 2: Base64-encoded PDF document
|
|
|
1067
1095
|
|
|
1068
1096
|
```ts
|
|
1069
1097
|
const result = await generateText({
|
|
1070
|
-
model: anthropic('claude-
|
|
1098
|
+
model: anthropic('claude-sonnet-4-5'),
|
|
1071
1099
|
messages: [
|
|
1072
1100
|
{
|
|
1073
1101
|
role: 'user',
|
package/package.json
CHANGED
|
@@ -19,13 +19,13 @@ import { anthropicTools } from './anthropic-tools';
|
|
|
19
19
|
|
|
20
20
|
export interface AnthropicProvider extends ProviderV3 {
|
|
21
21
|
/**
|
|
22
|
-
Creates a model for text generation.
|
|
23
|
-
*/
|
|
22
|
+
* Creates a model for text generation.
|
|
23
|
+
*/
|
|
24
24
|
(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
Creates a model for text generation.
|
|
28
|
-
*/
|
|
27
|
+
* Creates a model for text generation.
|
|
28
|
+
*/
|
|
29
29
|
languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
30
30
|
|
|
31
31
|
chat(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
@@ -38,41 +38,41 @@ Creates a model for text generation.
|
|
|
38
38
|
textEmbeddingModel(modelId: string): never;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
Anthropic-specific computer use tool.
|
|
41
|
+
* Anthropic-specific computer use tool.
|
|
42
42
|
*/
|
|
43
43
|
tools: typeof anthropicTools;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export interface AnthropicProviderSettings {
|
|
47
47
|
/**
|
|
48
|
-
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
49
|
-
The default prefix is `https://api.anthropic.com/v1`.
|
|
48
|
+
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
49
|
+
* The default prefix is `https://api.anthropic.com/v1`.
|
|
50
50
|
*/
|
|
51
51
|
baseURL?: string;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
API key that is being send using the `x-api-key` header.
|
|
55
|
-
It defaults to the `ANTHROPIC_API_KEY` environment variable.
|
|
56
|
-
Only one of `apiKey` or `authToken` is required.
|
|
54
|
+
* API key that is being send using the `x-api-key` header.
|
|
55
|
+
* It defaults to the `ANTHROPIC_API_KEY` environment variable.
|
|
56
|
+
* Only one of `apiKey` or `authToken` is required.
|
|
57
57
|
*/
|
|
58
58
|
apiKey?: string;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
Auth token that is being sent using the `Authorization: Bearer` header.
|
|
62
|
-
It defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable.
|
|
63
|
-
Only one of `apiKey` or `authToken` is required.
|
|
61
|
+
* Auth token that is being sent using the `Authorization: Bearer` header.
|
|
62
|
+
* It defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable.
|
|
63
|
+
* Only one of `apiKey` or `authToken` is required.
|
|
64
64
|
*/
|
|
65
65
|
authToken?: string;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
Custom headers to include in the requests.
|
|
69
|
-
|
|
68
|
+
* Custom headers to include in the requests.
|
|
69
|
+
*/
|
|
70
70
|
headers?: Record<string, string>;
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
74
|
-
or to provide a custom fetch implementation for e.g. testing.
|
|
75
|
-
|
|
73
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
74
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
75
|
+
*/
|
|
76
76
|
fetch?: FetchFunction;
|
|
77
77
|
|
|
78
78
|
generateId?: () => string;
|
|
@@ -85,7 +85,7 @@ or to provide a custom fetch implementation for e.g. testing.
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
Create an Anthropic provider instance.
|
|
88
|
+
* Create an Anthropic provider instance.
|
|
89
89
|
*/
|
|
90
90
|
export function createAnthropic(
|
|
91
91
|
options: AnthropicProviderSettings = {},
|
|
@@ -172,6 +172,6 @@ export function createAnthropic(
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
-
Default Anthropic provider instance.
|
|
175
|
+
* Default Anthropic provider instance.
|
|
176
176
|
*/
|
|
177
177
|
export const anthropic = createAnthropic();
|