Repository navigation
fix(proxy): stop shipping the literal string "None" as error type and param #39536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mateo-berri
merged 7 commits into
litellm_internal_staging
from
litellm_openai_error_payload_non_llm_routes
Sep 8, 2026
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bede8b5
fix(proxy): stop shipping the literal string "None" as error type and…
mateo-berri 7a5b8bc
test(proxy): type the parametrized inputs of the error payload helper…
mateo-berri 57fd8f6
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
mateo-berri edde951
test(proxy): cover every /v1/files route error type and param
mateo-berri 8b89c90
fix(proxy): keep a ProxyException's status and label 408s in the Open…
mateo-berri 720f2ca
fix(proxy): label a 408 invalid_request_error again and pin the in-ro…
mateo-berri b3bcd71
test(proxy): type the realtime WebRTC fixtures with Protocols instead…
mateo-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Shapes the ``error`` object the proxy answers with so it matches OpenAI's contract: | ||
| ``type`` is a required string and ``param`` is nullable, neither of which the literal | ||
| string ``"None"`` satisfies.""" | ||
|
|
||
| from collections.abc import Mapping | ||
| from types import MappingProxyType | ||
| from typing import Final | ||
|
|
||
| from fastapi import status | ||
|
|
||
| _OPENAI_ERROR_TYPE_BY_STATUS: Final[Mapping[int, str]] = MappingProxyType( | ||
| { | ||
| status.HTTP_401_UNAUTHORIZED: "authentication_error", | ||
| status.HTTP_403_FORBIDDEN: "permission_error", | ||
| status.HTTP_429_TOO_MANY_REQUESTS: "rate_limit_error", | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def attribute_of(value: object, name: str, default: object = None) -> object: | ||
| return getattr(value, name, default) | ||
|
|
||
|
|
||
| def error_status_code(exc: object, default: int) -> int: | ||
| """The HTTP status an exception carries, or ``default`` when it carries none.""" | ||
| carried: Final = attribute_of(exc, "status_code") | ||
| return carried if isinstance(carried, int) and not isinstance(carried, bool) else default | ||
|
|
||
|
|
||
| def openai_error_type(exc: object, status_code: int) -> str: | ||
| """OpenAI types ``error.type`` as a required string, so an exception carrying none | ||
| falls back to the type its status code stands for.""" | ||
| carried: Final = attribute_of(exc, "type") | ||
| if isinstance(carried, str): | ||
| return carried | ||
| mapped: Final = _OPENAI_ERROR_TYPE_BY_STATUS.get(status_code) | ||
| if mapped is not None: | ||
| return mapped | ||
| if status_code < status.HTTP_500_INTERNAL_SERVER_ERROR: | ||
| return "invalid_request_error" | ||
| return "internal_server_error" | ||
|
|
||
|
|
||
| def openai_error_param(exc: object) -> str | None: | ||
| """OpenAI types ``error.param`` as nullable, so an exception carrying none | ||
| serializes as JSON ``null``.""" | ||
| carried: Final = attribute_of(exc, "param") | ||
| return carried if isinstance(carried, str) else None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.