litellm - 💡(How to fix) Fix [Bug]: is_thinking_enabled crashes with AttributeError when non_default_params["thinking"] is None [5 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Traceback appears to be the default code path through map_openai_params). The error surfaces to the client as litellm.APIConnectionError: 'NoneType' object has no attribute 'get', with no

Root Cause

Send an OpenAI-compatible request from any client that doesn't include a thinking field — same payload shape as the OpenAI Python SDK or any plain requests-based caller. In our environment the trigger reliably fires on requests with multiple tool definitions and ~30KB of context, but the root cause is the None value, not the request shape.

Fix Action

Fixed

RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Bug description

When routing an OpenAI-compatible request to an Anthropic-backed model via the proxy, AnthropicConfig.map_openai_params calls update_optional_params_with_thinking_tokens, which in turn calls is_thinking_enabled. If optional_params contains the key "thinking" with an explicit None value (rather than the key being absent), the chained .get() call throws.

Affected version

LiteLLM v1.82.6 (Docker, ghcr.io/berriai/litellm:main-latest pulled today), Python 3.13.

Failing code

litellm/llms/base_llm/chat/transformation.py:114

def is_thinking_enabled(self, non_default_params): return non_default_params.get("thinking", {}).get("type") == "enabled"

The default {} in .get("thinking", {}) only kicks in when the key is missing. If the key exists and equals None, .get("thinking", {}) returns None, and the next .get("type") raises AttributeError.

Traceback

File ".../litellm/main.py", line 1516, in completion optional_params = get_optional_params(...) File ".../litellm/utils.py", line 4052, in get_optional_params optional_params = litellm.AnthropicConfig().map_openai_params(...) File ".../litellm/llms/anthropic/chat/transformation.py", line 1080, in map_openai_params self.update_optional_params_with_thinking_tokens( File ".../litellm/llms/base_llm/chat/transformation.py", line 137, in update_optional_params_with_thinking_tokens is_thinking_enabled = self.is_thinking_enabled(optional_params) File ".../litellm/llms/base_llm/chat/transformation.py", line 114, in is_thinking_enabled non_default_params.get("thinking", {}).get("type") == "enabled" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'get'

Reproduction

Configure LiteLLM with an alias mapping to an Anthropic Claude model:

model_list: - model_name: cloud-deep litellm_params: model: anthropic/claude-sonnet-4-5 api_key: os.environ/ANTHROPIC_API_KEY

Send an OpenAI-compatible request from any client that doesn't include a thinking field — same payload shape as the OpenAI Python SDK or any plain requests-based caller. In our environment the trigger reliably fires on requests with multiple tool definitions and ~30KB of context, but the root cause is the None value, not the request shape.

We also observed the same crash on the fallback path (alias's fallback chain leading to an Anthropic-backed group), confirming this is upstream of the request-shape variations.

Proposed fix

One-line guard on both potentially-None values:

def is_thinking_enabled(self, non_default_params): return ((non_default_params or {}).get("thinking") or {}).get("type") == "enabled"

Or, more readable:

def is_thinking_enabled(self, non_default_params): if not non_default_params: return False thinking = non_default_params.get("thinking") if not isinstance(thinking, dict): return False return thinking.get("type") == "enabled"

The latter also defends against thinking being any other non-dict value, which a future upstream change could introduce.

Impact

Any LiteLLM deployment proxying Anthropic models via the OpenAI-compatible endpoint will hit a hard 400 on the proxy whenever the LiteLLM internal pipeline sets thinking=None (which appears to be the default code path through map_openai_params). The error surfaces to the client as litellm.APIConnectionError: 'NoneType' object has no attribute 'get', with no actionable hint that the cause is internal.

Steps to Reproduce

Relevant log output

What part of LiteLLM is this about?

No response

What LiteLLM version are you on ?

v1.82.6

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: is_thinking_enabled crashes with AttributeError when non_default_params["thinking"] is None [5 pull requests]