Skip to content

Responses

The responses and aresponses functions implement the OpenResponses specification, a vendor-neutral API for agentic AI systems. This API supports multi-turn conversations, tool use, and streaming events.

The return type depends on the provider and whether streaming is enabled:

ConditionReturn Type
OpenResponses-compliant provider (non-streaming)openresponses_types.ResponseResource
OpenAI-native provider (non-streaming)openai.types.responses.Response
Streaming (stream=True)Iterator[ResponseStreamEvent] (sync) or AsyncIterator[ResponseStreamEvent] (async)
def responses(
model: str,
input_data: str | list[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | ComputerCallOutput | ResponseFunctionWebSearchParam | ResponseFunctionToolCallParam | FunctionCallOutput | ToolSearchCall | ResponseToolSearchOutputItemParamParam | ResponseReasoningItemParam | ResponseCompactionItemParamParam | ImageGenerationCall | ResponseCodeInterpreterToolCallParam | LocalShellCall | LocalShellCallOutput | ShellCall | ShellCallOutput | ApplyPatchCall | ApplyPatchCallOutput | McpListTools | McpApprovalRequest | McpApprovalResponse | McpCall | ResponseCustomToolCallOutputParam | ResponseCustomToolCallParam | ItemReference],
*,
provider: str | LLMProvider | None = None,
tools: list[dict[str, Any] | Callable[..., Any]] | None = None,
tool_choice: str | dict[str, Any] | None = None,
max_output_tokens: int | None = None,
temperature: float | None = None,
top_p: float | None = None,
stream: bool | None = None,
api_key: str | None = None,
api_base: str | None = None,
instructions: str | None = None,
max_tool_calls: int | None = None,
parallel_tool_calls: int | None = None,
reasoning: Any | None = None,
text: Any | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
truncation: str | None = None,
store: bool | None = None,
service_tier: str | None = None,
user: str | None = None,
metadata: dict[str, str] | None = None,
previous_response_id: str | None = None,
include: list[str] | None = None,
background: bool | None = None,
safety_identifier: str | None = None,
prompt_cache_key: str | None = None,
prompt_cache_retention: str | None = None,
conversation: str | dict[str, Any] | None = None,
client_args: dict[str, Any] | None = None,
**kwargs: Any,
) -> types.ResponseResource | response.Response | Iterator[Annotated[Union[response_audio_delta_event.ResponseAudioDeltaEvent, response_audio_done_event.ResponseAudioDoneEvent, response_audio_transcript_delta_event.ResponseAudioTranscriptDeltaEvent, response_audio_transcript_done_event.ResponseAudioTranscriptDoneEvent, response_code_interpreter_call_code_delta_event.ResponseCodeInterpreterCallCodeDeltaEvent, response_code_interpreter_call_code_done_event.ResponseCodeInterpreterCallCodeDoneEvent, response_code_interpreter_call_completed_event.ResponseCodeInterpreterCallCompletedEvent, response_code_interpreter_call_in_progress_event.ResponseCodeInterpreterCallInProgressEvent, response_code_interpreter_call_interpreting_event.ResponseCodeInterpreterCallInterpretingEvent, response_completed_event.ResponseCompletedEvent, response_content_part_added_event.ResponseContentPartAddedEvent, response_content_part_done_event.ResponseContentPartDoneEvent, response_created_event.ResponseCreatedEvent, response_error_event.ResponseErrorEvent, response_file_search_call_completed_event.ResponseFileSearchCallCompletedEvent, response_file_search_call_in_progress_event.ResponseFileSearchCallInProgressEvent, response_file_search_call_searching_event.ResponseFileSearchCallSearchingEvent, response_function_call_arguments_delta_event.ResponseFunctionCallArgumentsDeltaEvent, response_function_call_arguments_done_event.ResponseFunctionCallArgumentsDoneEvent, response_in_progress_event.ResponseInProgressEvent, response_failed_event.ResponseFailedEvent, response_incomplete_event.ResponseIncompleteEvent, response_output_item_added_event.ResponseOutputItemAddedEvent, response_output_item_done_event.ResponseOutputItemDoneEvent, response_reasoning_summary_part_added_event.ResponseReasoningSummaryPartAddedEvent, response_reasoning_summary_part_done_event.ResponseReasoningSummaryPartDoneEvent, response_reasoning_summary_text_delta_event.ResponseReasoningSummaryTextDeltaEvent, response_reasoning_summary_text_done_event.ResponseReasoningSummaryTextDoneEvent, response_reasoning_text_delta_event.ResponseReasoningTextDeltaEvent, response_reasoning_text_done_event.ResponseReasoningTextDoneEvent, response_refusal_delta_event.ResponseRefusalDeltaEvent, response_refusal_done_event.ResponseRefusalDoneEvent, response_text_delta_event.ResponseTextDeltaEvent, response_text_done_event.ResponseTextDoneEvent, response_web_search_call_completed_event.ResponseWebSearchCallCompletedEvent, response_web_search_call_in_progress_event.ResponseWebSearchCallInProgressEvent, response_web_search_call_searching_event.ResponseWebSearchCallSearchingEvent, response_image_gen_call_completed_event.ResponseImageGenCallCompletedEvent, response_image_gen_call_generating_event.ResponseImageGenCallGeneratingEvent, response_image_gen_call_in_progress_event.ResponseImageGenCallInProgressEvent, response_image_gen_call_partial_image_event.ResponseImageGenCallPartialImageEvent, response_mcp_call_arguments_delta_event.ResponseMcpCallArgumentsDeltaEvent, response_mcp_call_arguments_done_event.ResponseMcpCallArgumentsDoneEvent, response_mcp_call_completed_event.ResponseMcpCallCompletedEvent, response_mcp_call_failed_event.ResponseMcpCallFailedEvent, response_mcp_call_in_progress_event.ResponseMcpCallInProgressEvent, response_mcp_list_tools_completed_event.ResponseMcpListToolsCompletedEvent, response_mcp_list_tools_failed_event.ResponseMcpListToolsFailedEvent, response_mcp_list_tools_in_progress_event.ResponseMcpListToolsInProgressEvent, response_output_text_annotation_added_event.ResponseOutputTextAnnotationAddedEvent, response_queued_event.ResponseQueuedEvent, response_custom_tool_call_input_delta_event.ResponseCustomToolCallInputDeltaEvent, response_custom_tool_call_input_done_event.ResponseCustomToolCallInputDoneEvent], PropertyInfo(alias='None', format=None, format_template='None', discriminator='type')]]

