#Whisper API giving 400s using aiohttp in python

2 messages · Page 1 of 1 (latest)

glacial dove
#

I'm trying to create a Discord bot with Whisper capabilities, so I need my requests to be async. I am downloading .mp3 files from Discord, then I am trying to upload them to the Whisper API. It isn't accepting my requests, and it returns this error:

{
        "message": "Could not parse multipart form",
        "type": "invalid_request_error",
        "code": null
}

Here is the code I am using:

    async with aiohttp.ClientSession() as session:
        filename = "test.mp3"
        async with session.get("https://cdn.discordapp.com/attachments/1097219558466658354/1112417715316076775/AI_Test_Kitchen_toetapping_footstomping_americana_1.mp3") as resp:
            if resp.status == 200:
                audiodata = await resp.read()
...

                headers = {
                    "Authorization": "Bearer " + openai.api_key,
                    "Content-Type": "multipart/form-data"
                }
                form = aiohttp.FormData()
                form.add_field('file', audio, content_type='audio/mp3')
                form.add_field("model", "whisper-1", content_type="text/plain")


                resp = await session.post(url="https://api.openai.com/v1/audio/transcriptions", data=form, headers=headers)
                print(await resp.text())

                
            await session.close()

Does anyone know why this is?

glacial dove
#

Never mind