Skip to content

fix(responses): propagate chat bridge stream errors - #39207

Open
PriyanJindal wants to merge 1 commit into
BerriAI:mainfrom
PriyanJindal:fix/responses-chat-stream-terminal-events
Open

PriyanJindal wants to merge 1 commit into
BerriAI:mainfrom
PriyanJindal:fix/responses-chat-stream-terminal-events

Conversation

@PriyanJindal

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Failed Responses streams became empty Chat Completion chunks
  • Refusal deltas were discarded by the bridge

How it solves it:

  • Raise LiteLLM errors for response.failed and error events
  • Map refusal deltas to the Chat Completions refusal field

User Flow

Before: a developer streams a Chat Completion through the Responses bridge and a provider-side failure looks like an empty successful response

  1. They send POST /v1/chat/completions with "stream": true to a model routed through the Responses API
  2. The provider emits response.failed or error after accepting the request
  3. Their client receives an empty stream chunk rather than the provider error

After: the same stream exposes the provider failure to the Chat Completions client

  1. They send the same POST /v1/chat/completions request
  2. The provider emits response.failed or error after accepting the request
  3. Their client receives a LiteLLM error with the provider message and mapped status code

A refusal stream now exposes its refusal text through delta.refusal

Relevant issues

Fixes #36768
Fixes #39203

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Not applicable. This handles provider-generated terminal SSE events that cannot be deterministically induced with a live request

Type

Bug Fix

Caveats (if any)

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@codspeed

codspeed Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing PriyanJindal:fix/responses-chat-stream-terminal-events (1656e7e) with litellm_internal_staging (9c417ba)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR propagates terminal Responses API stream errors through the Chat Completions bridge and preserves streamed refusal text.

  • Converts response.failed and error events into mapped LiteLLM errors.
  • Maps refusal deltas into the Chat Completions delta.refusal field without repeating the completed refusal.
  • Adds focused tests for error status mapping and refusal streaming.

Confidence Score: 4/5

The PR should not merge until retryable server-side stream failures preserve the Router’s configured mid-stream fallback behavior.

The new bridge correctly surfaces provider errors, but representing every terminal error as APIError prevents server-side failures from reaching the Router branch that performs stream fallback.

Files Needing Attention: litellm/completion_extras/litellm_responses_transformation/transformation.py

Important Files Changed

Filename Overview
litellm/completion_extras/litellm_responses_transformation/transformation.py Adds error and refusal event conversion, but server-side failures use APIError and therefore bypass configured mid-stream fallbacks.
tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py Adds focused regression coverage, though the error tests currently encode APIError for server failures rather than exercising Router fallback behavior.

Reviews (1): Last reviewed commit: "fix(responses): propagate chat bridge st..." | Re-trigger Greptile

Comment on lines +1380 to +1385
raise litellm.APIError(
status_code=_status_code_for_error_fields(error_type, error_code),
message=error_message,
llm_provider="openai",
model="responses",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Server errors bypass fallbacks

When a Responses-backed stream emits a server-side failure and the Router has a fallback configured, this code raises APIError while the streaming fallback wrapper catches only MidStreamFallbackError, causing the request to terminate instead of using the configured fallback.

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...litellm_responses_transformation/transformation.py 91.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ben7am1n

ben7am1n commented Sep 2, 2026

Copy link
Copy Markdown

Codecov still reports one changed line without coverage in the Responses transformation; please add a focused assertion before maintainer review.

@mateo-berri

Copy link
Copy Markdown
Contributor

#46438 now keeps OpenAI's code and message on stream error events. Could you narrow this PR to its refusal delta change?

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants