Skip to content

Python: Bedrock connector drops cache token counts from usage details #6639

Description

@he-yufeng

Describe the bug

The Bedrock chat client only surfaces input, output, and total token counts in usage_details. When prompt caching is active, the Bedrock Converse API also reports cacheReadInputTokens (input tokens served from a cache) and cacheWriteInputTokens (input tokens written to a cache), but _parse_usage drops both. So cache usage silently reads as zero for cached prompts, which throws off cost and token accounting.

UsageDetails already defines canonical fields for these (cache_read_input_token_count, cache_creation_input_token_count), and the OpenAI and Anthropic connectors already populate them — Bedrock is the odd one out.

Where

python/packages/bedrock/agent_framework_bedrock/_chat_client.py, BedrockChatClient._parse_usage.

Expected behavior

When the Converse response includes cacheReadInputTokens / cacheWriteInputTokens, map them to cache_read_input_token_count / cache_creation_input_token_count in usage_details, matching the OpenAI and Anthropic connectors.

Metadata

Metadata

Assignees

Labels

pythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

No fields configured for Bug.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions