Skip to content

[Feat] Add support for cache_control_injection_points for Anthropic API, Bedrock API - #9996

Merged
ishaan-jaff merged 8 commits into
mainfrom
litellm_cache_control_hook
Apr 15, 2025
Merged

[Feat] Add support for cache_control_injection_points for Anthropic API, Bedrock API#9996
ishaan-jaff merged 8 commits into
mainfrom
litellm_cache_control_hook

Conversation

@ishaan-jaff

@ishaan-jaff ishaan-jaff commented Apr 15, 2025

Copy link
Copy Markdown
Contributor

[Feat] Add support for cache_control_injection_points for Anthropic API, Bedrock API

Usage with litellm python SDK

response = await litellm.acompletion(
            model="bedrock/anthropic.claude-3-5-haiku-20241022-v1:0",
            messages=[
                {
                    "role": "assistant",
                    "content": [
                        {
                            "type": "text",
                            "text": "You are an AI assistant tasked with analyzing legal documents.",
                        },
                    ],
                },
                {
                    "role": "user",
                    "content": "what are the key terms and conditions in this agreement? <very_long_text>",
                },
            ],
            cache_control_injection_points=[
                {
                    "location": "message",
                    "role": "user",
                },
            ],
        )

Spec for cache_control_injection_points

Field Type Description
location Literal["message"] Type for message-level injection points
role Optional[Literal["user", "system", "assistant"]] Optional: target by role (user, system, assistant)
index Optional[int] Optional: target by specific index
control Optional[ChatCompletionCachedContent] Content to inject

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on (make test-unit)[https://docs.litellm.ai/docs/extras/contributing_code]
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

@vercel

vercel Bot commented Apr 15, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2025 0:53am

@ishaan-jaff
ishaan-jaff merged commit 6cfa50d into main Apr 15, 2025
@ishaan-berri
ishaan-berri deleted the litellm_cache_control_hook branch March 26, 2026 21:51
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
… API, Bedrock API (BerriAI#9996)

* test_anthropic_cache_control_hook_system_message

* test_anthropic_cache_control_hook.py

* should_run_prompt_management_hooks

* fix should_run_prompt_management_hooks

* test_anthropic_cache_control_hook_specific_index

* fix test

* fix linting errors

* ChatCompletionCachedContent
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.

1 participant