feat: support bedrock prompt caching #1059
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Author Description
Description
🔄 What Changed
This PR adds support for prompt caching in Bedrock models by refactoring the existing Anthropic caching mechanism to be more generic and implementing cache point markers and token usage tracking for Bedrock providers.
🔍 Impact of the Change
Enables prompt caching for Bedrock models which can improve performance and reduce token usage costs by allowing specific parts of prompts to be cached and tracking cache read/write token usage.
📁 Total Files Changed
3 files modified with 92 additions and 26 deletions:
🧪 Test Added
N/A - No tests were added in this PR.
🔒 Security Vulnerabilities
N/A - No security vulnerabilities were introduced.
Motivation
To extend the existing caching mechanism to work with Bedrock providers, improving performance and reducing costs.
Type of Change
How Has This Been Tested?
Screenshots (if applicable)
N/A
Checklist
Related Issues
N/A
Quality Recommendations
Add unit tests to verify the caching functionality works as expected
Add documentation comments explaining the caching mechanism and how to use it
Add error handling for potential issues with cache point insertion
Consider adding a validation function to ensure cache_control is properly formatted
Sequence Diagram