Skip to content

Conversation

@Sameerlite
Copy link
Collaborator

@Sameerlite Sameerlite commented Nov 12, 2025

Title

Add Anthropic context_management support for chat completions and /v1/messages

Relevant issues

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit (ran pytest litellm/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py litellm/tests/test_litellm/responses/test_responses_utils.py)
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
📖 Documentation
✅ Test

Changes

  • Enable context_management for Anthropic chat completions: parameter is now accepted, forwarded unchanged, and auto-adds the required context-management-2025-06-27 beta header.
  • Preserve context_management for Anthropic /v1/messages; LiteLLM adds the beta flag while letting the native payload passthrough.
  • Extend logging/tests and provider docs to cover the new beta parameter support.
image

@vercel
Copy link

vercel bot commented Nov 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Error Error Nov 15, 2025 8:10pm

@Sameerlite Sameerlite marked this pull request as ready for review November 12, 2025 17:07
"response_format",
"user",
"web_search_options",
"context_management",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not an openai param

Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nits on this

headers[
"anthropic-beta"
] = ANTHROPIC_BETA_HEADER_VALUES.CONTEXT_MANAGEMENT_2025_06_27.value
if optional_params.get("context_management") is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a helper method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ishaan-jaff ishaan-jaff merged commit 59d17cc into main Nov 15, 2025
51 of 55 checks passed
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.

3 participants