Class Response.Builder
-
- All Implemented Interfaces:
public final class Response.Builder
A builder for Response.
-
-
Method Summary
Modifier and Type Method Description final Response.Builder
id(String id)
Unique identifier for this Response. final Response.Builder
id(JsonField<String> id)
Unique identifier for this Response. final Response.Builder
createdAt(Double createdAt)
Unix timestamp (in seconds) of when this Response was created. final Response.Builder
createdAt(JsonField<Double> createdAt)
Unix timestamp (in seconds) of when this Response was created. final Response.Builder
error(ResponseError error)
An error object returned when the model fails to generate a Response. final Response.Builder
error(Optional<ResponseError> error)
An error object returned when the model fails to generate a Response. final Response.Builder
error(JsonField<ResponseError> error)
An error object returned when the model fails to generate a Response. final Response.Builder
incompleteDetails(Response.IncompleteDetails incompleteDetails)
Details about why the response is incomplete. final Response.Builder
incompleteDetails(Optional<Response.IncompleteDetails> incompleteDetails)
Details about why the response is incomplete. final Response.Builder
incompleteDetails(JsonField<Response.IncompleteDetails> incompleteDetails)
Details about why the response is incomplete. final Response.Builder
instructions(String instructions)
Inserts a system (or developer) message as the first item in the model's context. final Response.Builder
instructions(Optional<String> instructions)
Inserts a system (or developer) message as the first item in the model's context. final Response.Builder
instructions(JsonField<String> instructions)
Inserts a system (or developer) message as the first item in the model's context. final Response.Builder
metadata(Metadata metadata)
Set of 16 key-value pairs that can be attached to an object. final Response.Builder
metadata(Optional<Metadata> metadata)
Set of 16 key-value pairs that can be attached to an object. final Response.Builder
metadata(JsonField<Metadata> metadata)
Set of 16 key-value pairs that can be attached to an object. final Response.Builder
model(ChatModel model)
Model ID used to generate the response, like gpt-4o
oro1
.final Response.Builder
model(JsonField<ChatModel> model)
Model ID used to generate the response, like gpt-4o
oro1
.final Response.Builder
model(String value)
Model ID used to generate the response, like gpt-4o
oro1
.final Response.Builder
object_(JsonValue object_)
The object type of this resource - always set to response
.final Response.Builder
output(List<ResponseOutputItem> output)
An array of content items generated by the model. final Response.Builder
output(JsonField<List<ResponseOutputItem>> output)
An array of content items generated by the model. final Response.Builder
addOutput(ResponseOutputItem output)
An array of content items generated by the model. final Response.Builder
addOutput(ResponseOutputMessage message)
An output message from the model. final Response.Builder
addOutput(ResponseFileSearchToolCall fileSearchCall)
The results of a file search tool call. final Response.Builder
addOutput(ResponseFunctionToolCall functionCall)
A tool call to run a function. final Response.Builder
addOutput(ResponseFunctionWebSearch webSearchCall)
The results of a web search tool call. final Response.Builder
addOutput(ResponseComputerToolCall computerCall)
A tool call to a computer use tool. final Response.Builder
addOutput(ResponseReasoningItem reasoning)
A description of the chain of thought used by a reasoning model while generating a response. final Response.Builder
parallelToolCalls(Boolean parallelToolCalls)
Whether to allow the model to run tool calls in parallel. final Response.Builder
parallelToolCalls(JsonField<Boolean> parallelToolCalls)
Whether to allow the model to run tool calls in parallel. final Response.Builder
temperature(Double temperature)
What sampling temperature to use, between 0 and 2. final Response.Builder
temperature(Double temperature)
What sampling temperature to use, between 0 and 2. final Response.Builder
temperature(Optional<Double> temperature)
What sampling temperature to use, between 0 and 2. final Response.Builder
temperature(JsonField<Double> temperature)
What sampling temperature to use, between 0 and 2. final Response.Builder
toolChoice(Response.ToolChoice toolChoice)
How the model should select which tool (or tools) to use when generating a response. final Response.Builder
toolChoice(JsonField<Response.ToolChoice> toolChoice)
How the model should select which tool (or tools) to use when generating a response. final Response.Builder
toolChoice(ToolChoiceOptions options)
Controls which (if any) tool is called by the model. final Response.Builder
toolChoice(ToolChoiceTypes types)
Indicates that the model should use a built-in tool to generate a response. final Response.Builder
toolChoice(ToolChoiceFunction function)
Use this option to force the model to call a specific function. final Response.Builder
tools(List<Tool> tools)
An array of tools the model may call while generating a response. final Response.Builder
tools(JsonField<List<Tool>> tools)
An array of tools the model may call while generating a response. final Response.Builder
addTool(Tool tool)
An array of tools the model may call while generating a response. final Response.Builder
addTool(FileSearchTool fileSearch)
A tool that searches for relevant content from uploaded files. final Response.Builder
addTool(FunctionTool function)
Defines a function in your own code the model can choose to call. final Response.Builder
addTool(ComputerTool computerUsePreview)
A tool that controls a virtual computer. final Response.Builder
addTool(WebSearchTool webSearch)
This tool searches the web for relevant results to use in a response. final Response.Builder
addFileSearchTool(List<String> vectorStoreIds)
A tool that searches for relevant content from uploaded files. final Response.Builder
topP(Double topP)
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. final Response.Builder
topP(Double topP)
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. final Response.Builder
topP(Optional<Double> topP)
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. final Response.Builder
topP(JsonField<Double> topP)
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. final Response.Builder
maxOutputTokens(Long maxOutputTokens)
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens. final Response.Builder
maxOutputTokens(Long maxOutputTokens)
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens. final Response.Builder
maxOutputTokens(Optional<Long> maxOutputTokens)
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens. final Response.Builder
maxOutputTokens(JsonField<Long> maxOutputTokens)
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens. final Response.Builder
previousResponseId(String previousResponseId)
The unique ID of the previous response to the model. final Response.Builder
previousResponseId(Optional<String> previousResponseId)
The unique ID of the previous response to the model. final Response.Builder
previousResponseId(JsonField<String> previousResponseId)
The unique ID of the previous response to the model. final Response.Builder
reasoning(Reasoning reasoning)
o-series models onlyConfiguration options for reasoning models. final Response.Builder
reasoning(Optional<Reasoning> reasoning)
o-series models onlyConfiguration options for reasoning models. final Response.Builder
reasoning(JsonField<Reasoning> reasoning)
o-series models onlyConfiguration options for reasoning models. final Response.Builder
status(ResponseStatus status)
The status of the response generation. final Response.Builder
status(JsonField<ResponseStatus> status)
The status of the response generation. final Response.Builder
text(ResponseTextConfig text)
Configuration options for a text response from the model. final Response.Builder
text(JsonField<ResponseTextConfig> text)
Configuration options for a text response from the model. final Response.Builder
truncation(Response.Truncation truncation)
The truncation strategy to use for the model response. final Response.Builder
truncation(Optional<Response.Truncation> truncation)
The truncation strategy to use for the model response. final Response.Builder
truncation(JsonField<Response.Truncation> truncation)
The truncation strategy to use for the model response. final Response.Builder
usage(ResponseUsage usage)
Represents token usage details including input tokens, output tokens, a breakdown of output tokens, and the total tokens used. final Response.Builder
usage(JsonField<ResponseUsage> usage)
Represents token usage details including input tokens, output tokens, a breakdown of output tokens, and the total tokens used. final Response.Builder
user(String user)
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. final Response.Builder
user(JsonField<String> user)
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. final Response.Builder
additionalProperties(Map<String, JsonValue> additionalProperties)
final Response.Builder
putAdditionalProperty(String key, JsonValue value)
final Response.Builder
putAllAdditionalProperties(Map<String, JsonValue> additionalProperties)
final Response.Builder
removeAdditionalProperty(String key)
final Response.Builder
removeAllAdditionalProperties(Set<String> keys)
final Response
build()
-
-
Method Detail
-
id
final Response.Builder id(String id)
Unique identifier for this Response.
-
id
final Response.Builder id(JsonField<String> id)
Unique identifier for this Response.
-
createdAt
final Response.Builder createdAt(Double createdAt)
Unix timestamp (in seconds) of when this Response was created.
-
createdAt
final Response.Builder createdAt(JsonField<Double> createdAt)
Unix timestamp (in seconds) of when this Response was created.
-
error
final Response.Builder error(ResponseError error)
An error object returned when the model fails to generate a Response.
-
error
final Response.Builder error(Optional<ResponseError> error)
An error object returned when the model fails to generate a Response.
-
error
final Response.Builder error(JsonField<ResponseError> error)
An error object returned when the model fails to generate a Response.
-
incompleteDetails
final Response.Builder incompleteDetails(Response.IncompleteDetails incompleteDetails)
Details about why the response is incomplete.
-
incompleteDetails
final Response.Builder incompleteDetails(Optional<Response.IncompleteDetails> incompleteDetails)
Details about why the response is incomplete.
-
incompleteDetails
final Response.Builder incompleteDetails(JsonField<Response.IncompleteDetails> incompleteDetails)
Details about why the response is incomplete.
-
instructions
final Response.Builder instructions(String instructions)
Inserts a system (or developer) message as the first item in the model's context.
When using along with
previous_response_id
, the instructions from a previous response will be not be carried over to the next response. This makes it simple to swap out system (or developer) messages in new responses.
-
instructions
final Response.Builder instructions(Optional<String> instructions)
Inserts a system (or developer) message as the first item in the model's context.
When using along with
previous_response_id
, the instructions from a previous response will be not be carried over to the next response. This makes it simple to swap out system (or developer) messages in new responses.
-
instructions
final Response.Builder instructions(JsonField<String> instructions)
Inserts a system (or developer) message as the first item in the model's context.
When using along with
previous_response_id
, the instructions from a previous response will be not be carried over to the next response. This makes it simple to swap out system (or developer) messages in new responses.
-
metadata
final Response.Builder metadata(Metadata metadata)
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
metadata
final Response.Builder metadata(Optional<Metadata> metadata)
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
metadata
final Response.Builder metadata(JsonField<Metadata> metadata)
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
model
final Response.Builder model(ChatModel model)
Model ID used to generate the response, like
gpt-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.
-
model
final Response.Builder model(JsonField<ChatModel> model)
Model ID used to generate the response, like
gpt-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.
-
model
final Response.Builder model(String value)
Model ID used to generate the response, like
gpt-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.
-
object_
final Response.Builder object_(JsonValue object_)
The object type of this resource - always set to
response
.
-
output
final Response.Builder output(List<ResponseOutputItem> output)
An array of content items generated by the model.
The length and order of items in the
output
array is dependent on the model's response.Rather than accessing the first item in the
output
array and assuming it's anassistant
message with the content generated by the model, you might consider using theoutput_text
property where supported in SDKs.
-
output
final Response.Builder output(JsonField<List<ResponseOutputItem>> output)
An array of content items generated by the model.
The length and order of items in the
output
array is dependent on the model's response.Rather than accessing the first item in the
output
array and assuming it's anassistant
message with the content generated by the model, you might consider using theoutput_text
property where supported in SDKs.
-
addOutput
final Response.Builder addOutput(ResponseOutputItem output)
An array of content items generated by the model.
The length and order of items in the
output
array is dependent on the model's response.Rather than accessing the first item in the
output
array and assuming it's anassistant
message with the content generated by the model, you might consider using theoutput_text
property where supported in SDKs.
-
addOutput
final Response.Builder addOutput(ResponseOutputMessage message)
An output message from the model.
-
addOutput
final Response.Builder addOutput(ResponseFileSearchToolCall fileSearchCall)
The results of a file search tool call. See the file search guide for more information.
-
addOutput
final Response.Builder addOutput(ResponseFunctionToolCall functionCall)
A tool call to run a function. See the function calling guide for more information.
-
addOutput
final Response.Builder addOutput(ResponseFunctionWebSearch webSearchCall)
The results of a web search tool call. See the web search guide for more information.
-
addOutput
final Response.Builder addOutput(ResponseComputerToolCall computerCall)
A tool call to a computer use tool. See the computer use guide for more information.
-
addOutput
final Response.Builder addOutput(ResponseReasoningItem reasoning)
A description of the chain of thought used by a reasoning model while generating a response.
-
parallelToolCalls
final Response.Builder parallelToolCalls(Boolean parallelToolCalls)
Whether to allow the model to run tool calls in parallel.
-
parallelToolCalls
final Response.Builder parallelToolCalls(JsonField<Boolean> parallelToolCalls)
Whether to allow the model to run tool calls in parallel.
-
temperature
final Response.Builder temperature(Double 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. We generally recommend altering this or
top_p
but not both.
-
temperature
final Response.Builder temperature(Double 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. We generally recommend altering this or
top_p
but not both.
-
temperature
final Response.Builder temperature(Optional<Double> 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. We generally recommend altering this or
top_p
but not both.
-
temperature
final Response.Builder temperature(JsonField<Double> 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. We generally recommend altering this or
top_p
but not both.
-
toolChoice
final Response.Builder toolChoice(Response.ToolChoice toolChoice)
How the model should select which tool (or tools) to use when generating a response. See the
tools
parameter to see how to specify which tools the model can call.
-
toolChoice
final Response.Builder toolChoice(JsonField<Response.ToolChoice> toolChoice)
How the model should select which tool (or tools) to use when generating a response. See the
tools
parameter to see how to specify which tools the model can call.
-
toolChoice
final Response.Builder toolChoice(ToolChoiceOptions options)
Controls which (if any) tool is called by the model.
none
means the model will not call any tool and instead generates a message.auto
means the model can pick between generating a message or calling one or more tools.required
means the model must call one or more tools.
-
toolChoice
final Response.Builder toolChoice(ToolChoiceTypes types)
Indicates that the model should use a built-in tool to generate a response. Learn more about built-in tools.
-
toolChoice
final Response.Builder toolChoice(ToolChoiceFunction function)
Use this option to force the model to call a specific function.
-
tools
final Response.Builder tools(List<Tool> tools)
An array of tools the model may call while generating a response. You can specify which tool to use by setting the
tool_choice
parameter.The two categories of tools you can provide the model are:
Built-in tools: Tools that are provided by OpenAI that extend the model's capabilities, like web search or file search. Learn more about built-in tools.
Function calls (custom tools): Functions that are defined by you, enabling the model to call your own code. Learn more about function calling.
-
tools
final Response.Builder tools(JsonField<List<Tool>> tools)
An array of tools the model may call while generating a response. You can specify which tool to use by setting the
tool_choice
parameter.The two categories of tools you can provide the model are:
Built-in tools: Tools that are provided by OpenAI that extend the model's capabilities, like web search or file search. Learn more about built-in tools.
Function calls (custom tools): Functions that are defined by you, enabling the model to call your own code. Learn more about function calling.
-
addTool
final Response.Builder addTool(Tool tool)
An array of tools the model may call while generating a response. You can specify which tool to use by setting the
tool_choice
parameter.The two categories of tools you can provide the model are:
Built-in tools: Tools that are provided by OpenAI that extend the model's capabilities, like web search or file search. Learn more about built-in tools.
Function calls (custom tools): Functions that are defined by you, enabling the model to call your own code. Learn more about function calling.
-
addTool
final Response.Builder addTool(FileSearchTool fileSearch)
A tool that searches for relevant content from uploaded files. Learn more about the file search tool.
-
addTool
final Response.Builder addTool(FunctionTool function)
Defines a function in your own code the model can choose to call. Learn more about function calling.
-
addTool
final Response.Builder addTool(ComputerTool computerUsePreview)
A tool that controls a virtual computer. Learn more about the computer tool.
-
addTool
final Response.Builder addTool(WebSearchTool webSearch)
This tool searches the web for relevant results to use in a response. Learn more about the web search tool.
-
addFileSearchTool
final Response.Builder addFileSearchTool(List<String> vectorStoreIds)
A tool that searches for relevant content from uploaded files. Learn more about the file search tool.
-
topP
final Response.Builder topP(Double topP)
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
We generally recommend altering this or
temperature
but not both.
-
topP
final Response.Builder topP(Double topP)
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
We generally recommend altering this or
temperature
but not both.
-
topP
final Response.Builder topP(Optional<Double> topP)
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
We generally recommend altering this or
temperature
but not both.
-
topP
final Response.Builder topP(JsonField<Double> topP)
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
We generally recommend altering this or
temperature
but not both.
-
maxOutputTokens
final Response.Builder maxOutputTokens(Long maxOutputTokens)
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.
-
maxOutputTokens
final Response.Builder maxOutputTokens(Long maxOutputTokens)
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.
-
maxOutputTokens
final Response.Builder maxOutputTokens(Optional<Long> maxOutputTokens)
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.
-
maxOutputTokens
final Response.Builder maxOutputTokens(JsonField<Long> maxOutputTokens)
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.
-
previousResponseId
final Response.Builder previousResponseId(String previousResponseId)
The unique ID of the previous response to the model. Use this to create multi-turn conversations. Learn more about conversation state.
-
previousResponseId
final Response.Builder previousResponseId(Optional<String> previousResponseId)
The unique ID of the previous response to the model. Use this to create multi-turn conversations. Learn more about conversation state.
-
previousResponseId
final Response.Builder previousResponseId(JsonField<String> previousResponseId)
The unique ID of the previous response to the model. Use this to create multi-turn conversations. Learn more about conversation state.
-
reasoning
final Response.Builder reasoning(Reasoning reasoning)
o-series models only
Configuration options for reasoning models.
-
reasoning
final Response.Builder reasoning(Optional<Reasoning> reasoning)
o-series models only
Configuration options for reasoning models.
-
reasoning
final Response.Builder reasoning(JsonField<Reasoning> reasoning)
o-series models only
Configuration options for reasoning models.
-
status
final Response.Builder status(ResponseStatus status)
The status of the response generation. One of
completed
,failed
,in_progress
, orincomplete
.
-
status
final Response.Builder status(JsonField<ResponseStatus> status)
The status of the response generation. One of
completed
,failed
,in_progress
, orincomplete
.
-
text
final Response.Builder text(ResponseTextConfig text)
Configuration options for a text response from the model. Can be plain text or structured JSON data. Learn more:
-
text
final Response.Builder text(JsonField<ResponseTextConfig> text)
Configuration options for a text response from the model. Can be plain text or structured JSON data. Learn more:
-
truncation
final Response.Builder truncation(Response.Truncation truncation)
The truncation strategy to use for the model response.
auto
: If the context of this response and previous ones exceeds the model's context window size, the model will truncate the response to fit the context window by dropping input items in the middle of the conversation.disabled
(default): If a model response will exceed the context window size for a model, the request will fail with a 400 error.
-
truncation
final Response.Builder truncation(Optional<Response.Truncation> truncation)
The truncation strategy to use for the model response.
auto
: If the context of this response and previous ones exceeds the model's context window size, the model will truncate the response to fit the context window by dropping input items in the middle of the conversation.disabled
(default): If a model response will exceed the context window size for a model, the request will fail with a 400 error.
-
truncation
final Response.Builder truncation(JsonField<Response.Truncation> truncation)
The truncation strategy to use for the model response.
auto
: If the context of this response and previous ones exceeds the model's context window size, the model will truncate the response to fit the context window by dropping input items in the middle of the conversation.disabled
(default): If a model response will exceed the context window size for a model, the request will fail with a 400 error.
-
usage
final Response.Builder usage(ResponseUsage usage)
Represents token usage details including input tokens, output tokens, a breakdown of output tokens, and the total tokens used.
-
usage
final Response.Builder usage(JsonField<ResponseUsage> usage)
Represents token usage details including input tokens, output tokens, a breakdown of output tokens, and the total tokens used.
-
user
final Response.Builder user(String user)
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
-
user
final Response.Builder user(JsonField<String> user)
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
-
additionalProperties
final Response.Builder additionalProperties(Map<String, JsonValue> additionalProperties)
-
putAdditionalProperty
final Response.Builder putAdditionalProperty(String key, JsonValue value)
-
putAllAdditionalProperties
final Response.Builder putAllAdditionalProperties(Map<String, JsonValue> additionalProperties)
-
removeAdditionalProperty
final Response.Builder removeAdditionalProperty(String key)
-
removeAllAdditionalProperties
final Response.Builder removeAllAdditionalProperties(Set<String> keys)
-
-
-
-