# Class LlmResponse

java.lang.Object
com.google.adk.JsonBaseModel
com.google.adk.models.LlmResponse

public abstract class LlmResponse extends JsonBaseModel
Represents a response received from the LLM.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `LlmResponse.Builder`
  Builder for constructing `LlmResponse` instances.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract Optional<Double>`
  `avgLogprobs()`
  Error code if the response is an error.
  `static LlmResponse.Builder`
  `builder()`
  `abstract Optional<com.google.genai.types.Content>`
  `content()`
  Returns the content of the first candidate in the response, if available.
  `static LlmResponse`
  `create(com.google.genai.types.GenerateContentResponse response)`
  `static LlmResponse`
  `create(List<com.google.genai.types.Candidate> candidates)`
  `abstract Optional<List<com.google.genai.types.CustomMetadata>>`
  `customMetadata()`
  Returns the custom metadata of the response, if available.
  `abstract Optional<com.google.genai.types.FinishReason>`
  `errorCode()`
  Error code if the response is an error.
  `abstract Optional<String>`
  `errorMessage()`
  Error message if the response is an error.
  `abstract Optional<com.google.genai.types.FinishReason>`
  `finishReason()`
  Error code if the response is an error.
  `abstract Optional<com.google.genai.types.GroundingMetadata>`
  `groundingMetadata()`
  Returns the grounding metadata of the first candidate in the response, if available.
  `abstract Optional<com.google.genai.types.Transcription>`
  `inputTranscription()`
  Input transcription.
  `abstract Optional<Boolean>`
  `interrupted()`
  Indicates that LLM was interrupted when generating the content.
  `abstract Optional<String>`
  `modelVersion()`
  The model version used to generate the response.
  `abstract Optional<com.google.genai.types.Transcription>`
  `outputTranscription()`
  Output transcription.
  `abstract Optional<Boolean>`
  `partial()`
  Indicates whether the text content is part of a unfinished text stream.
  `abstract LlmResponse.Builder`
  `toBuilder()`
  `abstract Optional<Boolean>`
  `turnComplete()`
  Indicates whether the response from the model is complete.
  `abstract Optional<com.google.genai.types.GenerateContentResponseUsageMetadata>`
  `usageMetadata()`
  Usage metadata about the response(s).

  ### Methods inherited from class JsonBaseModel

  `fromJsonNode, fromJsonString, getMapper, toJson, toJsonNode, toJsonString`
  Modifier and Type
  Method
  Description
  `static <T extends JsonBaseModel>
  T`
  `fromJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> clazz)`
  Deserializes a JsonNode to an object of the given type.
  `static <T extends JsonBaseModel>
  T`
  `fromJsonString(String jsonString, Class<T> clazz)`
  Deserializes a Json string to an object of the given type.
  `static com.fasterxml.jackson.databind.ObjectMapper`
  `getMapper()`
  Returns the mutable ObjectMapper instance used by ADK.
  `String`
  `toJson()`
  Serializes this object (i.e., the ObjectMappper instance used by ADK) to a Json string.
  `protected static com.fasterxml.jackson.databind.JsonNode`
  `toJsonNode(Object object)`
  Serializes an object to a JsonNode.
  `static String`
  `toJsonString(Object object)`
  Serializes an object to a Json string.

  ### Methods inherited from class Object

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

- ## Method Details

  - ### content

    public abstract Optional<com.google.genai.types.Content> content()
    Returns the content of the first candidate in the response, if available.
    Returns:
      An `Content` of the first `Candidate` in the `GenerateContentResponse` if the response contains at least one candidate., or an empty optional if no candidates are present in the response.

  - ### groundingMetadata

    public abstract Optional<com.google.genai.types.GroundingMetadata> groundingMetadata()
    Returns the grounding metadata of the first candidate in the response, if available.
    Returns:
      An `Optional` containing `GroundingMetadata` or empty.

  - ### customMetadata

    public abstract Optional<List<com.google.genai.types.CustomMetadata>> customMetadata()
    Returns the custom metadata of the response, if available.
    Returns:
      An `Optional` containing a list of `CustomMetadata` or empty.

  - ### partial

    public abstract Optional<Boolean> partial()
    Indicates whether the text content is part of a unfinished text stream.

    Only used for streaming mode and when the content is plain text.

  - ### turnComplete

    public abstract Optional<Boolean> turnComplete()
    Indicates whether the response from the model is complete.

    Only used for streaming mode.

  - ### errorCode

    public abstract Optional<com.google.genai.types.FinishReason> errorCode()
    Error code if the response is an error. Code varies by model.

  - ### finishReason

    public abstract Optional<com.google.genai.types.FinishReason> finishReason()
    Error code if the response is an error. Code varies by model.

  - ### avgLogprobs

    public abstract Optional<Double> avgLogprobs()
    Error code if the response is an error. Code varies by model.

  - ### errorMessage

    public abstract Optional<String> errorMessage()
    Error message if the response is an error.

  - ### interrupted

    public abstract Optional<Boolean> interrupted()
    Indicates that LLM was interrupted when generating the content. Usually it's due to user interruption during a bidi streaming.

  - ### usageMetadata

    public abstract Optional<com.google.genai.types.GenerateContentResponseUsageMetadata> usageMetadata()
    Usage metadata about the response(s).

  - ### modelVersion

    public abstract Optional<String> modelVersion()
    The model version used to generate the response.

  - ### inputTranscription

    public abstract Optional<com.google.genai.types.Transcription> inputTranscription()
    Input transcription. The transcription is independent to the model turn which means it doesn't imply any ordering between transcription and model turn.

  - ### outputTranscription

    public abstract Optional<com.google.genai.types.Transcription> outputTranscription()
    Output transcription. The transcription is independent to the model turn which means it doesn't imply any ordering between transcription and model turn.

  - ### toBuilder

    public abstract LlmResponse.Builder toBuilder()

  - ### builder

    public static LlmResponse.Builder builder()

  - ### create

    public static LlmResponse create(List<com.google.genai.types.Candidate> candidates)

  - ### create

    public static LlmResponse create(com.google.genai.types.GenerateContentResponse response)