Skip to content

fix(openai): preserve streaming service tier - #38294

Closed
daleselaji-dev wants to merge 1 commit into
BerriAI:mainfrom
daleselaji-dev:codex/streaming-service-tier-38247
Closed

daleselaji-dev wants to merge 1 commit into
BerriAI:mainfrom
daleselaji-dev:codex/streaming-service-tier-38247

Conversation

@daleselaji-dev

Copy link
Copy Markdown
Contributor

Problem

OpenAI-compatible streaming responses can include a provider-served service_tier such as priority, but LiteLLM's OpenAIChatCompletionStreamingHandler.chunk_parser rebuilds each chunk from a fixed field set and drops that metadata. This prevents downstream hooks, assembled streaming responses, and billing diagnostics from verifying the tier actually served.

Root Cause

The parser copied id, object, created, model, choices, and optional usage, but never copied a non-null service_tier field from the raw provider chunk.

Solution

Preserve a non-null service_tier in the normalized ModelResponseStream, matching the existing optional usage pass-through pattern.

Changes

  • Add service_tier pass-through in OpenAIChatCompletionStreamingHandler.chunk_parser.
  • Add a mocked regression test for a priority-tier streaming chunk.
  • Remove one pre-existing extra blank line in the touched test import block so Ruff check is clean.

Testing

  • Latest-base baseline: tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py — 49 passed.
  • Final focused suite: same file — 50 passed.
  • .venv\Scripts\ruff.exe check on both changed files — passed.
  • .venv\Scripts\python.exe -m compileall on both changed files — passed.
  • git diff --check — passed.
  • ruff format --check was attempted; the Windows checkout has mixed CRLF/LF normalization and the formatter reports existing formatting differences in these files. The repository HEAD passed the formatter through normalized stdin; no unrelated format rewrite was included.
  • basedpyright was attempted; it reports 333 repository-existing diagnostics across the touched module/test and is not a clean typecheck signal for this two-line behavior change. No typecheck pass is claimed.
  • Full suite was not run; no live provider or external API was used.

Compatibility/Risk

Low-risk parser-only metadata preservation. Providers that do not send service_tier are unchanged. The field is optional and already supported by LiteLLM response models and downstream service-tier utilities.

Notes for Reviewer

The regression uses a mocked raw chunk and verifies the normalized response exposes priority. The existing xAI handler inherits this parser, so no provider-specific branch is needed. The fork may still require the repository CLA gate before merge.

Linked Issue

Fixes #38247

Repository Gates

  • Focused tests and mocked-only validation completed.
  • Issue, assignee, claim comments, matching open PRs, and latest staging base rechecked before commit.
  • CLA gate — external contributor gate may require maintainer action.
  • Full repository typecheck/format baseline — existing Windows/environment diagnostics recorded above.

@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing daleselaji-dev:codex/streaming-service-tier-38247 (13b77ea) with litellm_internal_staging (d16c4da)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (72b8b47) during the generation of this report, so d16c4da was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:45
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@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 sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:55
@mateo-berri

Copy link
Copy Markdown
Contributor

Main already keeps the served service_tier on streamed chunks since #42870 landed, so closing this. Please reopen if something is missing

@mateo-berri mateo-berri closed this Nov 9, 2026
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.

[Bug]: streaming chunk_parser drops service_tier, breaking priority-tier billing verification (xAI/OpenAI)

4 participants