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
[Performance] Performance improvements for /v1/messages route (#11421)
Ishaan Jaffde306cfcb3d6
diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.pyindex c4164daabe6..0f1f215139b 100644--- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py+++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py@@ -125,9 +125,9 @@ class AnthropicPassthroughLoggingHandler:litellm_model_response.id = logging_obj.litellm_call_idlitellm_model_response.model = modellogging_obj.model_call_details["model"] = model- logging_obj.model_call_details[- "custom_llm_provider"- ] = litellm.LlmProviders.ANTHROPIC.value+ logging_obj.model_call_details["custom_llm_provider"] = (+ litellm.LlmProviders.ANTHROPIC.value+ )return kwargsexcept Exception as e:verbose_proxy_logger.exception(@@ -210,10 +210,6 @@ class AnthropicPassthroughLoggingHandler:if transformed_openai_chunk is not None:all_openai_chunks.append(transformed_openai_chunk)- verbose_proxy_logger.debug(- "all openai chunks= %s",- json.dumps(all_openai_chunks, indent=4, default=str),- )except (StopIteration, StopAsyncIteration):breakcomplete_streaming_response = litellm.stream_chunk_builder(diff --git a/litellm/proxy/pass_through_endpoints/streaming_handler.py b/litellm/proxy/pass_through_endpoints/streaming_handler.pyindex d4260a03003..4efd43c9ff1 100644--- a/litellm/proxy/pass_through_endpoints/streaming_handler.py+++ b/litellm/proxy/pass_through_endpoints/streaming_handler.py@@ -1,5 +1,4 @@import asyncio-import threadingfrom datetime import datetimefrom typing import List, Optional@@ -7,6 +6,7 @@ import httpxfrom litellm._logging import verbose_proxy_loggerfrom litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj+from litellm.litellm_core_utils.thread_pool_executor import executorfrom litellm.proxy._types import PassThroughEndpointLoggingResultValuesfrom litellm.types.passthrough_endpoints.pass_through_endpoints import EndpointTypefrom litellm.types.utils import StandardPassThroughResponseObject@@ -122,15 +122,7 @@ class PassThroughStreamingHandler:standard_logging_response_object = StandardPassThroughResponseObject(response=f"cannot parse chunks to standard response object. Chunks={all_chunks}")- threading.Thread(- target=litellm_logging_obj.success_handler,- args=(- standard_logging_response_object,- start_time,- end_time,- False,- ),- ).start()+await litellm_logging_obj.async_success_handler(result=standard_logging_response_object,start_time=start_time,@@ -138,6 +130,17 @@ class PassThroughStreamingHandler:cache_hit=False,**kwargs,)+ if litellm_logging_obj._should_run_sync_callbacks_for_async_calls() is False:+ return++ executor.submit(+ litellm_logging_obj.success_handler,+ result=standard_logging_response_object,+ end_time=end_time,+ cache_hit=False,+ start_time=start_time,+ **kwargs,+ )@staticmethoddef _convert_raw_bytes_to_str_lines(raw_bytes: List[bytes]) -> List[str]: