Class ChatResponse

java.lang.Object
com.codename1.ai.ChatResponse

public final class ChatResponse extends Object

The terminal response from a chat call. For streaming requests, the ChatResponse carries the aggregated final assistant message -- the individual deltas were delivered through StreamingListener before this object was produced.

finishReason is one of: "stop", "length", "tool_calls", "content_filter", "error" (normalized across providers).

  • Constructor Details

    • ChatResponse

      public ChatResponse(ChatMessage assistantMessage, List<ToolCall> toolCalls, String finishReason, Usage usage, String modelUsed)
      Creates a normalized terminal response.
      Parameters:
      assistantMessage - aggregated assistant output, or null
      toolCalls - requested tool calls; null becomes empty
      finishReason - normalized provider finish reason
      usage - token accounting, or null
      modelUsed - provider-reported model id, or null
  • Method Details

    • getAssistantMessage

      public ChatMessage getAssistantMessage()
      Returns:
      normalized assistant message, including any multimodal parts
    • getToolCalls

      public List<ToolCall> getToolCalls()
      Returns:
      immutable tool calls requested by the model
    • getText

      public String getText()
      Convenience: the assembled assistant text. Equivalent to getAssistantMessage().getText() when there is one.
      Returns:
      assistant text, or an empty string without a message
    • getFinishReason

      public String getFinishReason()
      Returns:
      provider finish reason such as stop or length
    • getUsage

      public Usage getUsage()
      Returns:
      token accounting, or null when the provider omitted it
    • getModelUsed

      public String getModelUsed()
      Returns:
      provider-reported model id, or null when omitted