Skip to content

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]

add: comment above optimization

AlexsanderHamir7241b4e9b505
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index 16988205530..da592c90720 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -5236,6 +5236,10 @@ async def moderations(
async def _audio_speech_chunk_generator(
_response: HttpxBinaryResponseContent,
) -> AsyncGenerator[bytes, None]:
+ # chunk_size has a big impact on latency, it can't be too small or too large
+ # too small: latency is high
+ # too large: latency is low, but memory usage is high
+ # 8192 is a good compromise
_generator = await _response.aiter_bytes(chunk_size=8192)
async for chunk in _generator:
yield chunk