Skip to content

Conversation

@Chesars
Copy link
Contributor

@Chesars Chesars commented Dec 3, 2025

Title

fix(anthropic): accept dict format for reasoning_effort parameter

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

SDKs like openai-agents-python pass reasoning_effort as a dict containing both effort and summary fields:

reasoning_effort = {"effort": "medium", "summary": "auto"}

The OpenAI Responses API handler already supports this dict format, but the Anthropic provider only accepted string format, causing the parameter to be silently ignored.

What was changed

File: litellm/llms/anthropic/chat/transformation.py

Updated the reasoning_effort handling to accept both formats:

  • String: "medium" → works as before
  • Dict: {"effort": "medium", "summary": "auto"} → extracts effort, ignores summary (Anthropic doesn't support configurable summary)

Tests added

6 new unit tests in tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py:

  • test_reasoning_effort_string_format_opus_45
  • test_reasoning_effort_dict_format_opus_45
  • test_reasoning_effort_dict_format_other_models
  • test_reasoning_effort_string_format_other_models
  • test_reasoning_effort_dict_without_effort_key
  • test_reasoning_effort_dict_with_none_effort

Backward compatibility

This is fully backward compatible - existing string format behavior is unchanged.

SDKs like openai-agents-python pass reasoning_effort as a dict:
{"effort": "medium", "summary": "auto"}

The Anthropic provider now extracts the "effort" key from dict format,
ignoring "summary" (Anthropic doesn't support configurable summary).

This is backward compatible - string format still works.
@vercel
Copy link

vercel bot commented Dec 3, 2025

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

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Dec 3, 2025 10:23pm

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