Skip to content

Conversation

@qrush
Copy link

@qrush qrush commented Feb 2, 2026

Summary

  • Add BedrockConverse::Content helper class for building content with cache points
  • Extract cache metrics from responses (cacheReadInputTokenCount, cacheWriteInputTokenCount)
  • Preserve Raw content with cachePoint blocks in system messages

Bedrock Converse Caching Format

{
  "system": [
    { "text": "System instructions" },
    { "cachePoint": { "type": "default", "ttl": "5m" } }
  ]
}

Usage

# Cache system instructions
system = RubyLLM::Providers::BedrockConverse::Content.new(
  "You are a helpful assistant",
  ttl: '1h'
)

chat = RubyLLM.chat(model: 'anthropic.claude-3-5-haiku-20241022-v1:0', provider: :bedrock_converse)
chat.with_instructions(system)

response = chat.ask("Hello")
puts response.cached_tokens          # Tokens read from cache
puts response.cache_creation_tokens  # Tokens written to cache

Test plan

  • Add specs for BedrockConverse::Content helper
  • Update specs for cache token extraction in streaming
  • Add specs for cache metrics in sync response parsing
  • Add specs for cachePoint preservation in system content

🤖 Generated with Claude Code

qrush and others added 3 commits February 2, 2026 11:23
Implement prompt caching using Bedrock's cachePoint blocks:
- Add Content helper class for building content with cache points
- Extract cache metrics (cacheReadInputTokenCount, cacheWriteInputTokenCount)
- Preserve Raw content with cachePoint blocks in system messages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The BedrockConverse provider's slug is 'bedrockconverse' (no underscore),
so the check for allowing raw model IDs needs to include this variant.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The provider is registered as :bedrock_converse but the slug is bedrockconverse.
When looking up the provider by slug, we need to normalize the key.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants