@ai-sdk/amazon-bedrock 4.0.97 → 4.0.99

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.
@@ -133,12 +133,10 @@ const bedrock = createAmazonBedrock({
133
133
  ```
134
134
 
135
135
  <Note>
136
- The credentials settings fall back to environment variable defaults described
137
- below. These may be set by your serverless environment without your awareness,
138
- which can lead to merged/conflicting credential values and provider errors
139
- around failed authentication. If you're experiencing issues be sure you are
140
- explicitly specifying all settings (even if `undefined`) to avoid any
141
- defaults.
136
+ Omitted options use the environment variables below. When **both**
137
+ `accessKeyId` and `secretAccessKey` are strings, SigV4 uses a **`sessionToken`
138
+ only if you pass one** - not `AWS_SESSION_TOKEN` from the environment - so static
139
+ keys are not mixed with workload tokens (e.g. EKS IRSA).
142
140
  </Note>
143
141
 
144
142
  You can use the following optional settings to customize the Amazon Bedrock provider instance:
@@ -160,8 +158,10 @@ You can use the following optional settings to customize the Amazon Bedrock prov
160
158
 
161
159
  - **sessionToken** _string_
162
160
 
163
- Optional. The AWS session token that you want to use for the API calls.
164
- It uses the `AWS_SESSION_TOKEN` environment variable by default.
161
+ Optional. For temporary credentials. With **both** access keys set as strings,
162
+ pass the token here if needed; `AWS_SESSION_TOKEN` from the environment is not
163
+ used. If either key is taken from the environment, omitting `sessionToken`
164
+ allows `AWS_SESSION_TOKEN`.
165
165
 
166
166
  - **credentialProvider** _() =&gt; Promise&lt;&#123; accessKeyId: string; secretAccessKey: string; sessionToken?: string; &#125;&gt;_
167
167
 
@@ -1359,8 +1359,10 @@ You can use the following optional settings to customize the Bedrock Anthropic p
1359
1359
 
1360
1360
  - **sessionToken** _string_
1361
1361
 
1362
- Optional. The AWS session token that you want to use for the API calls.
1363
- It uses the `AWS_SESSION_TOKEN` environment variable by default.
1362
+ Optional. For temporary credentials. With **both** access keys set as strings,
1363
+ pass the token here if needed; `AWS_SESSION_TOKEN` from the environment is not
1364
+ used. If either key is taken from the environment, omitting `sessionToken`
1365
+ allows `AWS_SESSION_TOKEN`.
1364
1366
 
1365
1367
  - **apiKey** _string_
1366
1368
 
@@ -1621,8 +1623,4 @@ The `bedrockOptions` provider setting previously available has been removed. If
1621
1623
  you were using the `bedrockOptions` object, you should now use the `region`,
1622
1624
  `accessKeyId`, `secretAccessKey`, and `sessionToken` settings directly instead.
1623
1625
 
1624
- Note that you may need to set all of these explicitly, e.g. even if you're not
1625
- using `sessionToken`, set it to `undefined`. If you're running in a serverless
1626
- environment, there may be default environment variables set by your containing
1627
- environment that the Amazon Bedrock provider will then pick up and could
1628
- conflict with the ones you're intending to use.
1626
+ Static IAM user keys do not require `sessionToken`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.97",
3
+ "version": "4.0.99",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -38,16 +38,16 @@
38
38
  "@smithy/eventstream-codec": "^4.0.1",
39
39
  "@smithy/util-utf8": "^4.0.0",
40
40
  "aws4fetch": "^1.0.20",
41
- "@ai-sdk/anthropic": "3.0.72",
42
- "@ai-sdk/provider": "3.0.9",
43
- "@ai-sdk/provider-utils": "4.0.24"
41
+ "@ai-sdk/anthropic": "3.0.74",
42
+ "@ai-sdk/provider": "3.0.10",
43
+ "@ai-sdk/provider-utils": "4.0.26"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "20.17.24",
47
47
  "tsup": "^8.3.0",
48
48
  "typescript": "5.8.3",
49
49
  "zod": "3.25.76",
50
- "@ai-sdk/test-server": "1.0.4",
50
+ "@ai-sdk/test-server": "1.0.5",
51
51
  "@vercel/ai-tsconfig": "0.0.0"
52
52
  },
53
53
  "peerDependencies": {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  convertBase64ToUint8Array,
3
- FetchFunction,
4
3
  safeParseJSON,
4
+ type FetchFunction,
5
5
  } from '@ai-sdk/provider-utils';
6
6
  import { z } from 'zod/v4';
7
7
  import { createBedrockEventStreamDecoder } from '../bedrock-event-stream-decoder';
@@ -1,28 +1,28 @@
1
1
  import {
2
- LanguageModelV3,
3
2
  NoSuchModelError,
4
- ProviderV3,
3
+ type LanguageModelV3,
4
+ type ProviderV3,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
- FetchFunction,
8
7
  loadOptionalSetting,
9
8
  loadSetting,
10
- Resolvable,
11
9
  resolve,
12
10
  withoutTrailingSlash,
13
11
  withUserAgentSuffix,
12
+ type FetchFunction,
13
+ type Resolvable,
14
14
  } from '@ai-sdk/provider-utils';
15
15
  import {
16
16
  anthropicTools,
17
17
  AnthropicMessagesLanguageModel,
18
18
  } from '@ai-sdk/anthropic/internal';
19
19
  import {
20
- BedrockCredentials,
21
20
  createApiKeyFetchFunction,
22
21
  createSigV4FetchFunction,
22
+ type BedrockCredentials,
23
23
  } from '../bedrock-sigv4-fetch';
24
24
  import { createBedrockAnthropicFetch } from './bedrock-anthropic-fetch';
25
- import { BedrockAnthropicModelId } from './bedrock-anthropic-options';
25
+ import type { BedrockAnthropicModelId } from './bedrock-anthropic-options';
26
26
  import { VERSION } from '../version';
27
27
 
28
28
  // Bedrock requires newer tool versions than the default Anthropic SDK versions
@@ -1,4 +1,4 @@
1
- import { JSONObject } from '@ai-sdk/provider';
1
+ import type { JSONObject } from '@ai-sdk/provider';
2
2
 
3
3
  export interface BedrockConverseInput {
4
4
  system?: BedrockSystemMessages;
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  JSONObject,
3
3
  LanguageModelV3,
4
4
  LanguageModelV3CallOptions,
@@ -13,33 +13,37 @@ import {
13
13
  SharedV3Warning,
14
14
  } from '@ai-sdk/provider';
15
15
  import {
16
- FetchFunction,
17
- ParseResult,
18
- Resolvable,
19
16
  combineHeaders,
20
17
  createJsonErrorResponseHandler,
21
18
  createJsonResponseHandler,
22
19
  parseProviderOptions,
23
20
  postJsonToApi,
24
21
  resolve,
22
+ type FetchFunction,
23
+ type ParseResult,
24
+ type Resolvable,
25
25
  } from '@ai-sdk/provider-utils';
26
26
  import { z } from 'zod/v4';
27
27
  import {
28
28
  BEDROCK_STOP_REASONS,
29
- BedrockConverseInput,
30
- BedrockStopReason,
29
+ type BedrockConverseInput,
30
+ type BedrockStopReason,
31
31
  } from './bedrock-api-types';
32
32
  import {
33
- BedrockChatModelId,
34
33
  amazonBedrockLanguageModelOptions,
34
+ type BedrockChatModelId,
35
35
  } from './bedrock-chat-options';
36
36
  import { BedrockErrorSchema } from './bedrock-error';
37
37
  import { createBedrockEventStreamResponseHandler } from './bedrock-event-stream-response-handler';
38
38
  import { prepareTools } from './bedrock-prepare-tools';
39
- import { BedrockUsage, convertBedrockUsage } from './convert-bedrock-usage';
39
+ import {
40
+ convertBedrockUsage,
41
+ type BedrockUsage,
42
+ } from './convert-bedrock-usage';
40
43
  import { convertToBedrockChatMessages } from './convert-to-bedrock-chat-messages';
41
44
  import { mapBedrockFinishReason } from './map-bedrock-finish-reason';
42
45
  import { isMistralModel, normalizeToolCallId } from './normalize-tool-call-id';
46
+ import type { BedrockReasoningMetadata } from './bedrock-reasoning-metadata';
43
47
 
44
48
  type BedrockChatConfig = {
45
49
  baseUrl: () => string;
@@ -1139,11 +1143,7 @@ const BedrockStreamSchema = z.object({
1139
1143
  validationException: z.record(z.string(), z.unknown()).nullish(),
1140
1144
  });
1141
1145
 
1142
- export const bedrockReasoningMetadataSchema = z.object({
1143
- signature: z.string().optional(),
1144
- redactedData: z.string().optional(),
1145
- });
1146
-
1147
- export type BedrockReasoningMetadata = z.infer<
1148
- typeof bedrockReasoningMetadataSchema
1149
- >;
1146
+ export {
1147
+ bedrockReasoningMetadataSchema,
1148
+ type BedrockReasoningMetadata,
1149
+ } from './bedrock-reasoning-metadata';
@@ -1,20 +1,20 @@
1
1
  import {
2
- EmbeddingModelV3,
3
2
  TooManyEmbeddingValuesForCallError,
3
+ type EmbeddingModelV3,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
- FetchFunction,
7
- Resolvable,
8
6
  combineHeaders,
9
7
  createJsonErrorResponseHandler,
10
8
  createJsonResponseHandler,
11
9
  parseProviderOptions,
12
10
  postJsonToApi,
13
11
  resolve,
12
+ type FetchFunction,
13
+ type Resolvable,
14
14
  } from '@ai-sdk/provider-utils';
15
15
  import {
16
- BedrockEmbeddingModelId,
17
16
  amazonBedrockEmbeddingModelOptionsSchema,
17
+ type BedrockEmbeddingModelId,
18
18
  } from './bedrock-embedding-options';
19
19
  import { BedrockErrorSchema } from './bedrock-error';
20
20
  import { z } from 'zod/v4';
@@ -1,12 +1,12 @@
1
1
  import { EmptyResponseBodyError } from '@ai-sdk/provider';
2
2
  import {
3
- ParseResult,
4
3
  safeParseJSON,
5
4
  extractResponseHeaders,
6
- ResponseHandler,
7
5
  safeValidateTypes,
6
+ type ParseResult,
7
+ type ResponseHandler,
8
8
  } from '@ai-sdk/provider-utils';
9
- import { ZodType } from 'zod/v4';
9
+ import type { ZodType } from 'zod/v4';
10
10
  import { createBedrockEventStreamDecoder } from './bedrock-event-stream-decoder';
11
11
 
12
12
  export const createBedrockEventStreamResponseHandler =
@@ -1,21 +1,21 @@
1
- import {
1
+ import type {
2
2
  ImageModelV3,
3
3
  ImageModelV3File,
4
4
  SharedV3Warning,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
- FetchFunction,
8
- Resolvable,
9
7
  combineHeaders,
10
8
  convertUint8ArrayToBase64,
11
9
  createJsonErrorResponseHandler,
12
10
  createJsonResponseHandler,
13
11
  postJsonToApi,
14
12
  resolve,
13
+ type FetchFunction,
14
+ type Resolvable,
15
15
  } from '@ai-sdk/provider-utils';
16
16
  import {
17
- BedrockImageModelId,
18
17
  modelMaxImagesPerCall,
18
+ type BedrockImageModelId,
19
19
  } from './bedrock-image-settings';
20
20
  import { BedrockErrorSchema } from './bedrock-error';
21
21
  import { z } from 'zod/v4';
@@ -1,15 +1,18 @@
1
1
  import {
2
- JSONObject,
3
- LanguageModelV3CallOptions,
4
- SharedV3Warning,
5
2
  UnsupportedFunctionalityError,
3
+ type JSONObject,
4
+ type LanguageModelV3CallOptions,
5
+ type SharedV3Warning,
6
6
  } from '@ai-sdk/provider';
7
7
  import { asSchema } from '@ai-sdk/provider-utils';
8
8
  import {
9
9
  anthropicTools,
10
10
  prepareTools as prepareAnthropicTools,
11
11
  } from '@ai-sdk/anthropic/internal';
12
- import { BedrockTool, BedrockToolConfiguration } from './bedrock-api-types';
12
+ import type {
13
+ BedrockTool,
14
+ BedrockToolConfiguration,
15
+ } from './bedrock-api-types';
13
16
 
14
17
  export async function prepareTools({
15
18
  tools,
@@ -1,5 +1,5 @@
1
1
  import { anthropicTools } from '@ai-sdk/anthropic/internal';
2
- import {
2
+ import type {
3
3
  EmbeddingModelV3,
4
4
  ImageModelV3,
5
5
  LanguageModelV3,
@@ -7,26 +7,26 @@ import {
7
7
  RerankingModelV3,
8
8
  } from '@ai-sdk/provider';
9
9
  import {
10
- FetchFunction,
11
10
  generateId,
12
11
  loadOptionalSetting,
13
12
  loadSetting,
14
13
  withoutTrailingSlash,
15
14
  withUserAgentSuffix,
15
+ type FetchFunction,
16
16
  } from '@ai-sdk/provider-utils';
17
17
  import { BedrockChatLanguageModel } from './bedrock-chat-language-model';
18
- import { BedrockChatModelId } from './bedrock-chat-options';
18
+ import type { BedrockChatModelId } from './bedrock-chat-options';
19
19
  import { BedrockEmbeddingModel } from './bedrock-embedding-model';
20
- import { BedrockEmbeddingModelId } from './bedrock-embedding-options';
20
+ import type { BedrockEmbeddingModelId } from './bedrock-embedding-options';
21
21
  import { BedrockImageModel } from './bedrock-image-model';
22
- import { BedrockImageModelId } from './bedrock-image-settings';
22
+ import type { BedrockImageModelId } from './bedrock-image-settings';
23
23
  import {
24
- BedrockCredentials,
25
24
  createApiKeyFetchFunction,
26
25
  createSigV4FetchFunction,
26
+ type BedrockCredentials,
27
27
  } from './bedrock-sigv4-fetch';
28
28
  import { BedrockRerankingModel } from './reranking/bedrock-reranking-model';
29
- import { BedrockRerankingModelId } from './reranking/bedrock-reranking-options';
29
+ import type { BedrockRerankingModelId } from './reranking/bedrock-reranking-options';
30
30
  import { VERSION } from './version';
31
31
 
32
32
  export interface AmazonBedrockProviderSettings {
@@ -74,8 +74,10 @@ export interface AmazonBedrockProviderSettings {
74
74
  secretAccessKey?: string;
75
75
 
76
76
  /**
77
- * The AWS session token to use for the Bedrock provider. Defaults to the value of the
78
- * `AWS_SESSION_TOKEN` environment variable.
77
+ * The AWS session token to use for the Bedrock provider. When `accessKeyId` and
78
+ * `secretAccessKey` are both passed explicitly as options, only this field is used
79
+ * If either access key field is omitted and resolved from the environment, the
80
+ * session token also falls back to `AWS_SESSION_TOKEN` when not set here.
79
81
  */
80
82
  sessionToken?: string;
81
83
 
@@ -221,10 +223,13 @@ export function createAmazonBedrock(
221
223
  environmentVariableName: 'AWS_SECRET_ACCESS_KEY',
222
224
  description: 'AWS secret access key',
223
225
  }),
224
- sessionToken: loadOptionalSetting({
225
- settingValue: options.sessionToken,
226
- environmentVariableName: 'AWS_SESSION_TOKEN',
227
- }),
226
+ sessionToken:
227
+ options.accessKeyId != null && options.secretAccessKey != null
228
+ ? options.sessionToken
229
+ : loadOptionalSetting({
230
+ settingValue: options.sessionToken,
231
+ environmentVariableName: 'AWS_SESSION_TOKEN',
232
+ }),
228
233
  };
229
234
  } catch (error) {
230
235
  // Provide helpful error message for missing AWS credentials
@@ -0,0 +1,10 @@
1
+ import { z } from 'zod/v4';
2
+
3
+ export const bedrockReasoningMetadataSchema = z.object({
4
+ signature: z.string().optional(),
5
+ redactedData: z.string().optional(),
6
+ });
7
+
8
+ export type BedrockReasoningMetadata = z.infer<
9
+ typeof bedrockReasoningMetadataSchema
10
+ >;
@@ -1,9 +1,9 @@
1
1
  import {
2
- FetchFunction,
3
2
  combineHeaders,
4
3
  normalizeHeaders,
5
4
  withUserAgentSuffix,
6
5
  getRuntimeEnvironmentUserAgent,
6
+ type FetchFunction,
7
7
  } from '@ai-sdk/provider-utils';
8
8
  import { AwsV4Signer } from 'aws4fetch';
9
9
  import { VERSION } from './version';
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3Usage } from '@ai-sdk/provider';
1
+ import type { LanguageModelV3Usage } from '@ai-sdk/provider';
2
2
 
3
3
  export type BedrockUsage = {
4
4
  inputTokens: number;
@@ -1,9 +1,9 @@
1
1
  import {
2
- JSONObject,
3
- LanguageModelV3Message,
4
- LanguageModelV3Prompt,
5
- SharedV3ProviderMetadata,
6
2
  UnsupportedFunctionalityError,
3
+ type JSONObject,
4
+ type LanguageModelV3Message,
5
+ type LanguageModelV3Prompt,
6
+ type SharedV3ProviderMetadata,
7
7
  } from '@ai-sdk/provider';
8
8
  import {
9
9
  convertToBase64,
@@ -13,17 +13,17 @@ import {
13
13
  import {
14
14
  BEDROCK_DOCUMENT_MIME_TYPES,
15
15
  BEDROCK_IMAGE_MIME_TYPES,
16
- BedrockAssistantMessage,
17
- BedrockCachePoint,
18
- BedrockDocumentFormat,
19
- BedrockDocumentMimeType,
20
- BedrockImageFormat,
21
- BedrockImageMimeType,
22
- BedrockMessages,
23
- BedrockSystemMessages,
24
- BedrockUserMessage,
16
+ type BedrockAssistantMessage,
17
+ type BedrockCachePoint,
18
+ type BedrockDocumentFormat,
19
+ type BedrockDocumentMimeType,
20
+ type BedrockImageFormat,
21
+ type BedrockImageMimeType,
22
+ type BedrockMessages,
23
+ type BedrockSystemMessages,
24
+ type BedrockUserMessage,
25
25
  } from './bedrock-api-types';
26
- import { bedrockReasoningMetadataSchema } from './bedrock-chat-language-model';
26
+ import { bedrockReasoningMetadataSchema } from './bedrock-reasoning-metadata';
27
27
  import { bedrockFilePartProviderOptions } from './bedrock-chat-options';
28
28
  import { normalizeToolCallId } from './normalize-tool-call-id';
29
29
 
@@ -309,9 +309,20 @@ export async function convertToBedrockChatMessages(
309
309
  },
310
310
  },
311
311
  });
312
- } else {
313
- // trim the last text part if it's the last message in the block
314
- // because Bedrock does not allow trailing whitespace
312
+ } else if (
313
+ part.providerOptions == null ||
314
+ Object.keys(part.providerOptions).every(
315
+ k => k === 'bedrock' || k === 'amazonBedrock',
316
+ )
317
+ ) {
318
+ // No foreign-provider metadata — preserve text. This covers
319
+ // the prefill case where the caller hand-crafts a reasoning
320
+ // block without a signature. Forwarding reasoning that was
321
+ // signed by a different provider (e.g. anthropic) would
322
+ // cause Bedrock to reject with
323
+ // `thinking.signature: Field required`, so we drop those.
324
+ // trim the last text part if it's the last message in the
325
+ // block because Bedrock does not allow trailing whitespace
315
326
  // in pre-filled assistant responses
316
327
  bedrockContent.push({
317
328
  reasoningContent: {
@@ -1,5 +1,5 @@
1
- import { LanguageModelV3FinishReason } from '@ai-sdk/provider';
2
- import { BedrockStopReason } from './bedrock-api-types';
1
+ import type { LanguageModelV3FinishReason } from '@ai-sdk/provider';
2
+ import type { BedrockStopReason } from './bedrock-api-types';
3
3
 
4
4
  export function mapBedrockFinishReason(
5
5
  finishReason: BedrockStopReason,
@@ -1,22 +1,22 @@
1
- import { RerankingModelV3 } from '@ai-sdk/provider';
1
+ import type { RerankingModelV3 } from '@ai-sdk/provider';
2
2
  import {
3
- FetchFunction,
4
- Resolvable,
5
3
  combineHeaders,
6
4
  createJsonErrorResponseHandler,
7
5
  createJsonResponseHandler,
8
6
  parseProviderOptions,
9
7
  postJsonToApi,
10
8
  resolve,
9
+ type FetchFunction,
10
+ type Resolvable,
11
11
  } from '@ai-sdk/provider-utils';
12
12
  import { BedrockErrorSchema } from '../bedrock-error';
13
13
  import {
14
- BedrockRerankingInput,
15
14
  bedrockRerankingResponseSchema,
15
+ type BedrockRerankingInput,
16
16
  } from './bedrock-reranking-api';
17
17
  import {
18
- BedrockRerankingModelId,
19
18
  amazonBedrockRerankingModelOptionsSchema,
19
+ type BedrockRerankingModelId,
20
20
  } from './bedrock-reranking-options';
21
21
 
22
22
  type BedrockRerankingConfig = {