11from __future__ import annotations
22
3- import inspect
43from typing import (
54 Any ,
6- Callable ,
75 Literal ,
86 Union ,
97)
108
119from typing_extensions import NotRequired , TypeAlias , TypedDict
1210
1311from ..model_settings import ToolChoice
14- from ..tool import FunctionTool
15- from ..util ._types import MaybeAwaitable
12+ from ..tool import Tool
13+
14+ RealtimeModelName : TypeAlias = Union [
15+ Literal [
16+ "gpt-4o-realtime-preview" ,
17+ "gpt-4o-mini-realtime-preview" ,
18+ "gpt-4o-realtime-preview-2025-06-03" ,
19+ "gpt-4o-realtime-preview-2024-12-17" ,
20+ "gpt-4o-realtime-preview-2024-10-01" ,
21+ "gpt-4o-mini-realtime-preview-2024-12-17" ,
22+ ],
23+ str ,
24+ ]
25+ """The name of a realtime model."""
1626
1727
1828class RealtimeClientMessage (TypedDict ):
1929 type : str # explicitly required
2030 other_data : NotRequired [dict [str , Any ]]
2131
2232
23- class UserInputText (TypedDict ):
33+ class RealtimeUserInputText (TypedDict ):
2434 type : Literal ["input_text" ]
2535 text : str
2636
2737
2838class RealtimeUserInputMessage (TypedDict ):
2939 type : Literal ["message" ]
3040 role : Literal ["user" ]
31- content : list [UserInputText ]
41+ content : list [RealtimeUserInputText ]
3242
3343
3444RealtimeUserInput : TypeAlias = Union [str , RealtimeUserInputMessage ]
@@ -55,9 +65,11 @@ class RealtimeTurnDetectionConfig(TypedDict):
5565 threshold : NotRequired [float ]
5666
5767
58- class RealtimeSessionConfig (TypedDict ):
59- api_key : NotRequired [APIKeyOrKeyFunc ]
60- model : NotRequired [str ]
68+ class RealtimeSessionModelSettings (TypedDict ):
69+ """Model settings for a realtime model session."""
70+
71+ model_name : NotRequired [RealtimeModelName ]
72+
6173 instructions : NotRequired [str ]
6274 modalities : NotRequired [list [Literal ["text" , "audio" ]]]
6375 voice : NotRequired [str ]
@@ -68,24 +80,13 @@ class RealtimeSessionConfig(TypedDict):
6880 turn_detection : NotRequired [RealtimeTurnDetectionConfig ]
6981
7082 tool_choice : NotRequired [ToolChoice ]
71- tools : NotRequired [list [FunctionTool ]]
72-
73-
74- APIKeyOrKeyFunc = str | Callable [[], MaybeAwaitable [str ]]
75- """Either an API key or a function that returns an API key."""
76-
83+ tools : NotRequired [list [Tool ]]
7784
78- async def get_api_key (key : APIKeyOrKeyFunc | None ) -> str | None :
79- """Get the API key from the key or key function."""
80- if key is None :
81- return None
82- elif isinstance (key , str ):
83- return key
8485
85- result = key ()
86- if inspect .isawaitable (result ):
87- return await result
88- return result
86+ class RealtimeRunConfig (TypedDict ):
87+ model_settings : NotRequired [RealtimeSessionModelSettings ]
8988
9089 # TODO (rm) Add tracing support
9190 # tracing: NotRequired[RealtimeTracingConfig | None]
91+ # TODO (rm) Add guardrail support
92+ # TODO (rm) Add history audio storage config
0 commit comments