Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pyrit/prompt_target/openai/openai_response_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def __init__(
super().__init__(api_version=api_version, temperature=temperature, top_p=top_p, **kwargs)
self._max_output_tokens = max_output_tokens

# Validate endpoint URL for OpenAI Response API
self._validate_endpoint_url()

# Reasoning parameters are not yet supported by PyRIT.
# See https://platform.openai.com/docs/api-reference/responses/create#responses-create-reasoning
# for more information.
Expand All @@ -136,6 +139,29 @@ def _set_openai_env_configuration_vars(self) -> None:
self.api_key_environment_variable = "OPENAI_RESPONSES_KEY"
return

def _validate_endpoint_url(self) -> None:
"""
Validate that the endpoint URL ends with the correct path for OpenAI Response API.

Prints a warning if the endpoint doesn't end with '/openai/responses' for OpenAI or Azure OpenAI endpoints.
This validation helps ensure the endpoint is configured correctly for the Response API.
"""
if not self._endpoint:
return

endpoint_lower = self._endpoint.lower()

# Check if this is an OpenAI or Azure OpenAI endpoint
is_openai_endpoint = False
if "openai.com" in endpoint_lower or "openai.azure.com" in endpoint_lower or "azure.com" in endpoint_lower:
is_openai_endpoint = True

if is_openai_endpoint and not self._endpoint.endswith("/openai/responses"):
logger.warning(
f"Warning: Expected endpoint to end with '/openai/responses'. "
f"Please verify your endpoint: Your endpoint is '{self._endpoint}'."
)

# Helpers kept on the class for reuse + testability
def _flush_message(self, role: Optional[str], content: List[Dict[str, Any]], output: List[Dict[str, Any]]) -> None:
"""
Expand Down