Skip to content

Commit 7a06eac

Browse files
committed
feat(bedrock): emit the opt-in cache TTL only for 1h-capable Converse models
What: - Add `promptCacheTtlSupport: ["5m", "1h"]` to the 13 Bedrock catalog rows whose AWS "Supported TTL" table entry lists 1h. The remaining rows stay absent, which is the fail-closed default. - Thread one resolved TTL through `CacheStrategyConfig.cacheTtl` into `CacheStrategy.createCachePoint`, and make that factory public so the provider's message-level emitter reuses it instead of building its own literal. - Resolve the TTL once in `createMessage` via the shared `resolveCacheTtl` helper and pass it to `convertToBedrockConverseMessages`, so both cache-point emitters (system/message blocks from the strategy, and the `messages[i].content` literal that used to hardcode `{ cachePoint: { type: "default" } }`) carry the same value. - Read the 1h share of `usage.cacheDetails` on the Converse stream and report it as `cacheWrite1hTokens`, clamped to the reported aggregate. Why: ADR-0006 PR-C7, the last request-side step of the TTL program. C5a (#2260) made a 1h cache write bill at 2x instead of the 5m rate and C5b (#2264) added the knob plus the capability field, but no Bedrock request could carry a TTL, so the knob was inert on the one provider that hard-fails on a wrong one. Impact: No behavior change by default: an unset or "5m" knob resolves to `undefined` and every cache point stays the byte-identical `{ type: "default" }`. A 1h request is emitted only when the resolved base model id is exactly listed, so a custom ARN, an inference profile naming an unlisted model, or any Nova row keeps today's bytes. Bedrock rejects an explicit ttl for a 5m-only model with a ValidationException that kills the turn, so the gate is capability-based and never error-driven: no catch-400-retry path exists. One TTL per request also makes the AWS "longer-before-shorter across tools -> system -> messages" ordering hazard unrepresentable rather than merely avoided. Cache-point placement is untouched.
1 parent 65ac862 commit 7a06eac

6 files changed

Lines changed: 691 additions & 7 deletions

File tree

