Skip to content

openai.Audio.transcribe() fails with BytesIO unless .name is manually set #2315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
cyborg728 opened this issue Apr 18, 2025 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@cyborg728
Copy link

cyborg728 commented Apr 18, 2025

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

When using openai_client.audio.transcriptions.create) with an in-memory file (io.BytesIO), the function fails unless the .name attribute is manually set to a valid filename with a supported extension (e.g., audio.wav or audio.mp3).

This requirement is not documented, and the resulting error is confusing (e.g., AttributeError). This is especially problematic when handling file uploads in memory, such as from Telegram bots or web clients.

To Reproduce

import io
from openai import AsyncOpenAI

openai_client = AsyncOpenAI(api_key=OPENAI_API_KEY)

# Simulating an audio file from memory (e.g., from a Telegram bot)

audio_bytes = io.BytesIO(b"audio binary data here")

# This will fail unless you set `audio_bytes.name = "audio.wav"

await openai_client.audio.transcriptions.create(
        model="whisper-1", file=audio_bytes
)

Code snippets

OS

windows

Python version

python v3.11.4

Library version

openai v1.75.0

@cyborg728 cyborg728 added the bug Something isn't working label Apr 18, 2025
@issamhaimour

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants