pyrit.prompt_target.OpenAIImageTarget#

class OpenAIImageTarget(image_size: Literal['256x256', '512x512', '1024x1024', '1536x1024', '1024x1536', '1792x1024', '1024x1792'] = '1024x1024', output_format: Literal['png', 'jpeg', 'webp'] | None = None, quality: Literal['standard', 'hd', 'low', 'medium', 'high'] | None = None, style: Literal['natural', 'vivid'] | None = None, *args: Any, **kwargs: Any)[source]#

Bases: OpenAITarget

A target for image generation or editing using OpenAI’s image models.

__init__(image_size: Literal['256x256', '512x512', '1024x1024', '1536x1024', '1024x1536', '1792x1024', '1024x1792'] = '1024x1024', output_format: Literal['png', 'jpeg', 'webp'] | None = None, quality: Literal['standard', 'hd', 'low', 'medium', 'high'] | None = None, style: Literal['natural', 'vivid'] | None = None, *args: Any, **kwargs: Any) None[source]#

Initialize the image target with specified parameters.

Parameters:
  • model_name (str, Optional) – The name of the model (or deployment name in Azure). If no value is provided, the OPENAI_IMAGE_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)). Defaults to the OPENAI_IMAGE_API_KEY environment variable.

  • headers (str, Optional) – 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. The number of requests sent to the target will be capped at the value provided.

  • image_size (Literal["256x256", "512x512", "1024x1024", "1536x1024", "1024x1536", "1792x1024", "1024x1792"], Optional) – The size of the generated image. Different models support different image sizes. GPT image models support “1024x1024”, “1536x1024” and “1024x1536”. DALL-E-3 supports “1024x1024”, “1792x1024” and “1024x1792”. DALL-E-2 supports “256x256”, “512x512” and “1024x1024”. Defaults to “1024x1024”.

  • output_format (Literal["png", "jpeg", "webp"], Optional) – The output format of the generated images. This parameter is only supported for GPT image models. Default is to not specify (which will use the model’s default format, e.g. PNG for OpenAI image models).

  • quality (Literal["standard", "hd", "low", "medium", "high"], Optional) – The quality of the generated images. Different models support different quality settings. GPT image models support “high”, “medium” and “low”. DALL-E-3 supports “hd” and “standard”. DALL-E-2 supports “standard” only. Default is to not specify.

  • style (Literal["natural", "vivid"], Optional) – The style of the generated images. This parameter is only supported for DALL-E-3. Default is to not specify.

  • *args – Additional positional arguments to be passed to AzureOpenAITarget.

  • **kwargs – Additional keyword arguments to be passed to AzureOpenAITarget.

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

Methods

__init__([image_size, output_format, ...])

Initialize the image target with specified parameters.

dispose_db_engine()

Dispose database engine to release database connections and resources.

get_identifier()

Get the typed identifier for this object.

is_json_response_supported()

Check if the target supports JSON as a response format.

is_response_format_json(message_piece)

Check if the response format is JSON and ensure the target supports it.

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.

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

Set the system prompt for the prompt target.

Attributes

ADDITIONAL_REQUEST_HEADERS

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.

api_key_environment_variable: str#
endpoint_environment_variable: str#
is_json_response_supported() bool[source]#

Check if the target supports JSON as a response format.

Returns:

True if JSON response is supported, False otherwise.

Return type:

bool

model_name_environment_variable: str#
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]

underlying_model_environment_variable: str#