@ai-sdk/amazon-bedrock 4.0.42 → 4.0.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.42",
3
+ "version": "4.0.44",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -38,7 +38,7 @@
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.32",
41
+ "@ai-sdk/anthropic": "3.0.33",
42
42
  "@ai-sdk/provider": "3.0.6",
43
43
  "@ai-sdk/provider-utils": "4.0.11"
44
44
  },
@@ -47,8 +47,8 @@
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.3",
51
- "@vercel/ai-tsconfig": "0.0.0"
50
+ "@vercel/ai-tsconfig": "0.0.0",
51
+ "@ai-sdk/test-server": "1.0.3"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "zod": "^3.25.76 || ^4.1.8"
@@ -35,11 +35,31 @@ export interface BedrockUserMessage {
35
35
  content: Array<BedrockContentBlock>;
36
36
  }
37
37
 
38
- export const BEDROCK_CACHE_POINT = {
39
- cachePoint: { type: 'default' },
40
- } as const;
38
+ /**
39
+ * Cache TTL options for Bedrock prompt caching.
40
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html
41
+ *
42
+ * - '5m': 5-minute TTL (default, supported by all models)
43
+ * - '1h': 1-hour TTL (supported by Claude Opus 4.5, Claude Haiku 4.5, Claude Sonnet 4.5)
44
+ */
45
+ export type BedrockCacheTTL = '5m' | '1h';
46
+
47
+ export type BedrockCachePoint = {
48
+ cachePoint: { type: 'default'; ttl?: BedrockCacheTTL };
49
+ };
50
+
51
+ /**
52
+ * Creates a cache point with an optional TTL.
53
+ * @param ttl - Cache TTL ('5m' or '1h'). If not provided, uses the default 5-minute TTL.
54
+ */
55
+ export function createBedrockCachePoint(
56
+ ttl?: BedrockCacheTTL,
57
+ ): BedrockCachePoint {
58
+ return {
59
+ cachePoint: { type: 'default', ttl },
60
+ };
61
+ }
41
62
 
42
- export type BedrockCachePoint = { cachePoint: { type: 'default' } };
43
63
  export type BedrockSystemContentBlock = { text: string } | BedrockCachePoint;
44
64
 
45
65
  export interface BedrockGuardrailConfiguration {
@@ -7,7 +7,6 @@ import {
7
7
  } from '@ai-sdk/provider';
8
8
  import { convertToBase64, parseProviderOptions } from '@ai-sdk/provider-utils';
9
9
  import {
10
- BEDROCK_CACHE_POINT,
11
10
  BEDROCK_DOCUMENT_MIME_TYPES,
12
11
  BEDROCK_IMAGE_MIME_TYPES,
13
12
  BedrockAssistantMessage,
@@ -27,7 +26,15 @@ import { normalizeToolCallId } from './normalize-tool-call-id';
27
26
  function getCachePoint(
28
27
  providerMetadata: SharedV3ProviderMetadata | undefined,
29
28
  ): BedrockCachePoint | undefined {
30
- return providerMetadata?.bedrock?.cachePoint as BedrockCachePoint | undefined;
29
+ const cachePointConfig = providerMetadata?.bedrock?.cachePoint as
30
+ | BedrockCachePoint['cachePoint']
31
+ | undefined;
32
+
33
+ if (!cachePointConfig) {
34
+ return undefined;
35
+ }
36
+
37
+ return { cachePoint: cachePointConfig };
31
38
  }
32
39
 
33
40
  async function shouldEnableCitations(
@@ -73,8 +80,9 @@ export async function convertToBedrockChatMessages(
73
80
 
74
81
  for (const message of block.messages) {
75
82
  system.push({ text: message.content });
76
- if (getCachePoint(message.providerOptions)) {
77
- system.push(BEDROCK_CACHE_POINT);
83
+ const cachePoint = getCachePoint(message.providerOptions);
84
+ if (cachePoint) {
85
+ system.push(cachePoint);
78
86
  }
79
87
  }
80
88
  break;
@@ -220,8 +228,9 @@ export async function convertToBedrockChatMessages(
220
228
  }
221
229
  }
222
230
 
223
- if (getCachePoint(providerOptions)) {
224
- bedrockContent.push(BEDROCK_CACHE_POINT);
231
+ const cachePoint = getCachePoint(providerOptions);
232
+ if (cachePoint) {
233
+ bedrockContent.push(cachePoint);
225
234
  }
226
235
  }
227
236
 
@@ -316,8 +325,9 @@ export async function convertToBedrockChatMessages(
316
325
  }
317
326
  }
318
327
  }
319
- if (getCachePoint(message.providerOptions)) {
320
- bedrockContent.push(BEDROCK_CACHE_POINT);
328
+ const cachePoint = getCachePoint(message.providerOptions);
329
+ if (cachePoint) {
330
+ bedrockContent.push(cachePoint);
321
331
  }
322
332
  }
323
333