fix(beta/realtime): Make model parameter optional for transcription mode #2805
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2652 - Makes model parameter optional in Beta AsyncRealtime/Realtime classes to enable transcription mode
Problem
The Beta
AsyncRealtimeandRealtimeclasses require themodelparameter, but the OpenAI transcription API explicitly rejects requests containingmodelwhenintent=transcribeis specified.Error from API:
{ "error": { "message": "You must not provide a model parameter for transcription sessions.", "type": "invalid_request_error", "code": "invalid_model" } }Root Cause
model: str(required parameter)model: str | Omit = omit(optional parameter)"model": self.__modelSolution
Made the Beta Realtime API match the Standard Realtime API pattern:
model: strtomodel: str | Omit = omit**({"model": self.__model} if self.__model is not omit else {})RealtimeandAsyncRealtimeChanges
Modified
src/openai/resources/beta/realtime/realtime.py:Omitandomitimports from_typesRealtime.connect()method signature (line 96)AsyncRealtime.connect()method signature (line 152)RealtimeConnectionManager.__init__(line 516)RealtimeConnectionManager.__enter__URL building (lines 549-561)AsyncRealtimeConnectionManager.__init__(line 330)AsyncRealtimeConnectionManager.__aenter__URL building (lines 363-375)Backward Compatibility
✅ Zero breaking changes:
modelcontinues to workstr | Omitaccepts string values (no type errors)Testing
✅ All verification checks passed:
ruff check)ruff format)Usage Examples
Before (fails for transcription):
After (transcription works):
Edge Cases Handled
OpenAIErrorif omittedomitsentinel (notNone) for clarityextra_queryif neededstr | Omitunion maintains type checkingRelated Issues