@ai-sdk/amazon-bedrock 5.0.0-beta.8 → 5.0.0-beta.85

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +669 -4
  2. package/README.md +2 -0
  3. package/dist/anthropic/index.d.ts +10 -10
  4. package/dist/anthropic/index.js +151 -117
  5. package/dist/anthropic/index.js.map +1 -1
  6. package/dist/index.d.ts +36 -23
  7. package/dist/index.js +881 -604
  8. package/dist/index.js.map +1 -1
  9. package/dist/mantle/index.cjs +253 -0
  10. package/dist/mantle/index.cjs.map +1 -0
  11. package/dist/mantle/index.d.cts +99 -0
  12. package/dist/mantle/index.d.ts +99 -0
  13. package/dist/mantle/index.js +240 -0
  14. package/dist/mantle/index.js.map +1 -0
  15. package/docs/08-amazon-bedrock.mdx +310 -84
  16. package/mantle/index.d.ts +1 -0
  17. package/package.json +27 -20
  18. package/src/amazon-bedrock-api-types.ts +228 -0
  19. package/src/{bedrock-chat-options.ts → amazon-bedrock-chat-language-model-options.ts} +27 -8
  20. package/src/{bedrock-chat-language-model.ts → amazon-bedrock-chat-language-model.ts} +350 -180
  21. package/src/{bedrock-embedding-options.ts → amazon-bedrock-embedding-model-options.ts} +1 -1
  22. package/src/{bedrock-embedding-model.ts → amazon-bedrock-embedding-model.ts} +61 -29
  23. package/src/{bedrock-error.ts → amazon-bedrock-error.ts} +1 -1
  24. package/src/{bedrock-event-stream-decoder.ts → amazon-bedrock-event-stream-decoder.ts} +1 -1
  25. package/src/{bedrock-event-stream-response-handler.ts → amazon-bedrock-event-stream-response-handler.ts} +6 -6
  26. package/src/{bedrock-image-model.ts → amazon-bedrock-image-model.ts} +62 -38
  27. package/src/amazon-bedrock-image-settings.ts +9 -0
  28. package/src/{bedrock-prepare-tools.ts → amazon-bedrock-prepare-tools.ts} +22 -18
  29. package/src/{bedrock-provider.ts → amazon-bedrock-provider.ts} +53 -46
  30. package/src/amazon-bedrock-reasoning-metadata.ts +10 -0
  31. package/src/{bedrock-sigv4-fetch.ts → amazon-bedrock-sigv4-fetch.ts} +17 -9
  32. package/src/anthropic/amazon-bedrock-anthropic-fetch.ts +104 -0
  33. package/src/anthropic/{bedrock-anthropic-options.ts → amazon-bedrock-anthropic-options.ts} +7 -1
  34. package/src/anthropic/{bedrock-anthropic-provider.ts → amazon-bedrock-anthropic-provider.ts} +40 -24
  35. package/src/anthropic/index.ts +19 -7
  36. package/src/{convert-bedrock-usage.ts → convert-amazon-bedrock-usage.ts} +4 -4
  37. package/src/convert-to-amazon-bedrock-chat-messages.ts +556 -0
  38. package/src/index.ts +15 -8
  39. package/src/inject-fetch-headers.ts +1 -1
  40. package/src/mantle/bedrock-mantle-options.ts +15 -0
  41. package/src/mantle/bedrock-mantle-provider.ts +283 -0
  42. package/src/mantle/index.ts +6 -0
  43. package/src/{map-bedrock-finish-reason.ts → map-amazon-bedrock-finish-reason.ts} +4 -4
  44. package/src/reranking/{bedrock-reranking-api.ts → amazon-bedrock-reranking-api.ts} +3 -3
  45. package/src/reranking/{bedrock-reranking-options.ts → amazon-bedrock-reranking-model-options.ts} +1 -1
  46. package/src/reranking/{bedrock-reranking-model.ts → amazon-bedrock-reranking-model.ts} +32 -25
  47. package/dist/anthropic/index.d.mts +0 -91
  48. package/dist/anthropic/index.mjs +0 -397
  49. package/dist/anthropic/index.mjs.map +0 -1
  50. package/dist/index.d.mts +0 -194
  51. package/dist/index.mjs +0 -2329
  52. package/dist/index.mjs.map +0 -1
  53. package/src/anthropic/bedrock-anthropic-fetch.ts +0 -68
  54. package/src/bedrock-api-types.ts +0 -216
  55. package/src/bedrock-image-settings.ts +0 -6
  56. package/src/convert-to-bedrock-chat-messages.ts +0 -468
