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 the OpenAiApi.ChatCompletionRequest.ToolChoiceBuilder to 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.
  • 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

      public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, Boolean stream)
      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

      Parameters:
      streamOptions - The new stream options to use.
      Returns:
      A new OpenAiApi.ChatCompletionRequest with the specified stream options.
    • extraBody

      public Map<String,Object> 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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • messages

      Returns the value of the messages record component.
      Returns:
      the value of the messages record component
    • model

      public String model()
      Returns the value of the model record component.
      Returns:
      the value of the model record component
    • store

      public Boolean store()
      Returns the value of the store record component.
      Returns:
      the value of the store record component
    • metadata

      public Map<String,String> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component
    • frequencyPenalty

      public Double frequencyPenalty()
      Returns the value of the frequencyPenalty record component.
      Returns:
      the value of the frequencyPenalty record component
    • logitBias

      public Map<String,Integer> logitBias()
      Returns the value of the logitBias record component.
      Returns:
      the value of the logitBias record component
    • logprobs

      public Boolean logprobs()
      Returns the value of the logprobs record component.
      Returns:
      the value of the logprobs record component
    • topLogprobs

      public Integer topLogprobs()
      Returns the value of the topLogprobs record component.
      Returns:
      the value of the topLogprobs record component
    • maxTokens

      public Integer maxTokens()
      Returns the value of the maxTokens record component.
      Returns:
      the value of the maxTokens record component
    • maxCompletionTokens

      public Integer maxCompletionTokens()
      Returns the value of the maxCompletionTokens record component.
      Returns:
      the value of the maxCompletionTokens record component
    • n

      public Integer n()
      Returns the value of the n record component.
      Returns:
      the value of the n record component
    • outputModalities

      public List<OpenAiApi.OutputModality> outputModalities()
      Returns the value of the outputModalities record component.
      Returns:
      the value of the outputModalities record component
    • audioParameters

      Returns the value of the audioParameters record component.
      Returns:
      the value of the audioParameters record component
    • presencePenalty

      public Double presencePenalty()
      Returns the value of the presencePenalty record component.
      Returns:
      the value of the presencePenalty record component
    • responseFormat

      public ResponseFormat responseFormat()
      Returns the value of the responseFormat record component.
      Returns:
      the value of the responseFormat record component
    • seed

      public Integer seed()
      Returns the value of the seed record component.
      Returns:
      the value of the seed record component
    • serviceTier

      public String serviceTier()
      Returns the value of the serviceTier record component.
      Returns:
      the value of the serviceTier record component
    • stop

      public List<String> stop()
      Returns the value of the stop record component.
      Returns:
      the value of the stop record component
    • stream

      public Boolean stream()
      Returns the value of the stream record component.
      Returns:
      the value of the stream record component
    • streamOptions

      Returns the value of the streamOptions record component.
      Returns:
      the value of the streamOptions record component
    • temperature

      public Double temperature()
      Returns the value of the temperature record component.
      Returns:
      the value of the temperature record component
    • topP

      public Double topP()
      Returns the value of the topP record component.
      Returns:
      the value of the topP record component
    • tools

      public List<OpenAiApi.FunctionTool> tools()
      Returns the value of the tools record component.
      Returns:
      the value of the tools record component
    • toolChoice

      public Object toolChoice()
      Returns the value of the toolChoice record component.
      Returns:
      the value of the toolChoice record component
    • parallelToolCalls

      public Boolean parallelToolCalls()
      Returns the value of the parallelToolCalls record component.
      Returns:
      the value of the parallelToolCalls record component
    • user

      public String user()
      Returns the value of the user record component.
      Returns:
      the value of the user record component
    • reasoningEffort

      public String reasoningEffort()
      Returns the value of the reasoningEffort record component.
      Returns:
      the value of the reasoningEffort record component
    • webSearchOptions

      Returns the value of the webSearchOptions record component.
      Returns:
      the value of the webSearchOptions record component
    • verbosity

      public String verbosity()
      Returns the value of the verbosity record component.
      Returns:
      the value of the verbosity record component
    • promptCacheKey

      public String promptCacheKey()
      Returns the value of the promptCacheKey record component.
      Returns:
      the value of the promptCacheKey record component
    • safetyIdentifier

      public String safetyIdentifier()
      Returns the value of the safetyIdentifier record component.
      Returns:
      the value of the safetyIdentifier record component