@ai-sdk/amazon-bedrock 5.0.0-beta.14 → 5.0.0-beta.16

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.
@@ -514,6 +514,37 @@ console.log(amazonResult.text); // text response
514
514
  See [AI SDK UI: Chatbot](/docs/ai-sdk-ui/chatbot#reasoning) for more details
515
515
  on how to integrate reasoning into your chatbot.
516
516
 
517
+ ## Service Tiers
518
+
519
+ Amazon Bedrock supports selecting an inference service tier per request via the `serviceTier` provider option.
520
+
521
+ ```ts
522
+ import {
523
+ bedrock,
524
+ type AmazonBedrockLanguageModelOptions,
525
+ } from '@ai-sdk/amazon-bedrock';
526
+ import { generateText } from 'ai';
527
+
528
+ const result = await generateText({
529
+ model: bedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
530
+ prompt: 'Summarize this support ticket backlog.',
531
+ providerOptions: {
532
+ bedrock: {
533
+ serviceTier: 'priority',
534
+ } satisfies AmazonBedrockLanguageModelOptions,
535
+ },
536
+ });
537
+ ```
538
+
539
+ Supported values are:
540
+
541
+ - `reserved`
542
+ - `priority`
543
+ - `default`
544
+ - `flex`
545
+
546
+ See the [Amazon Bedrock service tiers documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html) for model availability and behavior.
547
+
517
548
  ## Extended Context Window
518
549
 
519
550
  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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "5.0.0-beta.14",
3
+ "version": "5.0.0-beta.16",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -3,14 +3,40 @@ import {
3
3
  FetchFunction,
4
4
  safeParseJSON,
5
5
  } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
6
7
  import { createBedrockEventStreamDecoder } from '../bedrock-event-stream-decoder';
7
8
 
9
+ const bedrockErrorSchema = z.looseObject({
10
+ message: z.string().optional(),
11
+ });
12
+
8
13
  export function createBedrockAnthropicFetch(
9
14
  baseFetch: FetchFunction,
10
15
  ): FetchFunction {
11
16
  return async (url, options) => {
12
17
  const response = await baseFetch(url, options);
13
18
 
19
+ // Transform Bedrock error responses into Anthropic error format
20
+ // so that anthropicFailedResponseHandler can extract the message.
21
+ if (!response.ok) {
22
+ const text = await response.text();
23
+ const parsed = await safeParseJSON({ text, schema: bedrockErrorSchema });
24
+
25
+ const message =
26
+ parsed.success && parsed.value.message ? parsed.value.message : text;
27
+
28
+ const anthropicError = JSON.stringify({
29
+ type: 'error',
30
+ error: { type: 'error', message },
31
+ });
32
+
33
+ return new Response(anthropicError, {
34
+ status: response.status,
35
+ statusText: response.statusText,
36
+ headers: response.headers,
37
+ });
38
+ }
39
+
14
40
  const contentType = response.headers.get('content-type');
15
41
  if (
16
42
  contentType?.includes('application/vnd.amazon.eventstream') &&
@@ -13,6 +13,9 @@ export interface BedrockConverseInput {
13
13
  };
14
14
  additionalModelRequestFields?: Record<string, unknown>;
15
15
  additionalModelResponseFieldPaths?: string[];
16
+ serviceTier?: {
17
+ type: string;
18
+ };
16
19
  guardrailConfig?:
17
20
  | BedrockGuardrailConfiguration
18
21
  | BedrockGuardrailStreamConfiguration
@@ -383,6 +383,7 @@ export class BedrockChatLanguageModel implements LanguageModelV4 {
383
383
  const {
384
384
  reasoningConfig: _,
385
385
  additionalModelRequestFields: __,
386
+ serviceTier: ___,
386
387
  ...filteredBedrockOptions
387
388
  } = providerOptions?.bedrock || {};
388
389
 
@@ -402,6 +403,11 @@ export class BedrockChatLanguageModel implements LanguageModelV4 {
402
403
  ...(Object.keys(inferenceConfig).length > 0 && {
403
404
  inferenceConfig,
404
405
  }),
406
+ ...(bedrockOptions.serviceTier != null && {
407
+ serviceTier: {
408
+ type: bedrockOptions.serviceTier,
409
+ },
410
+ }),
405
411
  ...filteredBedrockOptions,
406
412
  ...(toolConfig.tools !== undefined && toolConfig.tools.length > 0
407
413
  ? { toolConfig }
@@ -122,6 +122,16 @@ export const amazonBedrockLanguageModelOptions = z.object({
122
122
  * Anthropic beta features to enable
123
123
  */
124
124
  anthropicBeta: z.array(z.string()).optional(),
125
+ /**
126
+ * Service tier for the request.
127
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/service-tiers-inference.html
128
+ *
129
+ * - 'reserved': Uses provisioned throughput capacity
130
+ * - 'priority': Prioritizes low-latency inference when capacity is available
131
+ * - 'default': Standard on-demand tier
132
+ * - 'flex': Lower-cost tier for flexible latency workloads
133
+ */
134
+ serviceTier: z.enum(['reserved', 'priority', 'default', 'flex']).optional(),
125
135
  });
126
136
 
127
137
  export type AmazonBedrockLanguageModelOptions = z.infer<