pyrit.prompt_target.OpenAISoraTarget#

class OpenAISoraTarget(*, resolution_dimensions: str = '1280x720', n_seconds: int = 4, **kwargs)[source]#

Bases: OpenAITarget

Unified OpenAI Sora Target supporting both Sora-1 and Sora-2 APIs.

API version is automatically detected from the endpoint URL: - Sora-2: Endpoint contains “v1/videos” - Sora-1: All other endpoints

Provider detection (OpenAI vs Azure OpenAI): - Azure OpenAI: Endpoint contains “azure.com” - OpenAI: All other endpoints (e.g., “openai.com”)

Sora-1 API: - Uses JSON body with /jobs endpoints - Supported resolutions: 480x480, 854x480, 720x720, 1280x720, 1080x1080, 1920x1080 - Duration: up to 20s (10s for 1080p)

Sora-2 API: - Uses multipart form data with direct task endpoints - Supported resolutions:

  • Sora-2 (both Azure OpenAI and OpenAI): 720x1280, 1280x720

  • Sora-2-Pro (OpenAI only): 720x1280, 1280x720, 1024x1792, 1792x1024

  • Duration: 4, 8, or 12 seconds only

Default resolution (1280x720) works with both APIs on OpenAI. Default duration (4s) works with both APIs (v1 supports up to 20s, v2 requires 4/8/12s).

__init__(*, resolution_dimensions: str = '1280x720', n_seconds: int = 4, **kwargs)[source]#

Initialize the unified OpenAI Sora Target.

Parameters:
  • model_name (str, Optional) – The name of the model.

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

  • api_key (str, Optional) – The API key for accessing the service. Uses OPENAI_SORA_KEY environment variable by default.

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

  • use_entra_auth (bool, Optional) – When set to True, user authentication is used instead of API Key. DefaultAzureCredential is taken for https://cognitiveservices.azure.com/.default. Please run az login locally to leverage user AuthN.

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

  • httpx_client_kwargs (dict, Optional) – Additional kwargs to be passed to the httpx.AsyncClient() constructor.

  • resolution_dimensions (str, Optional) – Resolution dimensions for the video in WIDTHxHEIGHT format. Defaults to “1280x720” which works with Sora-1 and Sora-2 on both providers. Sora-1 supported resolutions: “480x480”, “854x480”, “720x720”, “1280x720”, “1080x1080”, “1920x1080”. Sora-2 supported resolutions (both OpenAI and Azure OpenAI per API spec): “720x1280”, “1280x720” Sora-2-Pro (OpenAI only) supported resolutions: “720x1280”, “1280x720”, “1024x1792”, “1792x1024”

  • n_seconds (int, Optional) – The duration of the generated video (in seconds). Defaults to 4 (compatible with both APIs). Sora-1 supports up to 20 seconds (10 seconds max for 1080p resolutions). Sora-2 supports exactly 4, 8, or 12 seconds.

Methods

__init__(*[, resolution_dimensions, n_seconds])

Initialize the unified OpenAI Sora Target.

check_job_status_async(task_id)

Check job/task status using the appropriate endpoint.

dispose_db_engine()

Dispose database engine to release database connections and resources.

download_video_content_async(task_id[, ...])

Download video using the appropriate endpoint.

get_identifier()

is_json_response_supported()

Indicates that this target supports JSON response format.

is_response_format_json(message_piece)

Checks if the response format is JSON and ensures the target supports it.

refresh_auth_headers()

Refresh the authentication headers.

send_prompt_async(**kwargs)

Sends a normalized prompt async to the prompt target.

set_model_name(*, model_name)

Set the model name for this target.

set_system_prompt(*, system_prompt, ...[, ...])

Sets the system prompt for the prompt target.

Attributes

ADDITIONAL_REQUEST_HEADERS

CHAT_URL_REGEX

CHECK_JOB_RETRY_MAX_NUM_ATTEMPTS

DALLE_URL_REGEX

RESPONSE_URL_REGEX

SORA_URL_REGEX

TTS_URL_REGEX

V1_RESOLUTIONS

V2_DURATIONS

V2_RESOLUTIONS

model_name_environment_variable

endpoint_environment_variable

api_key_environment_variable

supported_converters

CHECK_JOB_RETRY_MAX_NUM_ATTEMPTS: int = 120#
V1_RESOLUTIONS = ['480x480', '854x480', '720x720', '1280x720', '1080x1080', '1920x1080']#
V2_DURATIONS = [4, 8, 12]#
V2_RESOLUTIONS = ['720x1280', '1280x720', '1024x1792', '1792x1024']#
async check_job_status_async(task_id: str) Response[source]#

Check job/task status using the appropriate endpoint.

async download_video_content_async(task_id: str, generation_id: str | None = None, **kwargs) Response[source]#

Download video using the appropriate endpoint.

is_json_response_supported() bool[source]#

Indicates that this target supports JSON response format.

async send_prompt_async(**kwargs)#

Sends a normalized prompt async to the prompt target.