‎packages/types/src/providers/bedrock.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ export const bedrockDefaultPromptRouterModelId: BedrockModelId = "anthropic.clau
1212
// https://aws.amazon.com/bedrock/pricing, including older models that are part
1313
// of the default prompt routers AWS enabled for GA of the promot router
1414
// feature.
15+
//
16+
// `promptCacheTtlSupport` marks the models whose Converse cache points accept an
17+
// explicit `ttl` (ADR-0006 PR-C7). The 1h boundary is not a version rule: Opus 4.1
18+
// and Opus 4 are 5m-only while Opus 4.6/4.7/4.8 are 1h-capable, so the flag is set
19+
// per exact model id from the AWS "Supported TTL" table and never inferred from a
20+
// pattern. Rows without it are 5m-only, which makes Bedrock reject an explicit ttl
21+
// (ValidationException), so absence must stay the fail-closed default.
22+
// https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html
1523
export const bedrockModels = {
1624
"anthropic.claude-sonnet-4-5-20250929-v1:0": {
1725
maxTokens: 64_000,
1826
contextWindow: 200_000,
1927
supportsImages: true,
2028
supportsPromptCache: true,
29+
promptCacheTtlSupport: ["5m", "1h"],
2130
supportsReasoningBudget: true,
2231
inputPrice: 3.0,
2332
outputPrice: 15.0,
@@ -33,6 +42,7 @@ export const bedrockModels = {
3342
contextWindow: 200_000, // Default 200K, extendable to 1M with beta flag 'context-1m-2025-08-07'
3443
supportsImages: true,
3544
supportsPromptCache: true,
45+
promptCacheTtlSupport: ["5m", "1h"],
3646
supportsReasoningBudget: true,
3747
inputPrice: 3.0, // $3 per million input tokens (≤200K context)
3848
outputPrice: 15.0, // $15 per million output tokens (≤200K context)
@@ -60,6 +70,7 @@ export const bedrockModels = {
6070
contextWindow: 1_000_000, // 1M context window native (no beta header required)
6171
supportsImages: true,
6272
supportsPromptCache: true,
73+
promptCacheTtlSupport: ["5m", "1h"],
6374
supportsReasoningBudget: true,
6475
supportsReasoningBinary: true,
6576
supportsTemperature: false,
@@ -173,6 +184,7 @@ export const bedrockModels = {
173184
contextWindow: 200_000, // Default 200K, extendable to 1M with beta flag 'context-1m-2025-08-07'
174185
supportsImages: true,
175186
supportsPromptCache: true,
187+
promptCacheTtlSupport: ["5m", "1h"],
176188
supportsReasoningBudget: true,
177189
inputPrice: 5.0, // $5 per million input tokens (≤200K context)
178190
outputPrice: 25.0, // $25 per million output tokens (≤200K context)
@@ -199,6 +211,7 @@ export const bedrockModels = {
199211
contextWindow: 200_000, // Default 200K, extendable to 1M with beta flag 'context-1m-2025-08-07'
200212
supportsImages: true,
201213
supportsPromptCache: true,
214+
promptCacheTtlSupport: ["5m", "1h"],
202215
supportsReasoningBudget: true,
203216
inputPrice: 5.0, // $5 per million input tokens (≤200K context) — verify against Bedrock console
204217
outputPrice: 25.0, // $25 per million output tokens (≤200K context) — verify against Bedrock console
@@ -225,6 +238,7 @@ export const bedrockModels = {
225238
contextWindow: 200_000, // Default 200K, extendable to 1M with beta flag 'context-1m-2025-08-07'
226239
supportsImages: true,
227240
supportsPromptCache: true,
241+
promptCacheTtlSupport: ["5m", "1h"],
228242
supportsReasoningBudget: true,
229243
inputPrice: 5.0, // $5 per million input tokens (≤200K context) — verify against Bedrock console
230244
outputPrice: 25.0, // $25 per million output tokens (≤200K context) — verify against Bedrock console
@@ -254,6 +268,7 @@ export const bedrockModels = {
254268
contextWindow: 1_000_000, // 1M context window native (no beta header required)
255269
supportsImages: true,
256270
supportsPromptCache: true,
271+
promptCacheTtlSupport: ["5m", "1h"],
257272
supportsReasoningBudget: true,
258273
supportsReasoningBinary: true,
259274
supportsTemperature: false,
@@ -275,6 +290,7 @@ export const bedrockModels = {
275290
contextWindow: 1_000_000, // 1M context window native (no beta header required)
276291
supportsImages: true,
277292
supportsPromptCache: true,
293+
promptCacheTtlSupport: ["5m", "1h"],
278294
supportsReasoningBudget: true,
279295
supportsReasoningBinary: true,
280296
supportsTemperature: false,
@@ -300,6 +316,7 @@ export const bedrockModels = {
300316
contextWindow: 1_000_000, // 1M context window native (no beta header required)
301317
supportsImages: true,
302318
supportsPromptCache: true,
319+
promptCacheTtlSupport: ["5m", "1h"],
303320
supportsReasoningBudget: true,
304321
supportsReasoningBinary: true,
305322
supportsTemperature: false,
@@ -326,6 +343,7 @@ export const bedrockModels = {
326343
contextWindow: 1_000_000,
327344
supportsImages: true,
328345
supportsPromptCache: true,
346+
promptCacheTtlSupport: ["5m", "1h"],
329347
supportsReasoningBudget: true,
330348
supportsReasoningBinary: true,
331349
supportsTemperature: false,
@@ -345,6 +363,7 @@ export const bedrockModels = {
345363
contextWindow: 1_000_000,
346364
supportsImages: true,
347365
supportsPromptCache: true,
366+
promptCacheTtlSupport: ["5m", "1h"],
348367
supportsReasoningBudget: true,
349368
supportsReasoningBinary: true,
350369
supportsTemperature: false,
@@ -364,6 +383,7 @@ export const bedrockModels = {
364383
contextWindow: 200_000,
365384
supportsImages: true,
366385
supportsPromptCache: true,
386+
promptCacheTtlSupport: ["5m", "1h"],
367387
supportsReasoningBudget: true,
368388
inputPrice: 5.0,
369389
outputPrice: 25.0,
@@ -437,6 +457,7 @@ export const bedrockModels = {
437457
contextWindow: 200_000,
438458
supportsImages: true,
439459
supportsPromptCache: true,
460+
promptCacheTtlSupport: ["5m", "1h"],
440461
supportsReasoningBudget: true,
441462
inputPrice: 1.0,
442463
outputPrice: 5.0,

0 commit comments

Comments
 (0)