@@ -35,6 +35,31 @@ See the [Model Access Docs](https://docs.aws.amazon.com/bedrock/latest/userguide
35
35
 
36
36
  ### Authentication
37
37
 
38
+ The Amazon Bedrock provider supports two authentication methods with automatic fallback: API key authentication (recommended) and AWS SigV4 authentication using IAM credentials or the AWS SDK credentials chain.
39
+
40
+ #### Using an API Key (Recommended)
41
+
42
+ API key authentication provides a simpler setup compared to AWS SigV4 authentication. When an API key is supplied, it takes precedence over any SigV4 credentials.
43
+
44
+ Generate a bedrock API key from the [AWS console](https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html), then either set it as the `AWS_BEARER_TOKEN_BEDROCK` environment variable:
45
+
46
+ ```bash
47
+ AWS_BEARER_TOKEN_BEDROCK=your-api-key-here
48
+ ```
49
+
50
+ or pass it directly to `createAmazonBedrock`:
51
+
52
+ ```ts
53
+ import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
54
+
55
+ const amazonBedrock = createAmazonBedrock({
56
+ apiKey: 'your-api-key-here',
57
+ region: 'us-east-1',
58
+ });
59
+ ```
60
+
61
+ When `apiKey` is omitted, the provider falls back to `AWS_BEARER_TOKEN_BEDROCK`, and then to SigV4 authentication if neither is set.
62
+
38
63
  #### Using IAM Access Key and Secret Key
39
64
 
40
65
  **Step 1: Creating AWS Access Key and Secret Key**
@@ -105,7 +130,7 @@ _Usage:_
105
130
  import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
106
131
  import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
107
132
 
108
- const bedrock = createAmazonBedrock({
133
+ const amazonBedrock = createAmazonBedrock({
109
134
  region: 'us-east-1',
110
135
  credentialProvider: fromNodeProviderChain(),
111
136
  });
@@ -113,10 +138,10 @@ const bedrock = createAmazonBedrock({
113
138
 
114
139
  ## Provider Instance
115
140
 
116
- You can import the default provider instance `bedrock` from `@ai-sdk/amazon-bedrock`:
141
+ You can import the default provider instance `amazonBedrock` from `@ai-sdk/amazon-bedrock`:
117
142
 
118
143
  ```ts
119
- import { bedrock } from '@ai-sdk/amazon-bedrock';
144
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
120
145
  ```
121
146
 
122
147
  If you need a customized setup, you can import `createAmazonBedrock` from `@ai-sdk/amazon-bedrock` and create a provider instance with your settings:
@@ -124,7 +149,7 @@ If you need a customized setup, you can import `createAmazonBedrock` from `@ai-s
124
149
  ```ts
125
150
  import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
126
151
 
127
- const bedrock = createAmazonBedrock({
152
+ const amazonBedrock = createAmazonBedrock({
128
153
  region: 'us-east-1',
129
154
  accessKeyId: 'xxxxxxxxx',
130
155
  secretAccessKey: 'xxxxxxxxx',
@@ -133,12 +158,10 @@ const bedrock = createAmazonBedrock({
133
158
  ```
134
159
 
135
160
  <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.
161
+ Omitted options use the environment variables below. When **both**
162
+ `accessKeyId` and `secretAccessKey` are strings, SigV4 uses a **`sessionToken`
163
+ only if you pass one** - not `AWS_SESSION_TOKEN` from the environment - so
164
+ static keys are not mixed with workload tokens (e.g. EKS IRSA).
142
165
  </Note>
143
166
 
144
167
  You can use the following optional settings to customize the Amazon Bedrock provider instance:
@@ -160,8 +183,10 @@ You can use the following optional settings to customize the Amazon Bedrock prov
160
183
 
161
184
  - **sessionToken** _string_
162
185
 
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.
186
+ Optional. For temporary credentials. With **both** access keys set as strings,
187
+ pass the token here if needed; `AWS_SESSION_TOKEN` from the environment is not
188
+ used. If either key is taken from the environment, omitting `sessionToken`
189
+ allows `AWS_SESSION_TOKEN`.
165
190
 
166
191
  - **credentialProvider** _() =&gt; Promise&lt;&#123; accessKeyId: string; secretAccessKey: string; sessionToken?: string; &#125;&gt;_
167
192
 
@@ -195,14 +220,14 @@ You can create models that call the Bedrock API using the provider instance.
195
220
  The first argument is the model id, e.g. `meta.llama3-70b-instruct-v1:0`.
196
221
 
197
222
  ```ts
198
- const model = bedrock('meta.llama3-70b-instruct-v1:0');
223
+ const model = amazonBedrock('meta.llama3-70b-instruct-v1:0');
199
224
  ```
200
225
 
201
226
  Amazon Bedrock models also support some model specific provider options that are not part of the [standard call settings](/docs/ai-sdk-core/settings).
202
227
  You can pass them in the `providerOptions` argument:
203
228
 
204
229
  ```ts
205
- const model = bedrock('anthropic.claude-3-sonnet-20240229-v1:0');
230
+ const model = amazonBedrock('anthropic.claude-3-sonnet-20240229-v1:0');
206
231
 
207
232
  await generateText({
208
233
  model,
@@ -219,11 +244,11 @@ Documentation for additional settings based on the selected model can be found w
219
244
  You can use Amazon Bedrock language models to generate text with the `generateText` function:
220
245
 
221
246
  ```ts
222
- import { bedrock } from '@ai-sdk/amazon-bedrock';
247
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
223
248
  import { generateText } from 'ai';
224
249
 
225
250
  const { text } = await generateText({
226
- model: bedrock('meta.llama3-70b-instruct-v1:0'),
251
+ model: amazonBedrock('meta.llama3-70b-instruct-v1:0'),
227
252
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
228
253
  });
229
254
  ```
@@ -241,11 +266,11 @@ Amazon Bedrock language models can also be used in the `streamText` function
241
266
  The Amazon Bedrock provider supports file inputs, e.g. PDF files.
242
267
 
243
268
  ```ts
244
- import { bedrock } from '@ai-sdk/amazon-bedrock';
269
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
245
270
  import { generateText } from 'ai';
246
271
 
247
272
  const result = await generateText({
248
- model: bedrock('anthropic.claude-3-haiku-20240307-v1:0'),
273
+ model: amazonBedrock('anthropic.claude-3-haiku-20240307-v1:0'),
249
274
  messages: [
250
275
  {
251
276
  role: 'user',
@@ -267,10 +292,10 @@ const result = await generateText({
267
292
  You can use the `bedrock` provider options to utilize [Amazon Bedrock Guardrails](https://aws.amazon.com/bedrock/guardrails/):
268
293
 
269
294
  ```ts
270
- import { type AmazonBedrockLanguageModelOptions } from '@ai-sdk/amazon-bedrock';
295
+ import { type AmazonBedrockLanguageModelChatOptions } from '@ai-sdk/amazon-bedrock';
271
296
 
272
297
  const result = await generateText({
273
- model: bedrock('anthropic.claude-3-sonnet-20240229-v1:0'),
298
+ model: amazonBedrock('anthropic.claude-3-sonnet-20240229-v1:0'),
274
299
  prompt: 'Write a story about space exploration.',
275
300
  providerOptions: {
276
301
  bedrock: {
@@ -280,7 +305,7 @@ const result = await generateText({
280
305
  trace: 'enabled' as const,
281
306
  streamProcessingMode: 'async',
282
307
  },
283
- } satisfies AmazonBedrockLanguageModelOptions,
308
+ } satisfies AmazonBedrockLanguageModelChatOptions,
284
309
  },
285
310
  });
286
311
  ```
@@ -303,13 +328,13 @@ Amazon Bedrock supports citations for document-based inputs across compatible mo
303
328
  - Models can cite specific parts of documents you provide, making it easier to trace information back to its source (Not Supported Yet)
304
329
 
305
330
  ```ts
306
- import { bedrock } from '@ai-sdk/amazon-bedrock';
331
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
307
332
  import { generateText, Output } from 'ai';
308
333
  import { z } from 'zod';
309
334
  import fs from 'fs';
310
335
 
311
336
  const result = await generateText({
312
- model: bedrock('apac.anthropic.claude-sonnet-4-20250514-v1:0'),
337
+ model: amazonBedrock('apac.anthropic.claude-sonnet-4-20250514-v1:0'),
313
338
  output: Output.object({
314
339
  schema: z.object({
315
340
  summary: z.string().describe('Summary of the PDF document'),
@@ -377,14 +402,14 @@ Cache usage information is returned in the `providerMetadata` object. See exampl
377
402
  </Note>
378
403
 
379
404
  ```ts
380
- import { bedrock } from '@ai-sdk/amazon-bedrock';
405
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
381
406
  import { generateText } from 'ai';
382
407
 
383
408
  const cyberpunkAnalysis =
384
409
  '... literary analysis of cyberpunk themes and concepts ...';
385
410
 
386
411
  const result = await generateText({
387
- model: bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
412
+ model: amazonBedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
388
413
  messages: [
389
414
  {
390
415
  role: 'system',
@@ -413,14 +438,14 @@ console.log(result.providerMetadata?.bedrock?.usage);
413
438
  Cache points also work with streaming responses:
414
439
 
415
440
  ```ts
416
- import { bedrock } from '@ai-sdk/amazon-bedrock';
441
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
417
442
  import { streamText } from 'ai';
418
443
 
419
444
  const cyberpunkAnalysis =
420
445
  '... literary analysis of cyberpunk themes and concepts ...';
421
446
 
422
447
  const result = streamText({
423
- model: bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
448
+ model: amazonBedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
424
449
  messages: [
425
450
  {
426
451
  role: 'assistant',
@@ -477,19 +502,19 @@ Amazon Bedrock supports model creator-specific reasoning features:
477
502
 
478
503
  ```ts
479
504
  import {
480
- bedrock,
481
- type AmazonBedrockLanguageModelOptions,
505
+ amazonBedrock,
506
+ type AmazonBedrockLanguageModelChatOptions,
482
507
  } from '@ai-sdk/amazon-bedrock';
483
508
  import { generateText } from 'ai';
484
509
 
485
510
  // Anthropic example
486
511
  const anthropicResult = await generateText({
487
- model: bedrock('us.anthropic.claude-sonnet-4-5-20250929-v1:0'),
512
+ model: amazonBedrock('us.anthropic.claude-sonnet-4-5-20250929-v1:0'),
488
513
  prompt: 'How many people will live in the world in 2040?',
489
514
  providerOptions: {
490
515
  bedrock: {
491
516
  reasoningConfig: { type: 'enabled', budgetTokens: 1024 },
492
- } satisfies AmazonBedrockLanguageModelOptions,
517
+ } satisfies AmazonBedrockLanguageModelChatOptions,
493
518
  },
494
519
  });
495
520
 
@@ -498,12 +523,12 @@ console.log(anthropicResult.text); // text response
498
523
 
499
524
  // Nova 2 example
500
525
  const amazonResult = await generateText({
501
- model: bedrock('us.amazon.nova-2-lite-v1:0'),
526
+ model: amazonBedrock('us.amazon.nova-2-lite-v1:0'),
502
527
  prompt: 'How many people will live in the world in 2040?',
503
528
  providerOptions: {
504
529
  bedrock: {
505
530
  reasoningConfig: { type: 'enabled', maxReasoningEffort: 'medium' },
506
- } satisfies AmazonBedrockLanguageModelOptions,
531
+ } satisfies AmazonBedrockLanguageModelChatOptions,
507
532
  },
508
533
  });
509
534
 
@@ -514,24 +539,55 @@ console.log(amazonResult.text); // text response
514
539
  See [AI SDK UI: Chatbot](/docs/ai-sdk-ui/chatbot#reasoning) for more details
515
540
  on how to integrate reasoning into your chatbot.
516
541
 
542
+ ## Service Tiers
543
+
544
+ Amazon Bedrock supports selecting an inference service tier per request via the `serviceTier` provider option.
545
+
546
+ ```ts
547
+ import {
548
+ amazonBedrock,
549
+ type AmazonBedrockLanguageModelChatOptions,
550
+ } from '@ai-sdk/amazon-bedrock';
551
+ import { generateText } from 'ai';
552
+
553
+ const result = await generateText({
554
+ model: amazonBedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
555
+ prompt: 'Summarize this support ticket backlog.',
556
+ providerOptions: {
557
+ bedrock: {
558
+ serviceTier: 'priority',
559
+ } satisfies AmazonBedrockLanguageModelChatOptions,
560
+ },
561
+ });
562
+ ```
563
+
564
+ Supported values are:
565
+
566
+ - `reserved`
567
+ - `priority`
568
+ - `default`
569
+ - `flex`
570
+
571
+ See the [Amazon Bedrock service tiers documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html) for model availability and behavior.
572
+
517
573
  ## Extended Context Window
518
574
 
519
575
  Claude Sonnet 4 models on Amazon Bedrock support an extended context window of up to 1 million tokens when using the `context-1m-2025-08-07` beta feature.
520
576
 
521
577
  ```ts
522
578
  import {
523
- bedrock,
524
- type AmazonBedrockLanguageModelOptions,
579
+ amazonBedrock,
580
+ type AmazonBedrockLanguageModelChatOptions,
525
581
  } from '@ai-sdk/amazon-bedrock';
526
582
  import { generateText } from 'ai';
527
583
 
528
584
  const result = await generateText({
529
- model: bedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
585
+ model: amazonBedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
530
586
  prompt: 'analyze this large document...',
531
587
  providerOptions: {
532
588
  bedrock: {
533
589
  anthropicBeta: ['context-1m-2025-08-07'],
534
- } satisfies AmazonBedrockLanguageModelOptions,
590
+ } satisfies AmazonBedrockLanguageModelChatOptions,
535
591
  },
536
592
  });
537
593
  ```
@@ -556,7 +612,7 @@ They are available via the `tools` property of the provider instance.
556
612
  The Bash Tool allows running bash commands. Here's how to create and use it:
557
613
 
558
614
  ```ts
559
- const bashTool = bedrock.tools.bash_20241022({
615
+ const bashTool = amazonBedrock.tools.bash_20241022({
560
616
  execute: async ({ command, restart }) => {
561
617
  // Implement your bash command execution logic here
562
618
  // Return the result of the command execution
@@ -576,7 +632,7 @@ The Text Editor Tool provides functionality for viewing and editing text files.
576
632
  **For Claude 4 models (Opus & Sonnet):**
577
633
 
578
634
  ```ts
579
- const textEditorTool = bedrock.tools.textEditor_20250429({
635
+ const textEditorTool = amazonBedrock.tools.textEditor_20250429({
580
636
  execute: async ({
581
637
  command,
582
638
  path,
@@ -596,7 +652,7 @@ const textEditorTool = bedrock.tools.textEditor_20250429({
596
652
  **For Claude 3.5 Sonnet and earlier models:**
597
653
 
598
654
  ```ts
599
- const textEditorTool = bedrock.tools.textEditor_20241022({
655
+ const textEditorTool = amazonBedrock.tools.textEditor_20241022({
600
656
  execute: async ({
601
657
  command,
602
658
  path,
@@ -632,7 +688,7 @@ When using the Text Editor Tool, make sure to name the key in the tools object c
632
688
  ```ts
633
689
  // For Claude 4 models
634
690
  const response = await generateText({
635
- model: bedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
691
+ model: amazonBedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
636
692
  prompt:
637
693
  "Create a new file called example.txt, write 'Hello World' to it, and run 'cat example.txt' in the terminal",
638
694
  tools: {
@@ -642,7 +698,7 @@ const response = await generateText({
642
698
 
643
699
  // For Claude 3.5 Sonnet and earlier
644
700
  const response = await generateText({
645
- model: bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
701
+ model: amazonBedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
646
702
  prompt:
647
703
  "Create a new file called example.txt, write 'Hello World' to it, and run 'cat example.txt' in the terminal",
648
704
  tools: {
@@ -656,7 +712,7 @@ const response = await generateText({
656
712
  The Computer Tool enables control of keyboard and mouse actions on a computer:
657
713
 
658
714
  ```ts
659
- const computerTool = bedrock.tools.computer_20241022({
715
+ const computerTool = amazonBedrock.tools.computer_20241022({
660
716
  displayWidthPx: 1920,
661
717
  displayHeightPx: 1080,
662
718
  displayNumber: 0, // Optional, for X11 environments
@@ -689,7 +745,7 @@ const computerTool = bedrock.tools.computer_20241022({
689
745
  toModelOutput({ output }) {
690
746
  return typeof output === 'string'
691
747
  ? [{ type: 'text', text: output }]
692
- : [{ type: 'image', data: output.data, mediaType: 'image/png' }];
748
+ : [{ type: 'file-data', data: output.data, mediaType: 'image/png' }];
693
749
  },
694
750
  });
695
751
  ```
@@ -779,18 +835,18 @@ You can create models that call the Bedrock API [Bedrock API](https://docs.aws.a
779
835
  using the `.embedding()` factory method.
780
836
 
781
837
  ```ts
782
- const model = bedrock.embedding('amazon.titan-embed-text-v1');
838
+ const model = amazonBedrock.embedding('amazon.titan-embed-text-v1');
783
839
  ```
784
840
 
785
841
  Bedrock Titan embedding model amazon.titan-embed-text-v2:0 supports several additional settings.
786
842
  You can pass them as an options argument:
787
843
 
788
844
  ```ts
789
- import { bedrock } from '@ai-sdk/amazon-bedrock';
845
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
790
846
  import { type AmazonBedrockEmbeddingModelOptions } from '@ai-sdk/amazon-bedrock';
791
847
  import { embed } from 'ai';
792
848
 
793
- const model = bedrock.embedding('amazon.titan-embed-text-v2:0');
849
+ const model = amazonBedrock.embedding('amazon.titan-embed-text-v2:0');
794
850
 
795
851
  const { embedding } = await embed({
796
852
  model,
@@ -819,12 +875,12 @@ The following optional provider options are available for Bedrock Titan embeddin
819
875
  Amazon Nova embedding models support additional provider options:
820
876
 
821
877
  ```ts
822
- import { bedrock } from '@ai-sdk/amazon-bedrock';
878
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
823
879
  import { type AmazonBedrockEmbeddingModelOptions } from '@ai-sdk/amazon-bedrock';
824
880
  import { embed } from 'ai';
825
881
 
826
882
  const { embedding } = await embed({
827
- model: bedrock.embedding('amazon.nova-embed-text-v2:0'),
883
+ model: amazonBedrock.embedding('amazon.nova-embed-text-v2:0'),
828
884
  value: 'sunny day at the beach',
829
885
  providerOptions: {
830
886
  bedrock: {
@@ -855,12 +911,12 @@ The following optional provider options are available for Nova embedding models:
855
911
  Cohere embedding models on Bedrock require an `inputType` and support truncation:
856
912
 
857
913
  ```ts
858
- import { bedrock } from '@ai-sdk/amazon-bedrock';
914
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
859
915
  import { type AmazonBedrockEmbeddingModelOptions } from '@ai-sdk/amazon-bedrock';
860
916
  import { embed } from 'ai';
861
917
 
862
918
  const { embedding } = await embed({
863
- model: bedrock.embedding('cohere.embed-english-v3'),
919
+ model: amazonBedrock.embedding('cohere.embed-english-v3'),
864
920
  value: 'sunny day at the beach',
865
921
  providerOptions: {
866
922
  bedrock: {
@@ -897,13 +953,13 @@ You can create models that call the [Bedrock Rerank API](https://docs.aws.amazon
897
953
  using the `.reranking()` factory method.
898
954
 
899
955
  ```ts
900
- const model = bedrock.reranking('cohere.rerank-v3-5:0');
956
+ const model = amazonBedrock.reranking('cohere.rerank-v3-5:0');
901
957
  ```
902
958
 
903
959
  You can use Amazon Bedrock reranking models to rerank documents with the `rerank` function:
904
960
 
905
961
  ```ts
906
- import { bedrock } from '@ai-sdk/amazon-bedrock';
962
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
907
963
  import { rerank } from 'ai';
908
964
 
909
965
  const documents = [
@@ -913,7 +969,7 @@ const documents = [
913
969
  ];
914
970
 
915
971
  const { ranking } = await rerank({
916
- model: bedrock.reranking('cohere.rerank-v3-5:0'),
972
+ model: amazonBedrock.reranking('cohere.rerank-v3-5:0'),
917
973
  documents,
918
974
  query: 'talk about rain',
919
975
  topN: 2,
@@ -929,11 +985,11 @@ console.log(ranking);
929
985
  Amazon Bedrock reranking models support additional provider options that can be passed via `providerOptions.bedrock`:
930
986
 
931
987
  ```ts
932
- import { bedrock } from '@ai-sdk/amazon-bedrock';
988
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
933
989
  import { rerank } from 'ai';
934
990
 
935
991
  const { ranking } = await rerank({
936
- model: bedrock.reranking('cohere.rerank-v3-5:0'),
992
+ model: amazonBedrock.reranking('cohere.rerank-v3-5:0'),
937
993
  documents: ['sunny day at the beach', 'rainy afternoon in the city'],
938
994
  query: 'talk about rain',
939
995
  providerOptions: {
@@ -975,17 +1031,17 @@ Overview](https://docs.aws.amazon.com/ai/responsible-ai/nova-canvas/overview.htm
975
1031
  </Note>
976
1032
 
977
1033
  ```ts
978
- const model = bedrock.image('amazon.nova-canvas-v1:0');
1034
+ const model = amazonBedrock.image('amazon.nova-canvas-v1:0');
979
1035
  ```
980
1036
 
981
1037
  You can then generate images with the `generateImage` function:
982
1038
 
983
1039
  ```ts
984
- import { bedrock } from '@ai-sdk/amazon-bedrock';
1040
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
985
1041
  import { generateImage } from 'ai';
986
1042
 
987
1043
  const { image } = await generateImage({
988
- model: bedrock.image('amazon.nova-canvas-v1:0'),
1044
+ model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
989
1045
  prompt: 'A beautiful sunset over a calm ocean',
990
1046
  size: '512x512',
991
1047
  seed: 42,
@@ -995,11 +1051,11 @@ const { image } = await generateImage({
995
1051
  You can also pass the `providerOptions` object to the `generateImage` function to customize the generation behavior:
996
1052
 
997
1053
  ```ts
998
- import { bedrock } from '@ai-sdk/amazon-bedrock';
1054
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
999
1055
  import { generateImage } from 'ai';
1000
1056
 
1001
1057
  const { image } = await generateImage({
1002
- model: bedrock.image('amazon.nova-canvas-v1:0'),
1058
+ model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
1003
1059
  prompt: 'A beautiful sunset over a calm ocean',
1004
1060
  size: '512x512',
1005
1061
  seed: 42,
@@ -1052,7 +1108,7 @@ Create variations of an existing image while maintaining its core characteristic
1052
1108
  const imageBuffer = readFileSync('./input-image.png');
1053
1109
 
1054
1110
  const { images } = await generateImage({
1055
- model: bedrock.image('amazon.nova-canvas-v1:0'),
1111
+ model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
1056
1112
  prompt: {
1057
1113
  text: 'Modernize the style, photo-realistic, 8k, hdr',
1058
1114
  images: [imageBuffer],
@@ -1081,7 +1137,7 @@ Edit specific parts of an image. You can define the area to modify using either
1081
1137
  const imageBuffer = readFileSync('./input-image.png');
1082
1138
 
1083
1139
  const { images } = await generateImage({
1084
- model: bedrock.image('amazon.nova-canvas-v1:0'),
1140
+ model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
1085
1141
  prompt: {
1086
1142
  text: 'a cute corgi dog in the same style',
1087
1143
  images: [imageBuffer],
@@ -1102,7 +1158,7 @@ const image = readFileSync('./input-image.png');
1102
1158
  const mask = readFileSync('./mask.png'); // White pixels = area to change
1103
1159
 
1104
1160
  const { images } = await generateImage({
1105
- model: bedrock.image('amazon.nova-canvas-v1:0'),
1161
+ model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
1106
1162
  prompt: {
1107
1163
  text: 'A sunlit indoor lounge area with a pool containing a flamingo',
1108
1164
  images: [image],
@@ -1123,7 +1179,7 @@ Extend an image beyond its original boundaries:
1123
1179
  const imageBuffer = readFileSync('./input-image.png');
1124
1180
 
1125
1181
  const { images } = await generateImage({
1126
- model: bedrock.image('amazon.nova-canvas-v1:0'),
1182
+ model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
1127
1183
  prompt: {
1128
1184
  text: 'A beautiful sunset landscape with mountains',
1129
1185
  images: [imageBuffer],
@@ -1150,7 +1206,7 @@ Remove the background from an image:
1150
1206
  const imageBuffer = readFileSync('./input-image.png');
1151
1207
 
1152
1208
  const { images } = await generateImage({
1153
- model: bedrock.image('amazon.nova-canvas-v1:0'),
1209
+ model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
1154
1210
  prompt: {
1155
1211
  images: [imageBuffer],
1156
1212
  },
@@ -1193,7 +1249,7 @@ You can customize the generation behavior with optional options:
1193
1249
 
1194
1250
  ```ts
1195
1251
  await generateImage({
1196
- model: bedrock.image('amazon.nova-canvas-v1:0'),
1252
+ model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
1197
1253
  prompt: 'A beautiful sunset over a calm ocean',
1198
1254
  size: '512x512',
1199
1255
  seed: 42,
@@ -1228,11 +1284,11 @@ The Amazon Bedrock provider will return the response headers associated with
1228
1284
  network requests made of the Bedrock servers.
1229
1285
 
1230
1286
  ```ts
1231
- import { bedrock } from '@ai-sdk/amazon-bedrock';
1287
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
1232
1288
  import { generateText } from 'ai';
1233
1289
 
1234
1290
  const { text } = await generateText({
1235
- model: bedrock('meta.llama3-70b-instruct-v1:0'),
1291
+ model: amazonBedrock('meta.llama3-70b-instruct-v1:0'),
1236
1292
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
1237
1293
  });
1238
1294
 
@@ -1255,11 +1311,11 @@ be useful for correlating Bedrock API calls with requests made by the AI SDK:
1255
1311
  This information is also available with `streamText`:
1256
1312
 
1257
1313
  ```ts
1258
- import { bedrock } from '@ai-sdk/amazon-bedrock';
1314
+ import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
1259
1315
  import { streamText } from 'ai';
1260
1316
 
1261
1317
  const result = streamText({
1262
- model: bedrock('meta.llama3-70b-instruct-v1:0'),
1318
+ model: amazonBedrock('meta.llama3-70b-instruct-v1:0'),
1263
1319
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
1264
1320
  });
1265
1321
  for await (const textPart of result.textStream) {
@@ -1328,8 +1384,10 @@ You can use the following optional settings to customize the Bedrock Anthropic p
1328
1384
 
1329
1385
  - **sessionToken** _string_
1330
1386
 
1331
- Optional. The AWS session token that you want to use for the API calls.
1332
- It uses the `AWS_SESSION_TOKEN` environment variable by default.
1387
+ Optional. For temporary credentials. With **both** access keys set as strings,
1388
+ pass the token here if needed; `AWS_SESSION_TOKEN` from the environment is not
1389
+ used. If either key is taken from the environment, omitting `sessionToken`
1390
+ allows `AWS_SESSION_TOKEN`.
1333
1391
 
1334
1392
  - **apiKey** _string_
1335
1393
 
@@ -1380,6 +1438,15 @@ const { text } = await generateText({
1380
1438
  });
1381
1439
  ```
1382
1440
 
1441
+ ### Provider Options
1442
+
1443
+ The following optional provider options are available for Bedrock Anthropic models:
1444
+
1445
+ - `metadata` _object_
1446
+
1447
+ Optional. Metadata to include with the request. See the [Anthropic API documentation](https://platform.claude.com/docs/en/api/messages/create) for details.
1448
+ - `userId` _string_ - An external identifier for the end-user.
1449
+
1383
1450
  ### Cache Control
1384
1451
 
1385
1452
  In the messages and message parts, you can use the `providerOptions` property to set cache control breakpoints.
@@ -1433,7 +1500,7 @@ They are available via the `tools` property of the provider instance.
1433
1500
 
1434
1501
  ```ts
1435
1502
  import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
1436
- import { generateText, stepCountIs } from 'ai';
1503
+ import { generateText, isStepCount } from 'ai';
1437
1504
 
1438
1505
  const result = await generateText({
1439
1506
  model: bedrockAnthropic('us.anthropic.claude-sonnet-4-5-20250929-v1:0'),
@@ -1446,7 +1513,7 @@ const result = await generateText({
1446
1513
  }),
1447
1514
  },
1448
1515
  prompt: 'List the files in my directory.',
1449
- stopWhen: stepCountIs(2),
1516
+ stopWhen: isStepCount(2),
1450
1517
  });
1451
1518
  ```
1452
1519
 
@@ -1454,7 +1521,7 @@ const result = await generateText({
1454
1521
 
1455
1522
  ```ts
1456
1523
  import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
1457
- import { generateText, stepCountIs } from 'ai';
1524
+ import { generateText, isStepCount } from 'ai';
1458
1525
 
1459
1526
  const result = await generateText({
1460
1527
  model: bedrockAnthropic('us.anthropic.claude-sonnet-4-5-20250929-v1:0'),
@@ -1467,7 +1534,7 @@ const result = await generateText({
1467
1534
  }),
1468
1535
  },
1469
1536
  prompt: 'Update my README file.',
1470
- stopWhen: stepCountIs(5),
1537
+ stopWhen: isStepCount(5),
1471
1538
  });
1472
1539
  ```
1473
1540
 
@@ -1475,7 +1542,7 @@ const result = await generateText({
1475
1542
 
1476
1543
  ```ts
1477
1544
  import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
1478
- import { generateText, stepCountIs } from 'ai';
1545
+ import { generateText, isStepCount } from 'ai';
1479
1546
  import fs from 'fs';
1480
1547
 
1481
1548
  const result = await generateText({
@@ -1510,7 +1577,7 @@ const result = await generateText({
1510
1577
  }),
1511
1578
  },
1512
1579
  prompt: 'Take a screenshot.',
1513
- stopWhen: stepCountIs(3),
1580
+ stopWhen: isStepCount(3),
1514
1581
  });
1515
1582
  ```
1516
1583
 
@@ -1518,6 +1585,9 @@ const result = await generateText({
1518
1585
 
1519
1586
  Anthropic has reasoning support for Claude 3.7 and Claude 4 models on Bedrock, including:
1520
1587
 
1588
+ - `us.anthropic.claude-fable-5`
1589
+ - `us.anthropic.claude-opus-4-8`
1590
+ - `us.anthropic.claude-opus-4-7`
1521
1591
  - `us.anthropic.claude-opus-4-6-v1`
1522
1592
  - `us.anthropic.claude-opus-4-5-20251101-v1:0`
1523
1593
  - `us.anthropic.claude-sonnet-4-5-20250929-v1:0`
@@ -1554,6 +1624,9 @@ on how to integrate reasoning into your chatbot.
1554
1624
 
1555
1625
  | Model | Image Input | Object Generation | Tool Usage | Computer Use | Reasoning |
1556
1626
  | ---------------------------------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
1627
+ | `us.anthropic.claude-fable-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
1628
+ | `us.anthropic.claude-opus-4-8` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
1629
+ | `us.anthropic.claude-opus-4-7` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
1557
1630
  | `us.anthropic.claude-opus-4-6-v1` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
1558
1631
  | `us.anthropic.claude-opus-4-5-20251101-v1:0` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
1559
1632
  | `us.anthropic.claude-sonnet-4-5-20250929-v1:0` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
@@ -1569,6 +1642,163 @@ on how to integrate reasoning into your chatbot.
1569
1642
  Connector which are not supported on Bedrock.
1570
1643
  </Note>
1571
1644
 
1645
+ ## Bedrock Mantle Provider Usage
1646
+
1647
+ The Bedrock Mantle provider offers access to OpenAI-compatible models through Amazon Bedrock's Mantle API at `https://bedrock-mantle.{region}.api.aws/v1`. This endpoint supports the Chat Completions API and the Responses API, and provides access to models that may only be available through the Mantle endpoint (such as `openai.gpt-oss-120b`).
1648
+
1649
+ ### Provider Instance
1650
+
1651
+ You can import the default provider instance `bedrockMantle` from `@ai-sdk/amazon-bedrock/mantle`:
1652
+
1653
+ ```typescript
1654
+ import { bedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1655
+ ```
1656
+
1657
+ If you need a customized setup, you can import `createBedrockMantle` from `@ai-sdk/amazon-bedrock/mantle` and create a provider instance with your settings:
1658
+
1659
+ ```typescript
1660
+ import { createBedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1661
+
1662
+ const bedrockMantle = createBedrockMantle({
1663
+ region: 'us-east-1', // optional
1664
+ accessKeyId: 'xxxxxxxxx', // optional
1665
+ secretAccessKey: 'xxxxxxxxx', // optional
1666
+ sessionToken: 'xxxxxxxxx', // optional
1667
+ });
1668
+ ```
1669
+
1670
+ #### Provider Settings
1671
+
1672
+ You can use the following optional settings to customize the Bedrock Mantle provider instance:
1673
+
1674
+ - **region** _string_
1675
+
1676
+ The AWS region that you want to use for the API calls.
1677
+ It uses the `AWS_REGION` environment variable by default.
1678
+
1679
+ - **accessKeyId** _string_
1680
+
1681
+ The AWS access key ID that you want to use for the API calls.
1682
+ It uses the `AWS_ACCESS_KEY_ID` environment variable by default.
1683
+
1684
+ - **secretAccessKey** _string_
1685
+
1686
+ The AWS secret access key that you want to use for the API calls.
1687
+ It uses the `AWS_SECRET_ACCESS_KEY` environment variable by default.
1688
+
1689
+ - **sessionToken** _string_
1690
+
1691
+ Optional. The AWS session token that you want to use for the API calls.
1692
+ It uses the `AWS_SESSION_TOKEN` environment variable by default.
1693
+
1694
+ - **apiKey** _string_
1695
+
1696
+ API key for authenticating requests using Bearer token authentication.
1697
+ When provided, this will be used instead of AWS SigV4 authentication.
1698
+ It uses the `AWS_BEARER_TOKEN_BEDROCK` environment variable by default.
1699
+
1700
+ - **baseURL** _string_
1701
+
1702
+ Base URL for the Bedrock Mantle API calls.
1703
+ Defaults to `https://bedrock-mantle.{region}.api.aws/v1`.
1704
+
1705
+ - **headers** _Record&lt;string, string | undefined&gt;_
1706
+
1707
+ Headers to include in the requests.
1708
+
1709
+ - **fetch** _(input: RequestInfo, init?: RequestInit) => Promise&lt;Response&gt;_
1710
+
1711
+ Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
1712
+ You can use it as a middleware to intercept requests,
1713
+ or to provide a custom fetch implementation for e.g. testing.
1714
+
1715
+ - **credentialProvider** _() => PromiseLike&lt;BedrockCredentials&gt;_
1716
+
1717
+ The AWS credential provider to use for the Bedrock provider to get dynamic
1718
+ credentials similar to the AWS SDK. Setting a provider here will cause its
1719
+ credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
1720
+ and `sessionToken` settings.
1721
+
1722
+ ### Language Models
1723
+
1724
+ You can create models using the Mantle provider instance. By default, the provider creates models using the Chat Completions API, which has the broadest model support on Mantle:
1725
+
1726
+ ```ts
1727
+ const model = bedrockMantle('openai.gpt-oss-120b');
1728
+ ```
1729
+
1730
+ You can also explicitly select the Chat Completions API or the Responses API:
1731
+
1732
+ ```ts
1733
+ const chatModel = bedrockMantle.chat('openai.gpt-oss-120b');
1734
+ const responsesModel = bedrockMantle.responses('openai.gpt-oss-120b');
1735
+ ```
1736
+
1737
+ Note that not all Mantle models support the Responses API. See the model capabilities table below.
1738
+
1739
+ You can use Bedrock Mantle language models to generate text with the `generateText` function:
1740
+
1741
+ ```ts
1742
+ import { bedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1743
+ import { generateText } from 'ai';
1744
+
1745
+ const { text } = await generateText({
1746
+ model: bedrockMantle('openai.gpt-oss-120b'),
1747
+ prompt: 'Invent a new holiday and describe its traditions.',
1748
+ });
1749
+ ```
1750
+
1751
+ Or stream text with the `streamText` function:
1752
+
1753
+ ```ts
1754
+ import { bedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1755
+ import { streamText } from 'ai';
1756
+
1757
+ const result = streamText({
1758
+ model: bedrockMantle('openai.gpt-oss-120b'),
1759
+ prompt: 'Invent a new holiday and describe its traditions.',
1760
+ });
1761
+
1762
+ for await (const textPart of result.textStream) {
1763
+ process.stdout.write(textPart);
1764
+ }
1765
+ ```
1766
+
1767
+ ### Provider Options
1768
+
1769
+ Since the Mantle API is OpenAI-compatible, provider options are passed under the `openai` namespace:
1770
+
1771
+ ```ts
1772
+ import { bedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1773
+ import { generateText } from 'ai';
1774
+
1775
+ const { text } = await generateText({
1776
+ model: bedrockMantle('openai.gpt-oss-120b'),
1777
+ prompt: 'Hello!',
1778
+ providerOptions: {
1779
+ openai: {
1780
+ // OpenAI-compatible provider options
1781
+ },
1782
+ },
1783
+ });
1784
+ ```
1785
+
1786
+ ### Model Capabilities
1787
+
1788
+ | Model | Chat Completions | Responses API |
1789
+ | ------------------------------- | ------------------- | ------------------- |
1790
+ | `openai.gpt-oss-20b` | <Check size={18} /> | <Check size={18} /> |
1791
+ | `openai.gpt-oss-120b` | <Check size={18} /> | <Check size={18} /> |
1792
+ | `openai.gpt-oss-safeguard-20b` | <Check size={18} /> | <Cross size={18} /> |
1793
+ | `openai.gpt-oss-safeguard-120b` | <Check size={18} /> | <Cross size={18} /> |
1794
+
1795
+ <Note>
1796
+ The Bedrock Mantle provider uses the OpenAI-compatible API format. Models
1797
+ available through the Mantle endpoint may differ from those available through
1798
+ the Bedrock Converse API. Use the Mantle endpoint's model listing API to
1799
+ discover all available models.
1800
+ </Note>
1801
+
1572
1802
  ## Migrating to `@ai-sdk/amazon-bedrock` 2.x
1573
1803
 
1574
1804
  The Amazon Bedrock provider was rewritten in version 2.x to remove the
@@ -1578,8 +1808,4 @@ The `bedrockOptions` provider setting previously available has been removed. If
1578
1808
  you were using the `bedrockOptions` object, you should now use the `region`,
1579
1809
  `accessKeyId`, `secretAccessKey`, and `sessionToken` settings directly instead.
1580
1810
 
1581
- Note that you may need to set all of these explicitly, e.g. even if you're not
1582
- using `sessionToken`, set it to `undefined`. If you're running in a serverless
1583
- environment, there may be default environment variables set by your containing
1584
- environment that the Amazon Bedrock provider will then pick up and could
1585
- conflict with the ones you're intending to use.
1811
+ Static IAM user keys do not require `sessionToken`.