fix(bedrock): count cacheWriteInputTokens in turn tokens and cost #478
All Vouch review confidence checks passed
Residual risk 0.39 = Change Risk (0.71) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.71 · 199 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.317
Sensitive Paths
sensitive_paths
0.071
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #478"
general
weight: 0.35
pcbeingused333
ChatBedrock()appends a Converse cache point by default foranthropic.andamazon.novamodels, butconverse_tokens()read onlyinputTokens,outputTokensandcacheReadInputTokens. ThecacheWriteInputTokensfield of the Converseusagewas dropped, so turns that wrote to the cache reported fewer input tokens, and a lower cost, than they used.ChatAnthropic()already folds cache creation into the input count (1.25x for the 5 minute cache, 2x forcache="1h").This change does the same for the Converse provider:
anthropic., with or without a cross-region prefix):inputTokens + cacheWriteInputTokens 1.25, or* 2whencache="1h".cacheWriteInputTokensfield counts as 0, as before.Tests (
tests/test_provider_bedrock_converse.py,TestResponseParsing) build Converse responses withcacheReadInputTokensandcacheWriteInputTokensand check the resulting(input, output, cached)tuple for a 5m Claude model, a 1h Claude model, a Nova model and a response without the field. Three of them fail onmain(the write tokens are ignored) and pass with the change. The bedrock and token test files pass locally; nothing was run against the real Bedrock API. A CHANGELOG entry is included.Open question: if you would rather only count the tokens and leave the per-model weighting out, the multiplier branch is a few lines and easy to drop.
This change was made with Claude Code.
🤖 Generated with Claude Code