The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge pull request #41893 from BerriAI/litellm_fix_responses_ws_encrypted_content_affinity
Mateo Wangb46612cfeb0c
diff --cc litellm/proxy/response_api_endpoints/endpoints.pyindex 3202fabe74e,b07458bb5ed..3b6afc34063--- a/litellm/proxy/response_api_endpoints/endpoints.py+++ b/litellm/proxy/response_api_endpoints/endpoints.py@@@ -1,9 -1,9 +1,10 @@@import asyncio+ import contextlibimport jsonimport time- from collections.abc import AsyncIterator, Awaitable, Mapping+ from collections.abc import AsyncIterator, Awaitable, Mapping, Sequencefrom enum import Enum+from functools import partialfrom types import MappingProxyTypefrom typing import TYPE_CHECKING, Any, Final, NamedTuple, Protocol, cast, get_argsfrom uuid import uuid4diff --cc litellm/responses/streaming_iterator.pyindex 08f5ec236a7,122476a1be3..195214b077c--- a/litellm/responses/streaming_iterator.py+++ b/litellm/responses/streaming_iterator.py@@@ -226,9 -221,35 +227,32 @@@ def _status_code_for_error_fields(errorfields: Final = tuple(field for field in (error_code, error_type) if field is not None)if any(field.startswith("rate_limit") or field == "insufficient_quota" for field in fields):return 429- return next(- (_ERROR_CODE_HTTP_STATUS[field] for field in fields if field in _ERROR_CODE_HTTP_STATUS),- 500,- )+ return next((status for status in map(_status_code_for_error_field, fields) if status is not None), 500)+ def _map_stream_error_to_exception(error_obj: object, model: str, custom_llm_provider: str) -> Exception:+ from litellm.llms.base_llm.chat.transformation import BaseLLMException++ error_message, error_type, error_code = _error_event_fields(error_obj)+ status_code: Final = _status_code_for_error_fields(error_type, error_code)+ error_body: Final = {"message": error_message, "type": error_type, "code": error_code}+ provider_exception: Final = BaseLLMException(+ status_code=status_code,+ message=f"Error code: {status_code} - {{'error': {error_body}}}",+ body=error_body,+ )+ try:+ return litellm.exception_type(+ model=model,+ custom_llm_provider=custom_llm_provider,+ original_exception=provider_exception,+ completion_kwargs={},+ extra_kwargs={},+ )+ except Exception as mapped_exception:+ return mapped_exception++def _mid_stream_fallback_eligible(mapped_exception: Exception) -> bool:if isinstance(mapped_exception, litellm.ContentPolicyViolationError):return True