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
fix: remove over-strict stream logging validator, restore base seam behavior
mateo-berri262d1b4ca070
diff --git a/basedpyright-code-budget.json b/basedpyright-code-budget.jsonindex 14fdd3ed0bc..1b2563a59a4 100644--- a/basedpyright-code-budget.json+++ b/basedpyright-code-budget.json@@ -3,13 +3,13 @@"limit": 25153},"reportArgumentType": {- "limit": 2596+ "limit": 2597},"reportAssignmentType": {- "limit": 327+ "limit": 325},"reportAttributeAccessIssue": {- "limit": 510+ "limit": 501},"reportCallIssue": {"limit": 114@@ -54,7 +54,7 @@"limit": 0},"reportMissingParameterType": {- "limit": 5770+ "limit": 5772},"reportMissingTypeArgument": {"limit": 15676@@ -99,16 +99,16 @@"limit": 0},"reportUnknownArgumentType": {- "limit": 44911+ "limit": 44914},"reportUnknownLambdaType": {"limit": 113},"reportUnknownMemberType": {- "limit": 39464+ "limit": 39456},"reportUnknownParameterType": {- "limit": 20058+ "limit": 20060},"reportUnknownVariableType": {"limit": 31038@@ -129,7 +129,7 @@"limit": 0},"reportUntypedFunctionDecorator": {- "limit": 33+ "limit": 30},"reportUnusedClass": {"limit": 23diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.pyindex 570c34169d0..99b1c1a2ab7 100644--- a/litellm/litellm_core_utils/streaming_handler.py+++ b/litellm/litellm_core_utils/streaming_handler.py@@ -155,14 +155,6 @@ class _TextCompletionChoiceLike(Protocol):finish_reason: str | None-def validated_stream_logging_obj(candidate: object) -> LiteLLMLoggingObject:- from litellm.litellm_core_utils.litellm_logging import Logging-- if isinstance(candidate, Logging):- return candidate- raise TypeError("CustomStreamWrapper requires a LiteLLMLoggingObject")--class CustomStreamWrapper:def __init__(self,diff --git a/litellm/main.py b/litellm/main.pyindex 5d9144674de..27c20159322 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -96,7 +96,6 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import (from litellm.litellm_core_utils.request_timeout_resolver import (get_configured_request_timeout,)-from litellm.litellm_core_utils.streaming_handler import validated_stream_logging_objfrom litellm.llms.base_llm import BaseConfig, BaseImageGenerationConfigfrom litellm.llms.base_llm.base_model_iterator import (convert_model_response_to_streaming,@@ -597,7 +596,7 @@ async def acompletion(_, custom_llm_provider, _, _ = get_llm_provider(model=model,custom_llm_provider=custom_llm_provider,- api_base=completion_kwargs.get("base_url", None),+ api_base=base_url,)fallbacks = fallbacks or litellm.model_fallbacks@@ -827,7 +826,7 @@ def mock_completion(mock_response: MOCK_RESPONSE_TYPE | None = "This is a mock request",mock_tool_calls: list | None = None,mock_timeout: bool | None = False,- logging: LiteLLMLoggingObj | None = None,+ logging=None,custom_llm_provider=None,timeout: float | str | httpx.Timeout | None = None,**kwargs,@@ -911,7 +910,7 @@ def mock_completion(),model=model,custom_llm_provider="openai",- logging_obj=validated_stream_logging_obj(logging),+ logging_obj=logging,)return CustomStreamWrapper(completion_stream=mock_completion_streaming_obj(@@ -919,7 +918,7 @@ def mock_completion(),model=model,custom_llm_provider="openai",- logging_obj=validated_stream_logging_obj(logging),+ logging_obj=logging,)if isinstance(mock_response, litellm.MockException):raise mock_responsediff --git a/litellm/proxy/image_endpoints/endpoints.py b/litellm/proxy/image_endpoints/endpoints.pyindex 24ee1d96a0d..414beabe014 100644--- a/litellm/proxy/image_endpoints/endpoints.py+++ b/litellm/proxy/image_endpoints/endpoints.py@@ -1,8 +1,10 @@import asyncio+import ioimport traceback+from typing import Finalimport orjson-from fastapi import APIRouter, Depends, File, HTTPException, Request, Response, status+from fastapi import APIRouter, Depends, File, HTTPException, Request, Response, UploadFile, statusfrom fastapi.responses import ORJSONResponseimport litellm@@ -18,11 +20,6 @@ from litellm.types.llms.openai import ChatCompletionUserMessagerouter: Final = APIRouter()-import io-from typing import Final--from fastapi import UploadFile-async def uploadfile_to_bytesio(upload: UploadFile) -> io.BytesIO:"""diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 91526ad70d0..78171bd3cec 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -259,7 +259,6 @@ from litellm.litellm_core_utils.sensitive_data_masker import (SensitiveDataMasker,mask_sensitive_keys,)-from litellm.litellm_core_utils.streaming_handler import validated_stream_logging_objfrom litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandlerfrom litellm.llms.vertex_ai.vertex_llm_base import VertexBasefrom litellm.proxy._lazy_features import attach_lazy_features@@ -9749,7 +9748,7 @@ async def chat_completion(completion_stream=_iterator,model=e.model,custom_llm_provider="cached_response",- logging_obj=validated_stream_logging_obj(_logging_obj),+ logging_obj=_logging_obj,)selected_data_generator = select_data_generator(response=_streaming_response,@@ -9766,7 +9765,6 @@ async def chat_completion(return _chat_responseexcept RejectedRequestError as e:_data = e.request_data- _rejected_request_data: Final[dict[str, object]] = e.request_dataawait proxy_logging_obj.post_call_failure_hook(user_api_key_dict=user_api_key_dict,original_exception=e,@@ -9781,7 +9779,7 @@ async def chat_completion(completion_stream=_iterator,model=data.get("model", ""),custom_llm_provider="cached_response",- logging_obj=validated_stream_logging_obj(_rejected_request_data.get("litellm_logging_obj")),+ logging_obj=_data.get("litellm_logging_obj", None),)selected_data_generator = select_data_generator(response=_streaming_response,diff --git a/litellm/proxy/rerank_endpoints/endpoints.py b/litellm/proxy/rerank_endpoints/endpoints.pyindex fab97f0bdab..45b190c1f9d 100644--- a/litellm/proxy/rerank_endpoints/endpoints.py+++ b/litellm/proxy/rerank_endpoints/endpoints.py@@ -1,5 +1,8 @@#### Rerank Endpoints #####+import asyncio+from typing import Final+import orjsonfrom fastapi import APIRouter, Depends, HTTPException, Request, Response, statusfrom fastapi.responses import ORJSONResponse@@ -10,8 +13,6 @@ from litellm.proxy.auth.user_api_key_auth import user_api_key_authfrom litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessingrouter: Final = APIRouter()-import asyncio-from typing import Final@router.post(diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.pyindex ee430a41b42..e5ba5182bed 100644--- a/litellm/proxy/response_api_endpoints/endpoints.py+++ b/litellm/proxy/response_api_endpoints/endpoints.py@@ -95,7 +95,7 @@ def _normalize_tool_dialect(def _is_chat_completions_body(data: Mapping[str, Any]) -> bool:messages: Final = data.get("messages")- if isinstance(messages, list) and len(messages) > 0:+ if isinstance(messages, list) and messages:return Truereturn "messages" in data and "input" not in data@@ -497,10 +497,7 @@ async def cursor_chat_completions(from litellm.completion_extras.litellm_responses_transformation.handler import (responses_api_bridge,)- from litellm.litellm_core_utils.streaming_handler import (- CustomStreamWrapper,- validated_stream_logging_obj,- )+ from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapperfrom litellm.proxy.proxy_server import (async_data_generator,chat_completion,@@ -548,7 +545,7 @@ async def cursor_chat_completions(processor: Final = ProxyBaseLLMRequestProcessing(data=data)- def cursor_data_generator(response, user_api_key_dict, request_data: dict[str, object], request=None):+ def cursor_data_generator(response, user_api_key_dict, request_data, request=None):"""Custom generator that transforms Responses API streaming chunks to chat completion chunks.@@ -582,7 +579,7 @@ async def cursor_chat_completions(completion_stream=completion_stream,model=request_data.get("model", ""),custom_llm_provider=None,- logging_obj=validated_stream_logging_obj(logging_obj),+ logging_obj=logging_obj,)# Use async_data_generator to format as SSEreturn async_data_generator(diff --git a/ruff-strict-budget.json b/ruff-strict-budget.jsonindex 9b97dcdb43c..5c2ae134b94 100644--- a/ruff-strict-budget.json+++ b/ruff-strict-budget.json@@ -1,6 +1,6 @@{"ANN001": {- "limit": 3056+ "limit": 3058},"ANN002": {"limit": 71diff --git a/type-discipline-budget.json b/type-discipline-budget.jsonindex ad3f56c7bdf..e33cd34f609 100644--- a/type-discipline-budget.json+++ b/type-discipline-budget.json@@ -1,6 +1,6 @@{"LIT001": {- "limit": 23023+ "limit": 23021},"LIT002": {"limit": 27148