Skip to content

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

Open
@cyborg728

Description

@cyborg728

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions