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(realtime): allow null transcripts in stream logging payloads (#29625)
milan-berri5ee526d78ee3
diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex 51e408f8c63..0c854d89bb1 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -1892,7 +1892,7 @@ class OpenAIRealtimeStreamResponseOutputItemContent(TypedDict, total=False):"""The ID of the previous conversation item for reference"""text: str"""The text content, used for 'input_text' / 'text' / 'output_text' content types"""- transcript: str+ transcript: Optional[str]"""The transcript content, used for 'input_audio' / 'audio' content types"""type: Literal["input_audio",@@ -1998,7 +1998,7 @@ class OpenAIRealtimeResponseContentPart(TypedDict, total=False):text: str"""The text content, if type is 'text' or 'output_text'"""- transcript: str+ transcript: Optional[str]"""The transcript content, if type is 'audio' or 'output_audio'"""type: Union[diff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.pyindex d973f8b4542..3d45a3409d8 100644--- a/tests/test_litellm/test_cost_calculator.py+++ b/tests/test_litellm/test_cost_calculator.py@@ -12,6 +12,7 @@ from pydantic import BaseModelimport litellmfrom litellm.cost_calculator import (+ RealtimeAPITokenUsageProcessor,completion_cost,cost_per_token,handle_realtime_stream_cost_calculation,@@ -385,6 +386,43 @@ def test_handle_realtime_stream_cost_calculation():assert cost == 0.0 # No usage, no cost+def test_realtime_logging_object_allows_null_transcript_in_conversation_item_added():+ results: OpenAIRealtimeStreamList = [+ {+ "type": "conversation.item.added",+ "event_id": "event_added",+ "item": {+ "id": "item_123",+ "type": "message",+ "role": "assistant",+ "status": "in_progress",+ "content": [{"type": "audio", "transcript": None}],+ },+ },+ {+ "type": "response.done",+ "event_id": "event_done",+ "response": {+ "id": "resp_123",+ "object": "realtime.response",+ "status": "completed",+ "usage": {"input_tokens": 11, "output_tokens": 7, "total_tokens": 18},+ },+ },+ ]++ usage = RealtimeAPITokenUsageProcessor.collect_and_combine_usage_from_realtime_stream_results(+ results=results+ )+ logging_result = RealtimeAPITokenUsageProcessor.create_logging_realtime_object(+ usage=usage,+ results=results,+ )++ assert logging_result.usage.total_tokens == 18+ assert logging_result.results[0]["item"]["content"][0]["transcript"] is None++def test_custom_pricing_with_router_model_id():from litellm import Router