View Source ExOpenAI.Responses (ex_openai.ex v1.8.0)
Modules for interacting with the responses
group of OpenAI APIs
API Reference: https://platform.openai.com/docs/api-reference/responses
Summary
Functions
Creates a model response. Provide text or image inputs to generate text or JSON outputs. Have the model call your own custom code or use built-in tools like web search or file search to use your own data as input for the model's response.
Deletes a model response with the given ID.
Retrieves a model response with the given ID.
Returns a list of input items for a given response.
Functions
@spec create_response( [ExOpenAI.Components.InputItem.t()] | String.t(), (:"gpt-3.5-turbo-16k-0613" | :"gpt-3.5-turbo-0125" | :"gpt-3.5-turbo-1106" | :"gpt-3.5-turbo-0613" | :"gpt-3.5-turbo-0301" | :"gpt-3.5-turbo-16k" | :"gpt-3.5-turbo" | :"gpt-4-32k-0613" | :"gpt-4-32k-0314" | :"gpt-4-32k" | :"gpt-4-0613" | :"gpt-4-0314" | :"gpt-4" | :"gpt-4-vision-preview" | :"gpt-4-1106-preview" | :"gpt-4-turbo-preview" | :"gpt-4-0125-preview" | :"gpt-4-turbo-2024-04-09" | :"gpt-4-turbo" | :"gpt-4o-mini-2024-07-18" | :"gpt-4o-mini" | :"chatgpt-4o-latest" | :"gpt-4o-mini-audio-preview-2024-12-17" | :"gpt-4o-mini-audio-preview" | :"gpt-4o-audio-preview-2024-12-17" | :"gpt-4o-audio-preview-2024-10-01" | :"gpt-4o-audio-preview" | :"gpt-4o-2024-05-13" | :"gpt-4o-2024-08-06" | :"gpt-4o-2024-11-20" | :"gpt-4o" | :"gpt-4.5-preview-2025-02-27" | :"gpt-4.5-preview" | :"computer-use-preview-2025-03-11" | :"computer-use-preview-2025-02-04" | :"computer-use-preview" | :"o1-mini-2024-09-12" | :"o1-mini" | :"o1-preview-2024-09-12" | :"o1-preview" | :"o1-2024-12-17" | :o1 | :"o3-mini-2025-01-31" | :"o3-mini") | String.t(), base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), user: String.t(), top_p: float(), temperature: float(), metadata: ExOpenAI.Components.Metadata.t(), truncation: :disabled | :auto, tools: [ExOpenAI.Components.Tool.t()], tool_choice: ExOpenAI.Components.ToolChoiceFunction.t() | ExOpenAI.Components.ToolChoiceTypes.t() | ExOpenAI.Components.ToolChoiceOptions.t(), text: %{format: ExOpenAI.Components.TextResponseFormatConfiguration.t()}, reasoning: ExOpenAI.Components.Reasoning.t(), previous_response_id: String.t(), max_output_tokens: integer(), instructions: String.t(), stream: boolean(), store: boolean(), parallel_tool_calls: boolean(), include: [ExOpenAI.Components.Includable.t()], stream_to: (... -> any()) | pid() ) :: ({:ok, ExOpenAI.Components.ResponseStreamEvent.t()} | {:ok, ExOpenAI.Components.Response.t()}) | {:error, any()}
Creates a model response. Provide text or image inputs to generate text or JSON outputs. Have the model call your own custom code or use built-in tools like web search or file search to use your own data as input for the model's response.
Endpoint: https://api.openai.com/v1/responses
Method: POST
Docs: https://platform.openai.com/docs/api-reference/responses
Required Arguments:
input
: Text, image, or file inputs to the model, used to generate a response.
Learn more:
model
: Model ID used to generate the response, likegpt-4o
oro1
. OpenAI offers a wide range of models with different capabilities, performance characteristics, and price points. Refer to the model guide to browse and compare available models.
Optional Arguments:
stream_to
: "PID or function of where to stream content to"include
: %{"$ref" => "#/components/schemas/Includable/description"}parallel_tool_calls
: "Whether to allow the model to run tool calls in parallel.\n"store
: "Whether to store the generated model response for later retrieval via\nAPI.\n"stream
: "If set to true, the model response data will be streamed to the client\nas it is generated using server-sent events.\nSee the Streaming section below\nfor more information.\n"instructions
: "Inserts a system (or developer) message as the first item in the model's context.\n\nWhen using along withprevious_response_id
, the instructions from a previous\nresponse will be not be carried over to the next response. This makes it simple\nto swap out system (or developer) messages in new responses.\n"max_output_tokens
: "An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.\n"previous_response_id
: "The unique ID of the previous response to the model. Use this to\ncreate multi-turn conversations. Learn more about \nconversation state.\n"reasoning
: ""text
: "Configuration options for a text response from the model. Can be plain\ntext or structured JSON data. Learn more:\n- Text inputs and outputs\n- Structured Outputs\n"tool_choice
: "How the model should select which tool (or tools) to use when generating\na response. See thetools
parameter to see how to specify which tools\nthe model can call.\n"tools
: "An array of tools the model may call while generating a response. You \ncan specify which tool to use by setting thetool_choice
parameter.\n\nThe two categories of tools you can provide the model are:\n\n- Built-in tools: Tools that are provided by OpenAI that extend the\n model's capabilities, like web search\n or file search. Learn more about\n built-in tools.\n- Function calls (custom tools): Functions that are defined by you,\n enabling the model to call your own code. Learn more about\n function calling.\n"truncation
: "The truncation strategy to use for the model response.\n-auto
: If the context of this response and previous ones exceeds\n the model's context window size, the model will truncate the \n response to fit the context window by dropping input items in the\n middle of the conversation. \n-disabled
(default): If a model response will exceed the context window \n size for a model, the request will fail with a 400 error.\n"metadata
: ""temperature
: "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.\nWe generally recommend altering this ortop_p
but not both.\n"
Example: 1
top_p
: "An alternative to sampling with temperature, called nucleus sampling,\nwhere the model considers the results of the tokens with top_p probability\nmass. So 0.1 means only the tokens comprising the top 10% probability mass\nare considered.\n\nWe generally recommend altering this ortemperature
but not both.\n"
Example: 1
user
: "A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.\n"
Example: "user-1234"
openai_api_key
: "OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value."openai_organization_key
: "OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value."base_url
: "Which API endpoint to use as base, defaults to https://api.openai.com/v1"
@spec delete_response(String.t(), base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, nil} | {:error, any()}
Deletes a model response with the given ID.
Endpoint: https://api.openai.com/v1/responses/{response_id}
Method: DELETE
Docs: https://platform.openai.com/docs/api-reference/responses
Required Arguments:
response_id
Example: resp_677efb5139a88190b512bc3fef8e535d
Optional Arguments:
openai_api_key
: "OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value."openai_organization_key
: "OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value."base_url
: "Which API endpoint to use as base, defaults to https://api.openai.com/v1"
@spec get_response(String.t(), base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), include: list(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.Response.t()} | {:error, any()}
Retrieves a model response with the given ID.
Endpoint: https://api.openai.com/v1/responses/{response_id}
Method: GET
Docs: https://platform.openai.com/docs/api-reference/responses
Required Arguments:
response_id
Example: resp_677efb5139a88190b512bc3fef8e535d
Optional Arguments:
stream_to
: "PID or function of where to stream content to"include
openai_api_key
: "OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value."openai_organization_key
: "OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value."base_url
: "Which API endpoint to use as base, defaults to https://api.openai.com/v1"
@spec list_input_items(String.t(), base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), before: String.t(), after: String.t(), order: String.t(), limit: integer(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ResponseItemList.t()} | {:error, any()}
Returns a list of input items for a given response.
Endpoint: https://api.openai.com/v1/responses/{response_id}/input_items
Method: GET
Docs: https://platform.openai.com/docs/api-reference/responses
Required Arguments:
response_id
Optional Arguments:
stream_to
: "PID or function of where to stream content to"limit
order
after
before
openai_api_key
: "OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value."openai_organization_key
: "OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value."base_url
: "Which API endpoint to use as base, defaults to https://api.openai.com/v1"