Class ResponsesEndpoint
OpenAI's most advanced interface for generating model responses. Supports text and image inputs, and text outputs. Create stateful interactions with the model, using the output of previous responses as input. Extend the model's capabilities with built-in tools for file search, web search, computer use, and more. Allow the model access to external systems and data using function calling.
public sealed class ResponsesEndpoint : OpenAIBaseEndpoint
- Inheritance
-
ResponsesEndpoint
- Inherited Members
Constructors
ResponsesEndpoint(OpenAIClient)
public ResponsesEndpoint(OpenAIClient client)
Parameters
client
OpenAIClient
Properties
Root
The root endpoint address.
protected override string Root { get; }
Property Value
Methods
CancelModelResponsesAsync(string, CancellationToken)
Cancels a model response with the given ID.
public Task<Response> CancelModelResponsesAsync(string responseId, CancellationToken cancellationToken = default)
Parameters
responseId
stringThe ID of the response to cancel.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
Remarks
Only responses created with the background parameter set to true can be cancelled.
CreateModelResponseAsync(CreateResponseRequest, Func<IServerSentEvent, Task>, CancellationToken)
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.
public Task<Response> CreateModelResponseAsync(CreateResponseRequest request, Func<IServerSentEvent, Task> streamEventHandler, CancellationToken cancellationToken = default)
Parameters
request
CreateResponseRequeststreamEventHandler
Func<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
CreateModelResponseAsync(CreateResponseRequest, Func<string, IServerSentEvent, Task>, CancellationToken)
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.
public Task<Response> CreateModelResponseAsync(CreateResponseRequest request, Func<string, IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
request
CreateResponseRequeststreamEventHandler
Func<string, IServerSentEvent, Task>Optional, Func<T1, T2, TResult> stream callback handler.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
CreateModelResponseAsync<T>(CreateResponseRequest, Func<IServerSentEvent, Task>, CancellationToken)
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.
public Task<(T, Response)> CreateModelResponseAsync<T>(CreateResponseRequest request, Func<IServerSentEvent, Task> streamEventHandler, CancellationToken cancellationToken = default)
Parameters
request
CreateResponseRequeststreamEventHandler
Func<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
Type Parameters
CreateModelResponseAsync<T>(CreateResponseRequest, Func<string, IServerSentEvent, Task>, CancellationToken)
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.
public Task<(T, Response)> CreateModelResponseAsync<T>(CreateResponseRequest request, Func<string, IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
request
CreateResponseRequeststreamEventHandler
Func<string, IServerSentEvent, Task>Optional, Func<T1, T2, TResult> stream callback handler.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
Type Parameters
DeleteModelResponseAsync(string, CancellationToken)
Deletes a model response with the given ID.
public Task<bool> DeleteModelResponseAsync(string responseId, CancellationToken cancellationToken = default)
Parameters
responseId
stringThe ID of the response to delete.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
GetModelResponseAsync(string, CancellationToken, params string[])
Retrieves a model response with the given ID.
public Task<Response> GetModelResponseAsync(string responseId, CancellationToken cancellationToken = default, params string[] include)
Parameters
responseId
stringThe ID of the response to retrieve.
cancellationToken
CancellationTokenOptional, CancellationToken.
include
string[]Additional fields to include in the response.
Currently supported values are:- file_search_call.results: Include the search results of the file search tool call.
- message.input_image.image_url: Include image URLs from the computer call output.
- computer_call_output.output.image_url: Include image urls from the computer call output.
- file_search_call.results: Include the search results of the file search tool call.
Returns
ListInputItemsAsync(string, ListQuery, CancellationToken)
Returns a list of input items for a given response.
public Task<ListResponse<IResponseItem>> ListInputItemsAsync(string responseId, ListQuery query = null, CancellationToken cancellationToken = default)
Parameters
responseId
stringThe ID of the response to retrieve input items for.
query
ListQuerycancellationToken
CancellationTokenOptional, CancellationToken.