Skip to content

fix: migrate OpenAI TTS provider to SDK v1.x#298

Open
kesslerio wants to merge 1 commit into
souzatharsis:mainfrom
kesslerio:fix/openai-sdk-v1
Open

fix: migrate OpenAI TTS provider to SDK v1.x#298
kesslerio wants to merge 1 commit into
souzatharsis:mainfrom
kesslerio:fix/openai-sdk-v1

Conversation

@kesslerio

Copy link
Copy Markdown

Problem

The OpenAI TTS provider fails with a 404 error when using OpenAI SDK v1.x:

Error code: 404 - Invalid URL (POST /v1/audio/speech)

This occurs because the provider uses the deprecated global API pattern from SDK v0.x:

  • Setting openai.api_key globally
  • Calling openai.audio.speech.create() at module level

OpenAI SDK v1.x requires instantiating a client object.

Solution

Migrate to the modern client-based pattern:

# Before (SDK v0.x - broken with v1.x)
openai.api_key = api_key
response = openai.audio.speech.create(...)

# After (SDK v1.x - compatible)
self.client = openai.OpenAI(api_key=api_key)
response = self.client.audio.speech.create(...)

Changes

  • Initialize OpenAI() client in __init__ instead of setting global API key
  • Use self.client.audio.speech.create() instead of module-level function
  • Rely on client's automatic environment variable handling for auth

Testing

Tested with OpenAI SDK 1.109.1:

  • TTS generation works correctly
  • 404 error resolved

Compatibility

  • Requires OpenAI SDK >=1.0.0 (which the package already depends on)
  • No breaking changes to provider interface

Note: This fix is urgent as the current code is broken for all users with modern OpenAI SDK versions.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants