Record Class OpenAiApi.ChatCompletionRequest
java.lang.Object
java.lang.Record
org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest
- Record Components:
messages- A list of messages comprising the conversation so far.model- ID of the model to use.store- Whether to store the output of this chat completion request for use in OpenAI's model distillation or evals products.metadata- Developer-defined tags and values used for filtering completions in the OpenAI's dashboard.frequencyPenalty- Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.logitBias- Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.logprobs- Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the 'content' of 'message'.topLogprobs- An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to 'true' if this parameter is used.maxTokens- The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API. This value is now deprecated in favor of max_completion_tokens, and is not compatible with o1 series models. The field is retained for use with other openai models and openai compatible models.maxCompletionTokens- An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.n- How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all the choices. Keep n as 1 to minimize costs.outputModalities- Output types that you would like the model to generate for this request. Most models are capable of generating text, which is the default: ["text"]. The gpt-4o-audio-preview model can also be used to generate audio. To request that this model generate both text and audio responses, you can use: ["text", "audio"].audioParameters- Parameters for audio output. Required when audio output is requested with outputModalities: ["audio"].presencePenalty- Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.responseFormat- An object specifying the format that the model must output. Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.seed- This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.serviceTier- Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service. When this parameter is set, the response body will include the service_tier utilized.stop- Up to 4 sequences where the API will stop generating further tokens.stream- If set, partial message deltas will be sent.Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.streamOptions- Options for streaming response. Only set this when you set.temperature- What sampling temperature to use, between 0 and 1. 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.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.tools- A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.toolChoice- Controls which (if any) function is called by the model. none means the model will not call a function and instead generates a message. auto means the model can pick between generating a message or calling a function. Specifying a particular function via {"type: "function", "function": {"name": "my_function"}} forces the model to call that function. none is the default when no functions are present. auto is the default if functions are present. Use theOpenAiApi.ChatCompletionRequest.ToolChoiceBuilderto create the tool choice value.parallelToolCalls- If set to true, the model will call all functions in the tools list in parallel. Otherwise, the model will call the functions in the tools list in the order they are provided.user- A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.reasoningEffort- Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.webSearchOptions- Options for web search.verbosity- Controls the verbosity of the model's response.
- Enclosing class:
OpenAiApi
public static record OpenAiApi.ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Boolean store, Map<String,String> metadata, Double frequencyPenalty, Map<String,Integer> logitBias, Boolean logprobs, Integer topLogprobs, Integer maxTokens, Integer maxCompletionTokens, Integer n, List<OpenAiApi.OutputModality> outputModalities, OpenAiApi.ChatCompletionRequest.AudioParameters audioParameters, Double presencePenalty, ResponseFormat responseFormat, Integer seed, String serviceTier, List<String> stop, Boolean stream, OpenAiApi.ChatCompletionRequest.StreamOptions streamOptions, Double temperature, Double topP, List<OpenAiApi.FunctionTool> tools, Object toolChoice, Boolean parallelToolCalls, String user, String reasoningEffort, OpenAiApi.ChatCompletionRequest.WebSearchOptions webSearchOptions, String verbosity, String promptCacheKey, String safetyIdentifier, Map<String,Object> extraBody)
extends Record
Creates a model request for the given chat conversation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordParameters for audio output.static final recordstatic classHelper factory that creates a tool_choice of type 'none', 'auto' or selected function by name.static final recordThis tool searches the web for relevant results to use in a response. -
Constructor Summary
ConstructorsConstructorDescriptionChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, Boolean stream) Shortcut constructor for a chat completion request with the given messages for streaming.ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Boolean store, Map<String, String> metadata, Double frequencyPenalty, Map<String, Integer> logitBias, Boolean logprobs, Integer topLogprobs, Integer maxTokens, Integer maxCompletionTokens, Integer n, List<OpenAiApi.OutputModality> outputModalities, OpenAiApi.ChatCompletionRequest.AudioParameters audioParameters, Double presencePenalty, ResponseFormat responseFormat, Integer seed, String serviceTier, List<String> stop, Boolean stream, OpenAiApi.ChatCompletionRequest.StreamOptions streamOptions, Double temperature, Double topP, List<OpenAiApi.FunctionTool> tools, Object toolChoice, Boolean parallelToolCalls, String user, String reasoningEffort, OpenAiApi.ChatCompletionRequest.WebSearchOptions webSearchOptions, String verbosity, String promptCacheKey, String safetyIdentifier, Map<String, Object> extraBody) Compact constructor that ensures extraBody is initialized as a mutable HashMap when null, enabling @JsonAnySetter to populate it during deserialization.ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Double temperature) Shortcut constructor for a chat completion request with the given messages, model and temperature.ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Double temperature, boolean stream) Shortcut constructor for a chat completion request with the given messages, model, temperature and control for streaming.ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, List<OpenAiApi.FunctionTool> tools, Object toolChoice) Shortcut constructor for a chat completion request with the given messages, model, tools and tool choice.ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, OpenAiApi.ChatCompletionRequest.AudioParameters audio, boolean stream) Shortcut constructor for a chat completion request with text and audio output. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theaudioParametersrecord component.final booleanIndicates whether some other object is "equal to" this one.Overrides the default accessor to add @JsonAnyGetter annotation.Returns the value of thefrequencyPenaltyrecord component.final inthashCode()Returns a hash code value for this object.Returns the value of thelogitBiasrecord component.logprobs()Returns the value of thelogprobsrecord component.Returns the value of themaxCompletionTokensrecord component.Returns the value of themaxTokensrecord component.messages()Returns the value of themessagesrecord component.metadata()Returns the value of themetadatarecord component.model()Returns the value of themodelrecord component.n()Returns the value of thenrecord component.Returns the value of theoutputModalitiesrecord component.Returns the value of theparallelToolCallsrecord component.Returns the value of thepresencePenaltyrecord component.Returns the value of thepromptCacheKeyrecord component.Returns the value of thereasoningEffortrecord component.Returns the value of theresponseFormatrecord component.Returns the value of thesafetyIdentifierrecord component.seed()Returns the value of theseedrecord component.Returns the value of theserviceTierrecord component.stop()Returns the value of thestoprecord component.store()Returns the value of thestorerecord component.stream()Returns the value of thestreamrecord component.Returns the value of thestreamOptionsrecord component.streamOptions(OpenAiApi.ChatCompletionRequest.StreamOptions streamOptions) Sets theOpenAiApi.ChatCompletionRequest.StreamOptionsfor this request.Returns the value of thetemperaturerecord component.Returns the value of thetoolChoicerecord component.tools()Returns the value of thetoolsrecord component.Returns the value of thetopLogprobsrecord component.topP()Returns the value of thetopPrecord component.final StringtoString()Returns a string representation of this record class.user()Returns the value of theuserrecord component.Returns the value of theverbosityrecord component.Returns the value of thewebSearchOptionsrecord component.
-
Constructor Details
-
ChatCompletionRequest
public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Boolean store, Map<String, String> metadata, Double frequencyPenalty, Map<String, Integer> logitBias, Boolean logprobs, Integer topLogprobs, Integer maxTokens, Integer maxCompletionTokens, Integer n, List<OpenAiApi.OutputModality> outputModalities, OpenAiApi.ChatCompletionRequest.AudioParameters audioParameters, Double presencePenalty, ResponseFormat responseFormat, Integer seed, String serviceTier, List<String> stop, Boolean stream, OpenAiApi.ChatCompletionRequest.StreamOptions streamOptions, Double temperature, Double topP, List<OpenAiApi.FunctionTool> tools, Object toolChoice, Boolean parallelToolCalls, String user, String reasoningEffort, OpenAiApi.ChatCompletionRequest.WebSearchOptions webSearchOptions, String verbosity, String promptCacheKey, String safetyIdentifier, Map<String, Object> extraBody) Compact constructor that ensures extraBody is initialized as a mutable HashMap when null, enabling @JsonAnySetter to populate it during deserialization. -
ChatCompletionRequest
public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Double temperature) Shortcut constructor for a chat completion request with the given messages, model and temperature.- Parameters:
messages- A list of messages comprising the conversation so far.model- ID of the model to use.temperature- What sampling temperature to use, between 0 and 1.
-
ChatCompletionRequest
public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, OpenAiApi.ChatCompletionRequest.AudioParameters audio, boolean stream) Shortcut constructor for a chat completion request with text and audio output.- Parameters:
messages- A list of messages comprising the conversation so far.model- ID of the model to use.audio- Parameters for audio output. Required when audio output is requested with outputModalities: ["audio"].
-
ChatCompletionRequest
public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Double temperature, boolean stream) Shortcut constructor for a chat completion request with the given messages, model, temperature and control for streaming.- Parameters:
messages- A list of messages comprising the conversation so far.model- ID of the model to use.temperature- What sampling temperature to use, between 0 and 1.stream- If set, partial message deltas will be sent.Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
-
ChatCompletionRequest
public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, List<OpenAiApi.FunctionTool> tools, Object toolChoice) Shortcut constructor for a chat completion request with the given messages, model, tools and tool choice. Streaming is set to false, temperature to 0.8 and all other parameters are null.- Parameters:
messages- A list of messages comprising the conversation so far.model- ID of the model to use.tools- A list of tools the model may call. Currently, only functions are supported as a tool.toolChoice- Controls which (if any) function is called by the model.
-
ChatCompletionRequest
Shortcut constructor for a chat completion request with the given messages for streaming.- Parameters:
messages- A list of messages comprising the conversation so far.stream- If set, partial message deltas will be sent.Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
-
-
Method Details
-
streamOptions
public OpenAiApi.ChatCompletionRequest streamOptions(OpenAiApi.ChatCompletionRequest.StreamOptions streamOptions) Sets theOpenAiApi.ChatCompletionRequest.StreamOptionsfor this request.- Parameters:
streamOptions- The new stream options to use.- Returns:
- A new
OpenAiApi.ChatCompletionRequestwith the specified stream options.
-
extraBody
Overrides the default accessor to add @JsonAnyGetter annotation. This causes Jackson to flatten the extraBody map contents to the top level of the JSON, matching the behavior expected by OpenAI-compatible servers like vLLM, Ollama, etc.- Returns:
- The extraBody map, or null if not set.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
messages
Returns the value of themessagesrecord component.- Returns:
- the value of the
messagesrecord component
-
model
Returns the value of themodelrecord component.- Returns:
- the value of the
modelrecord component
-
store
Returns the value of thestorerecord component.- Returns:
- the value of the
storerecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-
frequencyPenalty
Returns the value of thefrequencyPenaltyrecord component.- Returns:
- the value of the
frequencyPenaltyrecord component
-
logitBias
Returns the value of thelogitBiasrecord component.- Returns:
- the value of the
logitBiasrecord component
-
logprobs
Returns the value of thelogprobsrecord component.- Returns:
- the value of the
logprobsrecord component
-
topLogprobs
Returns the value of thetopLogprobsrecord component.- Returns:
- the value of the
topLogprobsrecord component
-
maxTokens
Returns the value of themaxTokensrecord component.- Returns:
- the value of the
maxTokensrecord component
-
maxCompletionTokens
Returns the value of themaxCompletionTokensrecord component.- Returns:
- the value of the
maxCompletionTokensrecord component
-
n
Returns the value of thenrecord component.- Returns:
- the value of the
nrecord component
-
outputModalities
Returns the value of theoutputModalitiesrecord component.- Returns:
- the value of the
outputModalitiesrecord component
-
audioParameters
Returns the value of theaudioParametersrecord component.- Returns:
- the value of the
audioParametersrecord component
-
presencePenalty
Returns the value of thepresencePenaltyrecord component.- Returns:
- the value of the
presencePenaltyrecord component
-
responseFormat
Returns the value of theresponseFormatrecord component.- Returns:
- the value of the
responseFormatrecord component
-
seed
Returns the value of theseedrecord component.- Returns:
- the value of the
seedrecord component
-
serviceTier
Returns the value of theserviceTierrecord component.- Returns:
- the value of the
serviceTierrecord component
-
stop
Returns the value of thestoprecord component.- Returns:
- the value of the
stoprecord component
-
stream
Returns the value of thestreamrecord component.- Returns:
- the value of the
streamrecord component
-
streamOptions
Returns the value of thestreamOptionsrecord component.- Returns:
- the value of the
streamOptionsrecord component
-
temperature
Returns the value of thetemperaturerecord component.- Returns:
- the value of the
temperaturerecord component
-
topP
Returns the value of thetopPrecord component.- Returns:
- the value of the
topPrecord component
-
tools
Returns the value of thetoolsrecord component.- Returns:
- the value of the
toolsrecord component
-
toolChoice
Returns the value of thetoolChoicerecord component.- Returns:
- the value of the
toolChoicerecord component
-
parallelToolCalls
Returns the value of theparallelToolCallsrecord component.- Returns:
- the value of the
parallelToolCallsrecord component
-
user
Returns the value of theuserrecord component.- Returns:
- the value of the
userrecord component
-
reasoningEffort
Returns the value of thereasoningEffortrecord component.- Returns:
- the value of the
reasoningEffortrecord component
-
webSearchOptions
Returns the value of thewebSearchOptionsrecord component.- Returns:
- the value of the
webSearchOptionsrecord component
-
verbosity
Returns the value of theverbosityrecord component.- Returns:
- the value of the
verbosityrecord component
-
promptCacheKey
Returns the value of thepromptCacheKeyrecord component.- Returns:
- the value of the
promptCacheKeyrecord component
-
safetyIdentifier
Returns the value of thesafetyIdentifierrecord component.- Returns:
- the value of the
safetyIdentifierrecord component
-