@ai-sdk/amazon-bedrock 4.0.43 → 4.0.45
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 +14 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -11
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +15 -1
- package/package.json +3 -3
- package/src/bedrock-api-types.ts +24 -4
- package/src/convert-to-bedrock-chat-messages.ts +18 -8
|
@@ -348,7 +348,21 @@ console.log('Response:', result.object);
|
|
|
348
348
|
|
|
349
349
|
In messages, you can use the `providerOptions` property to set cache points. Set the `bedrock` property in the `providerOptions` object to `{ cachePoint: { type: 'default' } }` to create a cache point.
|
|
350
350
|
|
|
351
|
-
|
|
351
|
+
You can also specify a TTL (time-to-live) for cache points using the `ttl` property. Supported values are `'5m'` (5 minutes, default) and `'1h'` (1 hour). The 1-hour TTL is only supported by Claude Opus 4.5, Claude Haiku 4.5, and Claude Sonnet 4.5.
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
providerOptions: {
|
|
355
|
+
bedrock: { cachePoint: { type: 'default', ttl: '1h' } },
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
<Note>
|
|
360
|
+
When using multiple cache points with different TTLs, cache entries with
|
|
361
|
+
longer TTL must appear before shorter TTLs (i.e., 1-hour cache entries must
|
|
362
|
+
come before 5-minute cache entries).
|
|
363
|
+
</Note>
|
|
364
|
+
|
|
365
|
+
Cache usage information is returned in the `providerMetadata` object. See examples below.
|
|
352
366
|
|
|
353
367
|
<Note>
|
|
354
368
|
Cache points have model-specific token minimums and limits. For example,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.45",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@smithy/util-utf8": "^4.0.0",
|
|
40
40
|
"aws4fetch": "^1.0.20",
|
|
41
41
|
"@ai-sdk/provider": "3.0.6",
|
|
42
|
-
"@ai-sdk/
|
|
43
|
-
"@ai-sdk/
|
|
42
|
+
"@ai-sdk/anthropic": "3.0.34",
|
|
43
|
+
"@ai-sdk/provider-utils": "4.0.12"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "20.17.24",
|
package/src/bedrock-api-types.ts
CHANGED
|
@@ -35,11 +35,31 @@ export interface BedrockUserMessage {
|
|
|
35
35
|
content: Array<BedrockContentBlock>;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
224
|
-
|
|
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
|
-
|
|
320
|
-
|
|
328
|
+
const cachePoint = getCachePoint(message.providerOptions);
|
|
329
|
+
if (cachePoint) {
|
|
330
|
+
bedrockContent.push(cachePoint);
|
|
321
331
|
}
|
|
322
332
|
}
|
|
323
333
|
|