OpenAIResponses
is a class for interacting with OpenAI models using the Responses API. This class provides a streamlined interface for working with OpenAI’s newer Responses API, which is distinct from the traditional Chat API. It supports advanced features like tool use, file processing, and knowledge retrieval.
Authentication
Set yourOPENAI_API_KEY
environment variable. You can get one from OpenAI here.
Example
UseOpenAIResponses
with your Agent
:
View more examples here.
Parameters
For more information, please refer to the OpenAI Responses docs as well.Parameter | Type | Default | Description |
---|---|---|---|
id | str | "gpt-5-mini" | The id of the OpenAI model to use with Responses API |
name | str | "OpenAIResponses" | The name of the model |
provider | str | "OpenAI" | The provider of the model |
instructions | Optional[str] | None | System-level instructions for the assistant |
response_format | Optional[Union[str, Dict]] | None | Response format specification for structured outputs |
temperature | Optional[float] | None | Controls randomness in the model’s output (0.0 to 2.0) |
top_p | Optional[float] | None | Controls diversity via nucleus sampling (0.0 to 1.0) |
max_completion_tokens | Optional[int] | None | Maximum number of completion tokens to generate |
truncation_strategy | Optional[Dict[str, Any]] | None | Strategy for truncating messages when they exceed context limits |
tool_choice | Optional[Union[str, Dict]] | None | Controls which function is called by the model |
parallel_tool_calls | Optional[bool] | None | Whether to enable parallel function calling |
metadata | Optional[Dict[str, str]] | None | Developer-defined metadata to associate with the response |
api_key | Optional[str] | None | The API key for authenticating with OpenAI (defaults to OPENAI_API_KEY env var) |
organization | Optional[str] | None | The organization ID to use for requests |
base_url | Optional[Union[str, httpx.URL]] | None | The base URL for the OpenAI API |
timeout | Optional[float] | None | Request timeout in seconds |
max_retries | Optional[int] | None | Maximum number of retries for failed requests |
default_headers | Optional[Any] | None | Default headers to include in all requests |
http_client | Optional[Union[httpx.Client, httpx.AsyncClient]] | None | HTTP client instance for making requests |
OpenAIResponses
is a subclass of the Model class and has access to the same params.