Skip to content

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

@he-yufeng

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

No one assigned

    Labels

    pythonIssues related to the Python codebasetriagePlaced on an issue or discussion that requires a maintainer to triage the item

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions