Skip to content

BUG: OpenAITTSTarget sends speed=null, which gpt-4o-mini-tts rejects #4485

Open

Description

Summary

OpenAITTSTarget sends "speed": null when no speed is configured. gpt-4o-mini-tts rejects the request with a 400, so the target fails against that model unless the caller passes an explicit speed.

BadRequestError: Error code: 400 - Invalid type for 'speed': expected a decimal, but got null instead.
  param: "speed", code: "invalid_type"

Cause

_send_prompt_to_target_async leaves speed out of body_parameters when it is None (pyrit/prompt_target/openai/openai_tts_target.py:154-155). But the SDK call then passes it anyway:

speed=body_parameters.get("speed"),  # line 164

.get("speed") returns None, and the OpenAI SDK serializes an explicit None as JSON null. Only its NOT_GIVEN sentinel, or leaving the argument out, omits the field. The classic tts / tts-hd models apparently tolerate null, which is why this hasn't shown up before.

Repro

from pyrit.models import Message
from pyrit.prompt_target import OpenAITTSTarget

target = OpenAITTSTarget(endpoint=..., model_name="gpt-4o-mini-tts")  # no speed
await target.send_prompt_async(message=Message.from_prompt(prompt="hello", role="user"))
# -> 400 Invalid type for 'speed'

Passing speed=1.0 works around it.

Suggested fix

Don't pass speed to audio.speech.create when it isn't set. Either spread the optional parameters from body_parameters, or pass NOT_GIVEN/omit instead of None. Add a unit test asserting that the outgoing request body has no speed key when speed is None, and has it when it's set.

Seen with gpt-4o-mini-tts version 2025-12-15 on Azure OpenAI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions