Skip to content

AzureOpenAI.audio.speech.create(...) rejects instructions parameter #2418

Open
@adarshxs

Description

@adarshxs

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 the AzureOpenAI client from the openai Python package with the audio.speech.create(...) or audio.speech.with_streaming_response.create(...) methods, passing an instructions argument results in a Python TypeError. However, the official OpenAI API docs show instructions as a supported parameter for text-to-speech.

when I send a curl request with instructions in data field, it works as well, so I'm guessing its not an endpoint issue but rather AzureOpenAI client?

To Reproduce

  1. Run the code snipper below
from openai import AzureOpenAI
import os

client = AzureOpenAI(
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),
    api_version="2025‑03‑01‑preview"
)

with client.audio.speech.with_streaming_response.create(
    model="gpt‑4o‑mini‑tts",
    voice="coral",
    input="Today is a wonderful day!",
    instructions="Speak in a cheerful and positive tone."
) as resp:
    resp.stream_to_file("out.mp3")

Output:
TypeError: Speech.create() got an unexpected keyword argument 'instructions'

Code snippets

This works well:


curl -X POST "https://xxxx.cognitiveservices.azure.com/openai/deployments/tts/audio/speech..." \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
      "model": "tts",
      "input": "The quick brown fox jumped over the lazy dog",
      "voice": "alloy",
      "instructions": "scary and dark and deep voice",
      "response_format": "wav"
    }' --output output.wav

OS

Windows

Python version

python v3.11.7

Library version

openai v1.88.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