Skip to content

fix(streaming): map reasoning to reasoning_content in Delta for gpt-oss providers - #22803

Merged
Chesars merged 2 commits into
BerriAI:litellm_oss_staging_03_04_2026from
Chesars:fix/reasoning-to-reasoning-content-delta
Mar 4, 2026
Merged

fix(streaming): map reasoning to reasoning_content in Delta for gpt-oss providers#22803
Chesars merged 2 commits into
BerriAI:litellm_oss_staging_03_04_2026from
Chesars:fix/reasoning-to-reasoning-content-delta

Conversation

@Chesars

@Chesars Chesars commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #13300

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

Providers like Cerebras return delta.reasoning in streaming responses for gpt-oss models, but LiteLLM's Delta class expects reasoning_content. This causes reasoning content to be silently dropped during streaming.

The fix adds a 3-line mapping in Delta.__init__ that converts reasoningreasoning_content when reasoning_content is not already set. This is generic and works for any OpenAI-compatible provider that uses the reasoning field name.

Tested with:

  • Cerebras gpt-oss-120b (streaming + non-streaming)
  • Groq gpt-oss-20b (streaming + non-streaming)
  • NVIDIA NIM gpt-oss-20b (streaming + non-streaming)

Files changed:

  • litellm/types/utils.py: Map reasoning kwarg to reasoning_content in Delta.__init__
  • tests/test_litellm/types/test_types_utils.py: Add unit test for the mapping

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@vercel

vercel Bot commented Mar 4, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
litellm Error Error Mar 4, 2026 8:45pm

Request Review

@greptile-apps

greptile-apps Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where reasoning content was silently dropped during streaming for OpenAI-compatible providers (e.g., Cerebras, Groq gpt-oss models) that return delta.reasoning instead of delta.reasoning_content. The fix adds a 3-line field name mapping in Delta.__init__ that normalizes reasoningreasoning_content before the parent class is initialized.

  • litellm/types/utils.py: Added reasoningreasoning_content mapping in Delta.__init__, placed before super().__init__() to prevent field leakage
  • tests/test_litellm/types/test_types_utils.py: Added comprehensive unit test covering mapping, precedence, non-leakage, and no-reasoning scenarios
  • poetry.lock: Routine regeneration (Poetry 2.2.0 → 2.3.2), unrelated to the bug fix
  • Note: Some providers (Groq, OpenAI GPT streaming handler) already have their own reasoningreasoning_content mapping at the transformation layer. This Delta-level mapping acts as a generic safety net for providers that lack such mapping (e.g., Cerebras).

Confidence Score: 4/5

  • This PR is safe to merge — it adds a small, defensive field mapping with no backwards-incompatible behavior changes.
  • The change is minimal (3 lines of logic), well-tested, and follows existing patterns in the codebase. It only activates when reasoning_content is absent and reasoning is present, so it cannot break existing behavior. The mapping is placed before super().__init__() to prevent field leakage. One minor edge case remains: when both reasoning_content and reasoning are provided simultaneously, reasoning is still passed to the parent — but this is a theoretical edge case unlikely in practice.
  • No files require special attention — the core change in litellm/types/utils.py is clean and well-scoped.

Important Files Changed

Filename Overview
litellm/types/utils.py Added reasoningreasoning_content field mapping in Delta.__init__ before super().__init__(). Clean, minimal change that normalizes field names for gpt-oss providers.
tests/test_litellm/types/test_types_utils.py Added comprehensive unit test covering: basic mapping, direct reasoning_content, precedence when both present, non-leakage assertion, and absent-field case. No network calls — pure mock tests.
poetry.lock Routine regeneration from Poetry 2.2.0 to 2.3.2 with markers format changes. Unrelated to the bug fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Provider Streaming Response<br/>(e.g., Cerebras, Groq)"] -->|"delta.reasoning = '...'"| B["Delta.__init__(**kwargs)"]
    B --> C{"reasoning_content<br/>is None?"}
    C -->|"Yes"| D["Pop 'reasoning' from params<br/>Set reasoning_content = reasoning"]
    C -->|"No"| E["Keep existing<br/>reasoning_content"]
    D --> F["super().__init__(**params)<br/>(reasoning removed from params)"]
    E --> F
    F --> G{"reasoning_content<br/>is not None?"}
    G -->|"Yes"| H["self.reasoning_content = value"]
    G -->|"No"| I["del self.reasoning_content<br/>(OpenAI spec compliance)"]
Loading

Last reviewed commit: e48b7ae

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Chesars
❌ github-actions[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment thread litellm/types/utils.py Outdated
@Chesars
Chesars force-pushed the fix/reasoning-to-reasoning-content-delta branch from b6bd95b to c673752 Compare March 4, 2026 20:32
@Chesars

Chesars commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptile

Comment thread tests/test_litellm/types/test_types_utils.py
…ss providers

Providers like Cerebras return delta.reasoning in streaming responses
for gpt-oss models, but LiteLLM's Delta class expects reasoning_content.
This causes reasoning content to be silently dropped during streaming.

Fixes BerriAI#13300
@Chesars
Chesars force-pushed the fix/reasoning-to-reasoning-content-delta branch from c673752 to e48b7ae Compare March 4, 2026 20:44
@Chesars
Chesars changed the base branch from main to litellm_oss_staging_03_04_2026 March 4, 2026 20:54
@Chesars
Chesars merged commit 0c2e6b5 into BerriAI:litellm_oss_staging_03_04_2026 Mar 4, 2026
31 of 38 checks passed
@Chesars
Chesars deleted the fix/reasoning-to-reasoning-content-delta branch March 4, 2026 20:54
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…ing-content-delta

fix(streaming): map reasoning to reasoning_content in Delta for gpt-oss providers
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.

[Feature]: Support reasoning in harmony response format for gpt-oss models

2 participants