Skip to content

fix: preserve llm_provider-* headers in error responses - #19020

Merged
2 commits merged into
BerriAI:mainfrom
pgolm:fix/preserve-provider-headers-on-errors
Jan 14, 2026
Merged

2 commits merged into
BerriAI:mainfrom
pgolm:fix/preserve-provider-headers-on-errors

Conversation

@pgolm

@pgolm pgolm commented Jan 13, 2026 •

Copy link
Copy Markdown
Contributor

Preserves llm_provider-* headers in error responses returned to clients. Previously, when an LLM provider returned an error (e.g., BadRequestError), any useful debugging headers from the provider's response were lost.

Problem

When LiteLLM catches provider exceptions and re-raises them as typed exceptions (e.g., BadRequestError, ContentPolicyViolationError), the original response headers were being discarded. This meant clients couldn't access provider-specific debugging information that was included in error response headers.

Solution

  1. BadRequestError: Now preserves headers from the original response when constructing the httpx.Response object
  2. ContextWindowExceededError / ContentPolicyViolationError: Pass through the original response to the parent class instead of creating a mock response without headers
  3. Proxy error handling: Extract llm_provider-* prefixed headers from exception responses and include them in the error response returned to clients

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • 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

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🐛 Bug Fix

Changes

Extract and preserve provider-specific headers (llm_provider-*) when
handling error responses from LLM providers. This ensures that useful
debugging information from providers is available even when requests
fail with BadRequestError or similar exceptions.
@vercel

vercel Bot commented Jan 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Review Updated (UTC)
litellm Ready Ready Preview, Comment Jan 14, 2026 9:08am

@CLAassistant

CLAassistant commented Jan 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@pgolm

pgolm commented Jan 13, 2026

Copy link
Copy Markdown
Contributor Author

Failing tests are unrelated to these changes.

@ghost
ghost changed the base branch from main to litellm_staging_01_13_2026 January 13, 2026 22:04
@ghost
ghost changed the base branch from litellm_staging_01_13_2026 to main January 13, 2026 22:06
…-headers-on-errors

# Conflicts:
#	litellm/proxy/common_request_processing.py
@ghost
ghost changed the base branch from main to litellm_staging_01_14_2026 January 14, 2026 17:19
@ghost
ghost changed the base branch from litellm_staging_01_14_2026 to main January 14, 2026 17:19
@ghost
ghost merged commit c215b3a into BerriAI:main Jan 14, 2026
6 of 8 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
Extract and preserve provider-specific headers (llm_provider-*) when
handling error responses from LLM providers. This ensures that useful
debugging information from providers is available even when requests
fail with BadRequestError or similar exceptions.
This pull request was closed.

This branch was successfully deployed

1 active deployment
Preview — 22c27e28 Deployed Jan 14, 2026 by vercel[bot]
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.

2 participants