# Class ChatRequest.Builder

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

Enclosing class:
  `ChatRequest`

public static final class ChatRequest.Builder extends Object
Mutable fluent builder for `ChatRequest`. Collection arguments are copied when the immutable request is built.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ChatRequest.Builder`
  `addMessage(ChatMessage m)`
  Appends one conversation message.
  `ChatRequest`
  `build()`
  Validates and creates an immutable request.
  `ChatRequest.Builder`
  `maxTokens(Integer n)`
  Limits response length.
  `ChatRequest.Builder`
  `messages(List<ChatMessage> messages)`
  Replaces the conversation history.
  `ChatRequest.Builder`
  `metadata(Map<String,String> meta)`
  Attaches provider-specific request metadata.
  `ChatRequest.Builder`
  `model(String model)`
  Selects a provider model.
  `ChatRequest.Builder`
  `responseFormat(ResponseFormat f)`
  Requests text or structured JSON output.
  `ChatRequest.Builder`
  `safetyFilter(SafetyFilter f)`
  Installs a client-side filter evaluated before network submission.
  `ChatRequest.Builder`
  `seed(Long seed)`
  Requests deterministic sampling where supported.
  `ChatRequest.Builder`
  `stopSequences(List<String> stops)`
  Sets sequences that terminate generation.
  `ChatRequest.Builder`
  `temperature(Float t)`
  Sets sampling temperature.
  `ChatRequest.Builder`
  `toolChoice(ToolChoice choice)`
  Controls whether and which tool the model may call.
  `ChatRequest.Builder`
  `tools(List<Tool> tools)`
  Replaces the callable tools advertised to the model.
  `ChatRequest.Builder`
  `topP(Float p)`
  Sets nucleus sampling probability.

  ### Methods inherited from class Object

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

- ## Method Details

  - ### model

    public ChatRequest.Builder model(String model)
    Selects a provider model.
    Parameters:
      `model` - provider model id; `null` uses the client default
    Returns:
      this builder

  - ### messages

    public ChatRequest.Builder messages(List<ChatMessage> messages)
    Replaces the conversation history.
    Parameters:
      `messages` - messages in chronological order; `null` clears them
    Returns:
      this builder

  - ### addMessage

    public ChatRequest.Builder addMessage(ChatMessage m)
    Appends one conversation message.
    Parameters:
      `m` - message to append
    Returns:
      this builder

  - ### temperature

    public ChatRequest.Builder temperature(Float t)
    Sets sampling temperature.
    Parameters:
      `t` - provider-supported temperature, or `null` to omit
    Returns:
      this builder

  - ### maxTokens

    public ChatRequest.Builder maxTokens(Integer n)
    Limits response length.
    Parameters:
      `n` - maximum generated token count, or `null` to omit
    Returns:
      this builder

  - ### topP

    public ChatRequest.Builder topP(Float p)
    Sets nucleus sampling probability.
    Parameters:
      `p` - provider-supported probability, or `null` to omit
    Returns:
      this builder

  - ### stopSequences

    public ChatRequest.Builder stopSequences(List<String> stops)
    Sets sequences that terminate generation.
    Parameters:
      `stops` - stop strings, or `null` for none
    Returns:
      this builder

  - ### seed

    public ChatRequest.Builder seed(Long seed)
    Requests deterministic sampling where supported.
    Parameters:
      `seed` - provider sampling seed, or `null` to omit
    Returns:
      this builder

  - ### responseFormat

    public ChatRequest.Builder responseFormat(ResponseFormat f)
    Requests text or structured JSON output.
    Parameters:
      `f` - desired format, or `null` for provider default
    Returns:
      this builder

  - ### tools

    public ChatRequest.Builder tools(List<Tool> tools)
    Replaces the callable tools advertised to the model.
    Parameters:
      `tools` - tool definitions, or `null` for none
    Returns:
      this builder

  - ### toolChoice

    public ChatRequest.Builder toolChoice(ToolChoice choice)
    Controls whether and which tool the model may call.
    Parameters:
      `choice` - selection policy, or `null` for provider default
    Returns:
      this builder

  - ### metadata

    public ChatRequest.Builder metadata(Map<String,String> meta)
    Attaches provider-specific request metadata.
    Parameters:
      `meta` - metadata copied into the request, or `null`
    Returns:
      this builder

  - ### safetyFilter

    public ChatRequest.Builder safetyFilter(SafetyFilter f)
    Installs a client-side filter evaluated before network submission.
    Parameters:
      `f` - safety policy, or `null` to disable it
    Returns:
      this builder

  - ### build

    public ChatRequest build()
    Validates and creates an immutable request.
    Returns:
      completed request
    Throws:
      `IllegalStateException` - when no messages were supplied