fix: migrate OpenAI TTS provider to SDK v1.x#298
Open
kesslerio wants to merge 1 commit into
Open
Conversation
The OpenAI TTS provider was using the deprecated global API pattern (openai.api_key + openai.audio.speech.create()) which is incompatible with OpenAI SDK v1.x. This caused 404 errors when generating audio. Changes: - Initialize OpenAI client with openai.OpenAI() instead of global API key - Use client.audio.speech.create() instead of module-level function - Simplify authentication by relying on client's automatic env var handling Fixes 404 error: Invalid URL (POST /v1/audio/speech)
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.
Problem
The OpenAI TTS provider fails with a 404 error when using OpenAI SDK v1.x:
This occurs because the provider uses the deprecated global API pattern from SDK v0.x:
openai.api_keygloballyopenai.audio.speech.create()at module levelOpenAI SDK v1.x requires instantiating a client object.
Solution
Migrate to the modern client-based pattern:
Changes
OpenAI()client in__init__instead of setting global API keyself.client.audio.speech.create()instead of module-level functionTesting
Tested with OpenAI SDK 1.109.1:
Compatibility
Note: This fix is urgent as the current code is broken for all users with modern OpenAI SDK versions.