Class GenerateContentResponse

java.lang.Object
com.google.genai.JsonSerializable
com.google.genai.types.GenerateContentResponse

public abstract class GenerateContentResponse extends JsonSerializable
Response message for PredictionService.GenerateContent.
  • Constructor Details

    • GenerateContentResponse

      public GenerateContentResponse()
  • Method Details

    • candidates

      public abstract Optional<List<Candidate>> candidates()
      Response variations returned by the model.
    • createTime

      public abstract Optional<String> createTime()
      Timestamp when the request is made to the server.
    • responseId

      public abstract Optional<String> responseId()
      Identifier for each response.
    • modelVersion

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

      public abstract Optional<GenerateContentResponsePromptFeedback> promptFeedback()
      Output only. Content filter results for a prompt sent in the request. Note: Sent only in the first stream chunk. Only happens when no candidates were generated due to content violations.
    • usageMetadata

      public abstract Optional<GenerateContentResponseUsageMetadata> usageMetadata()
      Usage metadata about the response(s).
    • builder

      public static GenerateContentResponse.Builder builder()
      Instantiates a builder for GenerateContentResponse.
    • toBuilder

      public abstract GenerateContentResponse.Builder toBuilder()
      Creates a builder with the same values as this instance.
    • fromJson

      public static GenerateContentResponse fromJson(String jsonString)
      Deserializes a JSON string to a GenerateContentResponse object.
    • parts

      public @Nullable com.google.common.collect.ImmutableList<Part> parts()
      Returns the list of parts in the first candidate of the response.

      Returns null if there is no candidate or no content in the first candidate

    • text

      public @Nullable String text()
      Returns the concatenation of all text parts in the first candidate of the response.

      Returns null if there is no candidate, no content in the first candidate, or no parts in the content.

    • functionCalls

      public @Nullable com.google.common.collect.ImmutableList<FunctionCall> functionCalls()
      Returns the list of function calls in the response.

      Returns null if there is no candidate, no content in the first candidate, or no parts in the content.

    • executableCode

      public @Nullable String executableCode()
      Returns the executable code in the response.

      Returns null if there is no candidate, no content in the first candidate, or no parts in the content, or no executable code in the parts.

    • codeExecutionResult

      public @Nullable String codeExecutionResult()
      Returns the code execution result in the response.

      Returns null if there is no candidate, no content in the first candidate, or no parts in the content, or no code execution result in the parts.

    • finishReason

      public FinishReason finishReason()
      Gets the finish reason in a GenerateContentResponse.
    • checkFinishReason

      @InternalApi public void checkFinishReason()
      Throws an exception if the response finishes unexpectedly.