fix(beta/realtime): Make model parameter optional for transcription mode#2805
Open
jay-dhamale wants to merge 2 commits intoopenai:mainfrom
Open
fix(beta/realtime): Make model parameter optional for transcription mode#2805jay-dhamale wants to merge 2 commits intoopenai:mainfrom
jay-dhamale wants to merge 2 commits intoopenai:mainfrom
Conversation
Fixes openai#2796 The error handling logic for `sse.event == "error"` was incorrectly nested inside the `if sse.event.startswith("thread.")` condition, making it logically unreachable (dead code). A string cannot both equal "error" AND start with "thread." simultaneously. This was a regression introduced in commit abc2596 which attempted to fix indentation but accidentally moved the error handler into the wrong conditional block. The fix restructures the logic to: 1. Check for error events first (before any event type routing) 2. Handle thread.* events with their special data structure 3. Handle all other events in the else block This ensures error events are properly caught and raise APIError with the appropriate error message.
Fixes openai#2652 The Beta AsyncRealtime and Realtime classes required the model parameter, but the OpenAI transcription API rejects requests with model when intent=transcribe is specified. Changes: - Made model parameter optional (str | Omit = omit) in all connect() methods - Conditionally include model in URL query params only when provided - Added Azure client validation to require model for Azure Realtime API - Applied fix to both sync (Realtime) and async (AsyncRealtime) versions This enables transcription mode while maintaining backward compatibility with existing code that explicitly passes model parameter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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