Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions litellm/types/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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[
Expand Down
38 changes: 38 additions & 0 deletions tests/test_litellm/test_cost_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import litellm
from litellm.cost_calculator import (
RealtimeAPITokenUsageProcessor,
completion_cost,
cost_per_token,
handle_realtime_stream_cost_calculation,
Expand Down Expand Up @@ -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

Expand Down
Loading