pyrit.prompt_target.HTTPTarget#

class HTTPTarget(http_request: str, prompt_regex_string: str = '{PROMPT}', use_tls: bool = True, callback_function: Callable[[...], Any] | None = None, max_requests_per_minute: int | None = None, client: AsyncClient | None = None, model_name: str = '', **httpx_client_kwargs: Any)[source]#

Bases: PromptTarget

HTTP_Target is for endpoints that do not have an API and instead require HTTP request(s) to send a prompt.

Parameters:
  • http_request (str) – the header parameters as a request (i.e., from Burp)

  • prompt_regex_string (str) – the placeholder for the prompt (default is {PROMPT}) which will be replaced by the actual prompt. make sure to modify the http request to have this included, otherwise it will not be properly replaced!

  • use_tls – (bool): whether to use TLS or not. Default is True

  • callback_function (function) – function to parse HTTP response. These are the customizable functions which determine how to parse the output

  • httpx_client_kwargs – (dict): additional keyword arguments to pass to the HTTP client

__init__(http_request: str, prompt_regex_string: str = '{PROMPT}', use_tls: bool = True, callback_function: Callable[[...], Any] | None = None, max_requests_per_minute: int | None = None, client: AsyncClient | None = None, model_name: str = '', **httpx_client_kwargs: Any) None[source]#

Initialize the HTTPTarget.

Parameters:
  • http_request (str) – The raw HTTP request string.

  • prompt_regex_string (str) – Regex string to match prompt location. Defaults to “{PROMPT}”.

  • use_tls (bool) – Whether to use TLS. Defaults to True.

  • callback_function (Callable, Optional) – Function to parse HTTP response.

  • max_requests_per_minute (int, Optional) – Maximum number of requests per minute.

  • client (httpx.AsyncClient, Optional) – Pre-configured httpx client.

  • model_name (str) – The model name. Defaults to empty string.

  • **httpx_client_kwargs – Additional keyword arguments for httpx.AsyncClient.

Raises:

ValueError – If both client and httpx_client_kwargs are provided.

Methods

__init__(http_request[, ...])

Initialize the HTTPTarget.

dispose_db_engine()

Dispose database engine to release database connections and resources.

get_identifier()

Get an identifier dictionary for this prompt target.

parse_raw_http_request(http_request)

Parse the HTTP request string into a dictionary of headers.

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.

with_client(client, http_request[, ...])

Alternative constructor that accepts a pre-configured httpx client.

Attributes

supported_converters

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

parse_raw_http_request(http_request: str) tuple[Dict[str, str], dict[str, Any] | str, str, str, str][source]#

Parse the HTTP request string into a dictionary of headers.

Parameters:

http_request – the header parameters as a request str with prompt already injected

Returns:

dictionary of all http header values body (str): string with body data url (str): string with URL http_method (str): method (ie GET vs POST) http_version (str): HTTP version to use

Return type:

headers_dict (dict)

Raises:

ValueError – If the HTTP request line is invalid.

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]

supported_converters: List[Any]#

A list of PromptConverters that are supported by the prompt target. An empty list implies that the prompt target supports all converters.

classmethod with_client(client: AsyncClient, http_request: str, prompt_regex_string: str = '{PROMPT}', callback_function: Callable[[...], Any] | None = None, max_requests_per_minute: int | None = None) HTTPTarget[source]#

Alternative constructor that accepts a pre-configured httpx client.

Parameters:
  • client – Pre-configured httpx.AsyncClient instance

  • http_request – the header parameters as a request (i.e., from Burp)

  • prompt_regex_string – the placeholder for the prompt

  • callback_function – function to parse HTTP response

  • max_requests_per_minute – Optional rate limiting

Returns:

an instance of HTTPTarget

Return type:

HTTPTarget