# Class ChatRequest

java.lang.Object
com.codename1.ai.ChatRequest

public final class ChatRequest extends Object

The full request to `LlmClient.chat(ChatRequest)` / `LlmClient.chatStream(ChatRequest, StreamingListener)`. Built via `builder()`; immutable once constructed so the same request can be re-used across retries.

Numeric tuning fields are boxed so a `null` means "don't send" -- the provider's own default is used instead of one we picked.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `ChatRequest.Builder`
  Mutable fluent builder for `ChatRequest`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static ChatRequest.Builder`
  `builder()`
  Starts an empty request builder.
  `Integer`
  `getMaxTokens()`
  `List<ChatMessage>`
  `getMessages()`
  `Map<String,String>`
  `getMetadata()`
  `String`
  `getModel()`
  `ResponseFormat`
  `getResponseFormat()`
  `SafetyFilter`
  `getSafetyFilter()`
  `Long`
  `getSeed()`
  `List<String>`
  `getStopSequences()`
  `Float`
  `getTemperature()`
  `ToolChoice`
  `getToolChoice()`
  `List<Tool>`
  `getTools()`
  `Float`
  `getTopP()`
  `ChatRequest.Builder`
  `toBuilder()`
  Returns a builder pre-populated with the values of this request.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### builder

    public static ChatRequest.Builder builder()
    Starts an empty request builder. At least one message is required.
    Returns:
      a new builder

  - ### getModel

    public String getModel()
    Returns:
      requested provider model, or `null` for the client default

  - ### getMessages

    public List<ChatMessage> getMessages()
    Returns:
      immutable conversation messages in provider order

  - ### getTemperature

    public Float getTemperature()
    Returns:
      sampling temperature, or `null` for the provider default

  - ### getMaxTokens

    public Integer getMaxTokens()
    Returns:
      maximum generated tokens, or `null` for the provider default

  - ### getTopP

    public Float getTopP()
    Returns:
      nucleus-sampling probability, or `null` when unspecified

  - ### getStopSequences

    public List<String> getStopSequences()
    Returns:
      immutable stop sequences; empty when none were requested

  - ### getSeed

    public Long getSeed()
    Returns:
      deterministic sampling seed, or `null` when unspecified

  - ### getResponseFormat

    public ResponseFormat getResponseFormat()
    Returns:
      requested text/JSON response format, or `null`

  - ### getTools

    public List<Tool> getTools()
    Returns:
      immutable tools offered to the model

  - ### getToolChoice

    public ToolChoice getToolChoice()
    Returns:
      tool-selection policy, or `null` for provider behavior

  - ### getMetadata

    public Map<String,String> getMetadata()
    Returns:
      immutable provider metadata attached to this request

  - ### getSafetyFilter

    public SafetyFilter getSafetyFilter()
    Returns:
      client-side preflight filter, or `null` when disabled

  - ### toBuilder

    public ChatRequest.Builder toBuilder()
    Returns a builder pre-populated with the values of this request. Useful for replaying a request with one field changed.