Async variant with the same parameters. Returns ResponseResource | Response | AsyncIterator[ResponseStreamEvent].

async def aresponses(
model: str,
input_data: str | list[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | ComputerCallOutput | ResponseFunctionWebSearchParam | ResponseFunctionToolCallParam | FunctionCallOutput | ToolSearchCall | ResponseToolSearchOutputItemParamParam | ResponseReasoningItemParam | ResponseCompactionItemParamParam | ImageGenerationCall | ResponseCodeInterpreterToolCallParam | LocalShellCall | LocalShellCallOutput | ShellCall | ShellCallOutput | ApplyPatchCall | ApplyPatchCallOutput | McpListTools | McpApprovalRequest | McpApprovalResponse | McpCall | ResponseCustomToolCallOutputParam | ResponseCustomToolCallParam | ItemReference],
*,
provider: str | LLMProvider | None = None,
tools: list[dict[str, Any] | Callable[..., Any]] | None = None,
tool_choice: str | dict[str, Any] | None = None,
max_output_tokens: int | None = None,
temperature: float | None = None,
top_p: float | None = None,
stream: bool | None = None,
api_key: str | None = None,
api_base: str | None = None,
instructions: str | None = None,
max_tool_calls: int | None = None,
parallel_tool_calls: int | None = None,
reasoning: Any | None = None,
text: Any | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
truncation: str | None = None,
store: bool | None = None,
service_tier: str | None = None,
user: str | None = None,
metadata: dict[str, str] | None = None,
previous_response_id: str | None = None,
include: list[str] | None = None,
background: bool | None = None,
safety_identifier: str | None = None,
prompt_cache_key: str | None = None,
prompt_cache_retention: str | None = None,
conversation: str | dict[str, Any] | None = None,
client_args: dict[str, Any] | None = None,
**kwargs: Any,
) -> types.ResponseResource | response.Response | AsyncIterator[Annotated[Union[response_audio_delta_event.ResponseAudioDeltaEvent, response_audio_done_event.ResponseAudioDoneEvent, response_audio_transcript_delta_event.ResponseAudioTranscriptDeltaEvent, response_audio_transcript_done_event.ResponseAudioTranscriptDoneEvent, response_code_interpreter_call_code_delta_event.ResponseCodeInterpreterCallCodeDeltaEvent, response_code_interpreter_call_code_done_event.ResponseCodeInterpreterCallCodeDoneEvent, response_code_interpreter_call_completed_event.ResponseCodeInterpreterCallCompletedEvent, response_code_interpreter_call_in_progress_event.ResponseCodeInterpreterCallInProgressEvent, response_code_interpreter_call_interpreting_event.ResponseCodeInterpreterCallInterpretingEvent, response_completed_event.ResponseCompletedEvent, response_content_part_added_event.ResponseContentPartAddedEvent, response_content_part_done_event.ResponseContentPartDoneEvent, response_created_event.ResponseCreatedEvent, response_error_event.ResponseErrorEvent, response_file_search_call_completed_event.ResponseFileSearchCallCompletedEvent, response_file_search_call_in_progress_event.ResponseFileSearchCallInProgressEvent, response_file_search_call_searching_event.ResponseFileSearchCallSearchingEvent, response_function_call_arguments_delta_event.ResponseFunctionCallArgumentsDeltaEvent, response_function_call_arguments_done_event.ResponseFunctionCallArgumentsDoneEvent, response_in_progress_event.ResponseInProgressEvent, response_failed_event.ResponseFailedEvent, response_incomplete_event.ResponseIncompleteEvent, response_output_item_added_event.ResponseOutputItemAddedEvent, response_output_item_done_event.ResponseOutputItemDoneEvent, response_reasoning_summary_part_added_event.ResponseReasoningSummaryPartAddedEvent, response_reasoning_summary_part_done_event.ResponseReasoningSummaryPartDoneEvent, response_reasoning_summary_text_delta_event.ResponseReasoningSummaryTextDeltaEvent, response_reasoning_summary_text_done_event.ResponseReasoningSummaryTextDoneEvent, response_reasoning_text_delta_event.ResponseReasoningTextDeltaEvent, response_reasoning_text_done_event.ResponseReasoningTextDoneEvent, response_refusal_delta_event.ResponseRefusalDeltaEvent, response_refusal_done_event.ResponseRefusalDoneEvent, response_text_delta_event.ResponseTextDeltaEvent, response_text_done_event.ResponseTextDoneEvent, response_web_search_call_completed_event.ResponseWebSearchCallCompletedEvent, response_web_search_call_in_progress_event.ResponseWebSearchCallInProgressEvent, response_web_search_call_searching_event.ResponseWebSearchCallSearchingEvent, response_image_gen_call_completed_event.ResponseImageGenCallCompletedEvent, response_image_gen_call_generating_event.ResponseImageGenCallGeneratingEvent, response_image_gen_call_in_progress_event.ResponseImageGenCallInProgressEvent, response_image_gen_call_partial_image_event.ResponseImageGenCallPartialImageEvent, response_mcp_call_arguments_delta_event.ResponseMcpCallArgumentsDeltaEvent, response_mcp_call_arguments_done_event.ResponseMcpCallArgumentsDoneEvent, response_mcp_call_completed_event.ResponseMcpCallCompletedEvent, response_mcp_call_failed_event.ResponseMcpCallFailedEvent, response_mcp_call_in_progress_event.ResponseMcpCallInProgressEvent, response_mcp_list_tools_completed_event.ResponseMcpListToolsCompletedEvent, response_mcp_list_tools_failed_event.ResponseMcpListToolsFailedEvent, response_mcp_list_tools_in_progress_event.ResponseMcpListToolsInProgressEvent, response_output_text_annotation_added_event.ResponseOutputTextAnnotationAddedEvent, response_queued_event.ResponseQueuedEvent, response_custom_tool_call_input_delta_event.ResponseCustomToolCallInputDeltaEvent, response_custom_tool_call_input_done_event.ResponseCustomToolCallInputDoneEvent], PropertyInfo(alias='None', format=None, format_template='None', discriminator='type')]]
ParameterTypeDefaultDescription
modelstrrequiredModel identifier. Recommended: Use with separate provider parameter (e.g., model=‘gpt-4o’, provider=‘openai’). Alternative: Combined format ‘provider:model’ (e.g., ‘openai:gpt-4o’). Legacy format ‘provider/model’ is also supported but deprecated.
input_datastr | list[EasyInputMessageParam | Message | ResponseOutputMessageParam | ResponseFileSearchToolCallParam | ResponseComputerToolCallParam | ComputerCallOutput | ResponseFunctionWebSearchParam | ResponseFunctionToolCallParam | FunctionCallOutput | ToolSearchCall | ResponseToolSearchOutputItemParamParam | ResponseReasoningItemParam | ResponseCompactionItemParamParam | ImageGenerationCall | ResponseCodeInterpreterToolCallParam | LocalShellCall | LocalShellCallOutput | ShellCall | ShellCallOutput | ApplyPatchCall | ApplyPatchCallOutput | McpListTools | McpApprovalRequest | McpApprovalResponse | McpCall | ResponseCustomToolCallOutputParam | ResponseCustomToolCallParam | ItemReference]requiredThe input payload accepted by provider’s Responses API. For OpenAI-compatible providers, this is typically a list mixing text, images, and tool instructions, or a dict per OpenAI spec.
providerstr | LLMProvider | NoneNoneRecommended: Provider name to use for the request (e.g., ‘openai’, ‘mistral’). When provided, the model parameter should contain only the model name.
toolslist[dict[str, Any] | Callable[..., Any]] | NoneNoneOptional tools for tool calling (Python callables or OpenAI tool dicts)
tool_choicestr | dict[str, Any] | NoneNoneControls which tools the model can call
max_output_tokensint | NoneNoneMaximum number of output tokens to generate
temperaturefloat | NoneNoneControls randomness in the response (0.0 to 2.0)
top_pfloat | NoneNoneControls diversity via nucleus sampling (0.0 to 1.0)
streambool | NoneNoneWhether to stream response events
api_keystr | NoneNoneAPI key for the provider
api_basestr | NoneNoneBase URL for the provider API
instructionsstr | NoneNoneA system (or developer) message inserted into the model’s context.
max_tool_callsint | NoneNoneThe maximum number of total calls to built-in tools that can be processed in a response. This maximum number applies across all built-in tool calls, not per individual tool. Any further attempts to call a tool by the model will be ignored.
parallel_tool_callsint | NoneNoneWhether to allow the model to run tool calls in parallel.
reasoningAny | NoneNoneConfiguration options for reasoning models.
textAny | NoneNoneConfiguration options for a text response from the model. Can be plain text or structured JSON data.
presence_penaltyfloat | NoneNonePenalizes new tokens based on whether they appear in the text so far.
frequency_penaltyfloat | NoneNonePenalizes new tokens based on their frequency in the text so far.
truncationstr | NoneNoneControls how the service truncates input when it exceeds the model context window.
storebool | NoneNoneWhether to store the response so it can be retrieved later.
service_tierstr | NoneNoneThe service tier to use for this request.
userstr | NoneNoneA unique identifier representing your end user.
metadatadict[str, str] | NoneNoneKey-value pairs for custom metadata (up to 16 pairs).
previous_response_idstr | NoneNoneThe ID of the response to use as the prior turn for this request.
includelist[str] | NoneNoneItems to include in the response (e.g., ‘reasoning.encrypted_content’).
backgroundbool | NoneNoneWhether to run the request in the background and return immediately.
safety_identifierstr | NoneNoneA stable identifier used for safety monitoring and abuse detection.
prompt_cache_keystr | NoneNoneA key to use when reading from or writing to the prompt cache.
prompt_cache_retentionstr | NoneNoneHow long to retain a prompt cache entry created by this request.
conversationstr | dict[str, Any] | NoneNoneThe conversation to associate this response with (ID string or ConversationParam object).
client_argsdict[str, Any] | NoneNoneAdditional provider-specific arguments that will be passed to the provider’s client instantiation.
**kwargsAnyrequiredAdditional provider-specific arguments that will be passed to the provider’s API call.
from any_llm import responses
result = responses(
model="gpt-4.1-mini",
provider="openai",
input_data="What is the capital of France?",
)
print(result.output_text)
result = responses(
model="gpt-4.1-mini",
provider="openai",
input_data="Translate to French: Hello, how are you?",
instructions="You are a professional translator. Always respond with only the translation.",
)
for event in responses(
model="gpt-4.1-mini",
provider="openai",
input_data="Tell me a short story.",
stream=True,
):
print(event)
first = responses(
model="gpt-4.1-mini",
provider="openai",
input_data="My name is Alice.",
store=True,
)
second = responses(
model="gpt-4.1-mini",
provider="openai",
input_data="What is my name?",
previous_response_id=first.id,
)