pyrit.prompt_target.OpenAIVideoTarget#

class OpenAIVideoTarget(*, resolution_dimensions: Literal['720x1280', '1280x720', '1024x1792', '1792x1024'] = '1280x720', n_seconds: int | Literal['4', '8', '12'] = 4, **kwargs: Any)[source]#

Bases: OpenAITarget

OpenAI Video Target using the OpenAI SDK for video generation.

Supports Sora-2 and Sora-2-Pro models via the OpenAI videos API.

Supports three modes: - Text-to-video: Generate video from a text prompt - Text+Image-to-video: Generate video using an image as the first frame (include image_path piece) - Remix: Create variation of existing video (include video_id in prompt_metadata)

Supported resolutions: - Sora-2: 720x1280, 1280x720 - Sora-2-Pro: 720x1280, 1280x720, 1024x1792, 1792x1024

Supported durations: 4, 8, or 12 seconds

Default: resolution=”1280x720”, duration=4 seconds

Supported image formats for text+image-to-video: JPEG, PNG, WEBP

__init__(*, resolution_dimensions: Literal['720x1280', '1280x720', '1024x1792', '1792x1024'] = '1280x720', n_seconds: int | Literal['4', '8', '12'] = 4, **kwargs: Any) None[source]#

Initialize the OpenAI Video Target.

Parameters:
  • model_name (str, Optional) – The video model to use (e.g., “sora-2”, “sora-2-pro”) (or deployment name in Azure). If no value is provided, the OPENAI_VIDEO_MODEL environment variable will be used.

  • endpoint (str, Optional) – The target URL for the OpenAI service.

  • api_key (str | Callable[[], str], Optional) – The API key for accessing the OpenAI service, or a callable that returns an access token. For Azure endpoints with Entra authentication, pass a token provider from pyrit.auth (e.g., get_azure_openai_auth(endpoint)). Uses OPENAI_VIDEO_KEY environment variable by default.

  • headers (str, Optional) – Extra headers of the endpoint (JSON).

  • max_requests_per_minute (int, Optional) – Number of requests the target can handle per minute before hitting a rate limit.

  • resolution_dimensions (VideoSize, Optional) – Resolution dimensions for the video. Defaults to “1280x720”. Supported resolutions: - Sora-2: “720x1280”, “1280x720” - Sora-2-Pro: “720x1280”, “1280x720”, “1024x1792”, “1792x1024”

  • n_seconds (int | VideoSeconds, Optional) – The duration of the generated video. Accepts an int (4, 8, 12) or a VideoSeconds string (“4”, “8”, “12”). Defaults to 4.

  • **kwargs – Additional keyword arguments passed to the parent OpenAITarget class.

  • httpx_client_kwargs (dict, Optional) – Additional kwargs to be passed to the httpx.AsyncClient() constructor. For example, to specify a 3 minute timeout: httpx_client_kwargs={"timeout": 180}

Remix workflow:

To remix an existing video, set prompt_metadata={"video_id": "<id>"} on the text MessagePiece. The video_id is returned in the response metadata after any successful generation (response.message_pieces[0].prompt_metadata["video_id"]).

Methods

__init__(*[, resolution_dimensions, n_seconds])

Initialize the OpenAI Video Target.

dispose_db_engine()

Dispose database engine to release database connections and resources.

get_identifier()

Get the component's identifier, building it lazily on first access.

is_json_response_supported()

Check if the target supports JSON response data.

send_prompt_async(**kwargs)

Send a normalized prompt async to the prompt target.

set_model_name(*, model_name)

Set the model name for this target.

Attributes

ADDITIONAL_REQUEST_HEADERS

SUPPORTED_DURATIONS

SUPPORTED_IMAGE_FORMATS

SUPPORTED_RESOLUTIONS

capabilities

The capabilities of this target instance.

supports_multi_turn

Whether this target supports multi-turn conversations.

model_name_environment_variable

endpoint_environment_variable

api_key_environment_variable

underlying_model_environment_variable

supported_converters

A list of PromptConverters that are supported by the prompt target.

SUPPORTED_DURATIONS: list[Literal['4', '8', '12']] = ['4', '8', '12']#
SUPPORTED_IMAGE_FORMATS: list[str] = ['image/jpeg', 'image/png', 'image/webp']#
SUPPORTED_RESOLUTIONS: list[Literal['720x1280', '1280x720', '1024x1792', '1792x1024']] = ['720x1280', '1280x720', '1024x1792', '1792x1024']#
is_json_response_supported() bool[source]#

Check if the target supports JSON response data.

Returns:

False, as video generation doesn’t return JSON content.

Return type:

bool

async send_prompt_async(**kwargs: Any) Any#

Send a normalized prompt async to the prompt target.

Returns:

A list of message responses. Most targets return a single message,

but some (like response target with tool calls) may return multiple messages.

Return type:

list[Message]