feat(bedrock): support cache_control_injection_points for tool_config location#24076
Conversation
… location
Add support for {"location": "tool_config"} in cache_control_injection_points,
which appends a cachePoint block to the Bedrock Converse toolConfig.tools array.
This enables prompt caching of tool definitions on Bedrock Claude models.
Also update the cache control hook to pass through non-message injection points
to provider-specific handling instead of silently dropping them.
Fixes BerriAI#21969
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds support for Key changes:
Architectural note: Because the hook now forwards any non- Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/types/integrations/anthropic_cache_control_hook.py | Adds CacheControlToolConfigInjectionPoint TypedDict for Bedrock tool_config caching and expands CacheControlInjectionPoint from a simple alias to a Union type. Clean and correct type definitions. |
| litellm/integrations/anthropic_cache_control_hook.py | Splits injection-point processing so that non-message points are written back into non_default_params for downstream provider-specific handling. Previously they were silently dropped. The forwarding-to-all-providers concern was flagged in a prior review thread. |
| litellm/llms/bedrock/chat/converse_transformation.py | Adds cache_control_injection_points handling in _transform_request_helper (shared by both sync and async paths). Correctly pops the key from additional_request_params before it can leak into additionalModelRequestFields, then appends {"cachePoint": {"type": "default"}} to bedrock_tools when a tool_config location is found. Unrecognised locations are silently discarded (flagged in a prior review thread). |
| tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py | Three new unit tests cover: (1) cachePoint appended when tool_config injection point is present, (2) no toolConfig when no tools are provided, and (3) no cachePoint when injection points don't include tool_config. All tests call _transform_request directly with no real network calls, consistent with the repo's mock-only rule for this folder. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["User calls litellm.completion() with\ncache_control_injection_points"] --> B["AnthropicCacheControlHook\nget_chat_completion_prompt"]
B --> C{For each injection point}
C -->|location == 'message'| D["_process_message_injection\nApply cache_control to messages"]
C -->|any other location| E["Add to remaining_points"]
D --> F{More points?}
F -->|yes| C
F -->|no| G{remaining_points\nnon-empty?}
E --> F
G -->|yes| H["Write remaining_points back\ninto non_default_params\n(cache_control_injection_points)"]
G -->|no| I["non_default_params unchanged"]
H --> J["AmazonConverseConfig\n_transform_request_helper"]
I --> J
J --> K["_prepare_request_params\ncache_control_injection_points →\nadditional_request_params"]
K --> L["Pop cache_control_injection_points\nfrom additional_request_params"]
L --> M{len bedrock_tools > 0\nAND cache_injection_points?}
M -->|yes| N{Any point with\nlocation == 'tool_config'?}
M -->|no| O["Discard injection points\n(no tools to cache)"]
N -->|yes| P["Append cachePoint block\nto bedrock_tools list\nbreak"]
N -->|no| Q["Silently discard\nunrecognised locations"]
P --> R["Build ToolConfigBlock\nwith cachePoint at end\nof tools array"]
R --> S["Bedrock Converse API request\nwith toolConfig.tools including cachePoint"]
O --> T["Bedrock Converse API request\nwithout toolConfig"]
Last reviewed commit: "fix(types): add Cach..."
a3095f4
into
BerriAI:litellm_oss_staging_03_19_2026
Relevant issues
Fixes #21969
Pre-Submission checklist
tests/test_litellm/directory, Adding at least 1 test is a hard requirementmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewType
🆕 New Feature
Changes
Add support for
{"location": "tool_config"}incache_control_injection_points, which appends acachePointblock to the Bedrock ConversetoolConfig.toolsarray. This enables prompt caching of tool definitions on Bedrock Claude models, reducing cost and latency for tool-heavy agentic workloads.Also update the cache control hook to pass through non-message injection points to provider-specific handling instead of silently dropping them.