@ai-sdk/amazon-bedrock 3.0.0-beta.1 → 3.0.0-beta.11
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 +71 -0
- package/README.md +75 -0
- package/dist/index.d.mts +28 -27
- package/dist/index.d.ts +28 -27
- package/dist/index.js +357 -185
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +282 -110
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,76 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a89add7: fix(amazon-bedrock): add structured output support for claude models
|
|
8
|
+
|
|
9
|
+
## 3.0.0-beta.10
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b652872: fix(provider/bedrock): include toolConfig when conversation contains tool content
|
|
14
|
+
- Updated dependencies [ac34802]
|
|
15
|
+
- @ai-sdk/provider-utils@3.0.0-beta.6
|
|
16
|
+
|
|
17
|
+
## 3.0.0-beta.9
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [57edfcb]
|
|
22
|
+
- Updated dependencies [383cbfa]
|
|
23
|
+
- @ai-sdk/provider-utils@3.0.0-beta.5
|
|
24
|
+
|
|
25
|
+
## 3.0.0-beta.8
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 205077b: fix: improve Zod compatibility
|
|
30
|
+
- Updated dependencies [205077b]
|
|
31
|
+
- @ai-sdk/provider-utils@3.0.0-beta.4
|
|
32
|
+
|
|
33
|
+
## 3.0.0-beta.7
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 314edb2: Add API key authentication support for Amazon Bedrock with Bearer token and automatic SigV4 fallback
|
|
38
|
+
|
|
39
|
+
## 3.0.0-beta.6
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Updated dependencies [05d2819]
|
|
44
|
+
- @ai-sdk/provider-utils@3.0.0-beta.3
|
|
45
|
+
|
|
46
|
+
## 3.0.0-beta.5
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- 89eaf5e: Add style parameter support for Amazon Bedrock Nova Canvas image generation
|
|
51
|
+
|
|
52
|
+
## 3.0.0-beta.4
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- a10bf62: Fixes "Extra inputs are not permitted" error when using reasoning with Bedrock
|
|
57
|
+
|
|
58
|
+
## 3.0.0-beta.3
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- 3593385: fix(bedrock): resolve mime-types of document and images
|
|
63
|
+
|
|
64
|
+
## 3.0.0-beta.2
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- d1a034f: feature: using Zod 4 for internal stuff
|
|
69
|
+
- Updated dependencies [0571b98]
|
|
70
|
+
- Updated dependencies [39a4fab]
|
|
71
|
+
- Updated dependencies [d1a034f]
|
|
72
|
+
- @ai-sdk/provider-utils@3.0.0-beta.2
|
|
73
|
+
|
|
3
74
|
## 3.0.0-beta.1
|
|
4
75
|
|
|
5
76
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -19,6 +19,81 @@ You can import the default provider instance `bedrock` from `@ai-sdk/amazon-bedr
|
|
|
19
19
|
import { bedrock } from '@ai-sdk/amazon-bedrock';
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## Authentication
|
|
23
|
+
|
|
24
|
+
The Amazon Bedrock provider supports two authentication methods with automatic fallback:
|
|
25
|
+
|
|
26
|
+
### API Key Authentication (Recommended)
|
|
27
|
+
|
|
28
|
+
API key authentication provides a simpler setup process compared to traditional AWS SigV4 authentication. You can authenticate using either environment variables or direct configuration.
|
|
29
|
+
|
|
30
|
+
#### Using Environment Variable
|
|
31
|
+
|
|
32
|
+
Set the `AWS_BEARER_TOKEN_BEDROCK` environment variable with your API key:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
export AWS_BEARER_TOKEN_BEDROCK=your-api-key-here
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { bedrock } from '@ai-sdk/amazon-bedrock';
|
|
40
|
+
import { generateText } from 'ai';
|
|
41
|
+
|
|
42
|
+
const { text } = await generateText({
|
|
43
|
+
model: bedrock('anthropic.claude-3-haiku-20240307-v1:0'),
|
|
44
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
45
|
+
// API key is automatically loaded from AWS_BEARER_TOKEN_BEDROCK
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### Using Direct Configuration
|
|
50
|
+
|
|
51
|
+
You can also pass the API key directly in the provider configuration:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { bedrock } from '@ai-sdk/amazon-bedrock';
|
|
55
|
+
import { generateText } from 'ai';
|
|
56
|
+
|
|
57
|
+
const bedrockWithApiKey = bedrock.withSettings({
|
|
58
|
+
apiKey: process.env.AWS_BEARER_TOKEN_BEDROCK, // or your API key directly
|
|
59
|
+
region: 'us-east-1', // Optional: specify region
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const { text } = await generateText({
|
|
63
|
+
model: bedrockWithApiKey('anthropic.claude-3-haiku-20240307-v1:0'),
|
|
64
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### SigV4 Authentication (Fallback)
|
|
69
|
+
|
|
70
|
+
If no API key is provided, the provider automatically falls back to AWS SigV4 authentication using standard AWS credentials:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { bedrock } from '@ai-sdk/amazon-bedrock';
|
|
74
|
+
import { generateText } from 'ai';
|
|
75
|
+
|
|
76
|
+
// Uses AWS credentials from environment variables or AWS credential chain
|
|
77
|
+
const { text } = await generateText({
|
|
78
|
+
model: bedrock('anthropic.claude-3-haiku-20240307-v1:0'),
|
|
79
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This method requires standard AWS environment variables:
|
|
84
|
+
|
|
85
|
+
- `AWS_ACCESS_KEY_ID`
|
|
86
|
+
- `AWS_SECRET_ACCESS_KEY`
|
|
87
|
+
- `AWS_SESSION_TOKEN` (optional, for temporary credentials)
|
|
88
|
+
|
|
89
|
+
### Authentication Precedence
|
|
90
|
+
|
|
91
|
+
The provider uses the following authentication precedence:
|
|
92
|
+
|
|
93
|
+
1. **API key from direct configuration** (`apiKey` in `withSettings()`)
|
|
94
|
+
2. **API key from environment variable** (`AWS_BEARER_TOKEN_BEDROCK`)
|
|
95
|
+
3. **SigV4 authentication** (AWS credential chain fallback)
|
|
96
|
+
|
|
22
97
|
## Example
|
|
23
98
|
|
|
24
99
|
```ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,38 +1,15 @@
|
|
|
1
1
|
import { ProviderV2, LanguageModelV2, EmbeddingModelV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { z } from 'zod';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
4
4
|
|
|
5
5
|
type BedrockChatModelId = 'amazon.titan-tg1-large' | 'amazon.titan-text-express-v1' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-instant-v1' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.command-r-v1:0' | 'cohere.command-r-plus-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-1-405b-instruct-v1:0' | 'meta.llama3-1-70b-instruct-v1:0' | 'meta.llama3-1-8b-instruct-v1:0' | 'meta.llama3-2-11b-instruct-v1:0' | 'meta.llama3-2-1b-instruct-v1:0' | 'meta.llama3-2-3b-instruct-v1:0' | 'meta.llama3-2-90b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'mistral.mistral-small-2402-v1:0' | 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | (string & {});
|
|
6
6
|
declare const bedrockProviderOptions: z.ZodObject<{
|
|
7
|
-
/**
|
|
8
|
-
* Additional inference parameters that the model supports,
|
|
9
|
-
* beyond the base set of inference parameters that Converse
|
|
10
|
-
* supports in the inferenceConfig field
|
|
11
|
-
*/
|
|
12
7
|
additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
13
8
|
reasoningConfig: z.ZodOptional<z.ZodObject<{
|
|
14
|
-
type: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>;
|
|
9
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>;
|
|
15
10
|
budgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
budgetTokens?: number | undefined;
|
|
19
|
-
}, {
|
|
20
|
-
type?: "enabled" | "disabled" | undefined;
|
|
21
|
-
budgetTokens?: number | undefined;
|
|
22
|
-
}>>;
|
|
23
|
-
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
25
|
-
reasoningConfig?: {
|
|
26
|
-
type?: "enabled" | "disabled" | undefined;
|
|
27
|
-
budgetTokens?: number | undefined;
|
|
28
|
-
} | undefined;
|
|
29
|
-
}, {
|
|
30
|
-
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
31
|
-
reasoningConfig?: {
|
|
32
|
-
type?: "enabled" | "disabled" | undefined;
|
|
33
|
-
budgetTokens?: number | undefined;
|
|
34
|
-
} | undefined;
|
|
35
|
-
}>;
|
|
11
|
+
}, z.core.$strip>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
36
13
|
type BedrockProviderOptions = z.infer<typeof bedrockProviderOptions>;
|
|
37
14
|
|
|
38
15
|
type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
|
|
@@ -53,6 +30,30 @@ interface AmazonBedrockProviderSettings {
|
|
|
53
30
|
*/
|
|
54
31
|
region?: string;
|
|
55
32
|
/**
|
|
33
|
+
API key for authenticating requests using Bearer token authentication.
|
|
34
|
+
When provided, this will be used instead of AWS SigV4 authentication.
|
|
35
|
+
Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
|
|
36
|
+
|
|
37
|
+
@example
|
|
38
|
+
```typescript
|
|
39
|
+
// Using API key directly
|
|
40
|
+
const bedrock = createAmazonBedrock({
|
|
41
|
+
apiKey: 'your-api-key-here',
|
|
42
|
+
region: 'us-east-1'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Using environment variable AWS_BEARER_TOKEN_BEDROCK
|
|
46
|
+
const bedrock = createAmazonBedrock({
|
|
47
|
+
region: 'us-east-1'
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication.
|
|
52
|
+
If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set,
|
|
53
|
+
the provider will fall back to AWS SigV4 authentication using AWS credentials.
|
|
54
|
+
*/
|
|
55
|
+
apiKey?: string;
|
|
56
|
+
/**
|
|
56
57
|
The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
57
58
|
`AWS_ACCESS_KEY_ID` environment variable.
|
|
58
59
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,15 @@
|
|
|
1
1
|
import { ProviderV2, LanguageModelV2, EmbeddingModelV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { z } from 'zod';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
4
4
|
|
|
5
5
|
type BedrockChatModelId = 'amazon.titan-tg1-large' | 'amazon.titan-text-express-v1' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-instant-v1' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.command-r-v1:0' | 'cohere.command-r-plus-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-1-405b-instruct-v1:0' | 'meta.llama3-1-70b-instruct-v1:0' | 'meta.llama3-1-8b-instruct-v1:0' | 'meta.llama3-2-11b-instruct-v1:0' | 'meta.llama3-2-1b-instruct-v1:0' | 'meta.llama3-2-3b-instruct-v1:0' | 'meta.llama3-2-90b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'mistral.mistral-small-2402-v1:0' | 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | (string & {});
|
|
6
6
|
declare const bedrockProviderOptions: z.ZodObject<{
|
|
7
|
-
/**
|
|
8
|
-
* Additional inference parameters that the model supports,
|
|
9
|
-
* beyond the base set of inference parameters that Converse
|
|
10
|
-
* supports in the inferenceConfig field
|
|
11
|
-
*/
|
|
12
7
|
additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
13
8
|
reasoningConfig: z.ZodOptional<z.ZodObject<{
|
|
14
|
-
type: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>;
|
|
9
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>;
|
|
15
10
|
budgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
budgetTokens?: number | undefined;
|
|
19
|
-
}, {
|
|
20
|
-
type?: "enabled" | "disabled" | undefined;
|
|
21
|
-
budgetTokens?: number | undefined;
|
|
22
|
-
}>>;
|
|
23
|
-
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
25
|
-
reasoningConfig?: {
|
|
26
|
-
type?: "enabled" | "disabled" | undefined;
|
|
27
|
-
budgetTokens?: number | undefined;
|
|
28
|
-
} | undefined;
|
|
29
|
-
}, {
|
|
30
|
-
additionalModelRequestFields?: Record<string, any> | undefined;
|
|
31
|
-
reasoningConfig?: {
|
|
32
|
-
type?: "enabled" | "disabled" | undefined;
|
|
33
|
-
budgetTokens?: number | undefined;
|
|
34
|
-
} | undefined;
|
|
35
|
-
}>;
|
|
11
|
+
}, z.core.$strip>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
36
13
|
type BedrockProviderOptions = z.infer<typeof bedrockProviderOptions>;
|
|
37
14
|
|
|
38
15
|
type BedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {});
|
|
@@ -53,6 +30,30 @@ interface AmazonBedrockProviderSettings {
|
|
|
53
30
|
*/
|
|
54
31
|
region?: string;
|
|
55
32
|
/**
|
|
33
|
+
API key for authenticating requests using Bearer token authentication.
|
|
34
|
+
When provided, this will be used instead of AWS SigV4 authentication.
|
|
35
|
+
Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
|
|
36
|
+
|
|
37
|
+
@example
|
|
38
|
+
```typescript
|
|
39
|
+
// Using API key directly
|
|
40
|
+
const bedrock = createAmazonBedrock({
|
|
41
|
+
apiKey: 'your-api-key-here',
|
|
42
|
+
region: 'us-east-1'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Using environment variable AWS_BEARER_TOKEN_BEDROCK
|
|
46
|
+
const bedrock = createAmazonBedrock({
|
|
47
|
+
region: 'us-east-1'
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication.
|
|
52
|
+
If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set,
|
|
53
|
+
the provider will fall back to AWS SigV4 authentication using AWS credentials.
|
|
54
|
+
*/
|
|
55
|
+
apiKey?: string;
|
|
56
|
+
/**
|
|
56
57
|
The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
57
58
|
`AWS_ACCESS_KEY_ID` environment variable.
|
|
58
59
|
*/
|