From e25239570c841163bc6038d6b8758edb27b68628 Mon Sep 17 00:00:00 2001 From: Tony Rogers Date: Tue, 1 Sep 2026 17:27:11 -0400 Subject: [PATCH] fix(bedrock): fold cache tokens into non-streaming converse usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The non-streaming Converse conversion copied inputTokens raw, dropping cacheReadInputTokens / cacheWriteInputTokens even though the internal TokenUsage parses them — AWS defines inputTokens as exclusive of cached tokens, so prompt usage was understated whenever caching was active. Fold them in, matching the streaming path. --- .../src/types/assistant_content.rs | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/rig-integrations/rig-bedrock/src/types/assistant_content.rs b/rig-integrations/rig-bedrock/src/types/assistant_content.rs index d4a2e8e8cd..9521ec21b9 100644 --- a/rig-integrations/rig-bedrock/src/types/assistant_content.rs +++ b/rig-integrations/rig-bedrock/src/types/assistant_content.rs @@ -42,11 +42,16 @@ impl TryFrom for completion::CompletionResponse = + AwsConverseOutput(internal).try_into().unwrap(); + assert_eq!( + completion.usage.input_tokens, 20_100, + "cache tokens fold into input" + ); + assert_eq!(completion.usage.total_tokens, 20_150); + } + #[test] fn aws_content_block_to_assistant_content() { let content_block = aws_bedrock::ContentBlock::Text("text".into());