fix(proxy): type upstream timeouts as timeout_error and update integration asserts for the null param

A 408 with no carried type now answers timeout_error instead of invalid_request_error, so a client branching on type keeps retrying it. Three integration suites still compared auth rejections against param="None".
This commit is contained in:
mateo-berri 2026-10-28 20:12:18 -07:00
parent 2e24f3d060
commit 32470e4aa3
5 changed files with 19 additions and 8 deletions

View file

@ -17,6 +17,7 @@ _OPENAI_ERROR_TYPE_BY_STATUS: Final[Mapping[int, str]] = MappingProxyType(
{
status.HTTP_401_UNAUTHORIZED: "authentication_error",
status.HTTP_403_FORBIDDEN: "permission_error",
status.HTTP_408_REQUEST_TIMEOUT: "timeout_error",
status.HTTP_429_TOO_MANY_REQUESTS: "rate_limit_error",
}
)

View file

@ -310,7 +310,7 @@ def test_non_admin_keys_scoped_to_the_submission_routes_get_403_from_the_admin_c
f"Your user_id={_mask_user_id(user_id)}"
),
type="auth_error",
param="None",
param=None,
code="401",
)
)

View file

@ -114,7 +114,7 @@ class _ChatRequest(BaseModel):
class _ProxyError(BaseModel):
message: str
type: str
param: str
param: str | None
code: str
@ -398,7 +398,7 @@ def _assert_unmapped(response: httpx.Response, client_id: str) -> None:
assert response.status_code == 403, response.text
error: Final = _ErrorResponse.model_validate_json(response.content)
expected: Final = f"JWT Key Mapping: No registered mapping for {_CLIENT_CLAIM}='{client_id}'. Access denied."
assert error.error == _ProxyError(message=expected, type="auth_error", param="None", code="403"), response.text
assert error.error == _ProxyError(message=expected, type="auth_error", param=None, code="403"), response.text
def _mapping_info(gateway: Gateway, identity: str) -> _JWTMappingResponse:

View file

@ -40,7 +40,7 @@ class _ProxyError(BaseModel):
message: str
type: str
param: str
param: str | None
code: str
@ -260,12 +260,12 @@ def _control_error(response: httpx.Response) -> _ProxyError:
def test_requests_without_an_sk_key_keep_their_own_401(gateway: Gateway, peer: Gateway, side: Side) -> None:
client: Final = _side(gateway, peer, side).client
assert _control_error(client.get("/v1/models")) == _ProxyError(
message="Authentication Error, No api key passed in.", type="auth_error", param="None", code="401"
message="Authentication Error, No api key passed in.", type="auth_error", param=None, code="401"
)
assert _control_error(client.get("/v1/models", headers={"Authorization": "Bearer not-a-real-key"})) == _ProxyError(
message="LiteLLM Virtual Key expected. Received=not-****-key, expected to start with 'sk-'.",
type="auth_error",
param="None",
param=None,
code="401",
)
@ -277,7 +277,7 @@ def test_a_blocked_key_keeps_its_own_401_on_both_proxies(gateway: Gateway, peer:
expected: Final = _ProxyError(
message="Authentication Error, Key is blocked. Update via `/key/unblock` if you're an admin.",
type="auth_error",
param="None",
param=None,
code="401",
)
for candidate in (gateway, peer):

View file

@ -20,7 +20,7 @@ from litellm.proxy.common_utils.openai_error_payload import (
(401, "authentication_error"),
(403, "permission_error"),
(404, "invalid_request_error"),
(408, "invalid_request_error"),
(408, "timeout_error"),
(422, "invalid_request_error"),
(429, "rate_limit_error"),
(499, "invalid_request_error"),
@ -161,6 +161,16 @@ def test_an_upstream_5xx_body_does_not_relabel_the_internal_server_error():
assert openai_error_type(carried, error_status_code(carried, 400)) == "internal_server_error"
def test_an_upstream_timeout_is_not_typed_as_the_clients_mistake():
"""A provider timeout carries status 408 and no type, and calling it an
invalid_request_error tells a client branching on type not to retry a request that can succeed."""
from litellm.exceptions import Timeout
timeout = Timeout(message="Request timed out", model="gpt-5.4-mini", llm_provider="openai")
assert openai_error_type(timeout, error_status_code(timeout, 500)) == "timeout_error"
def test_a_stringified_none_type_or_param_is_treated_as_absent():
from litellm.exceptions import BadRequestError