Class Candidate

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

public abstract class Candidate extends JsonSerializable
A response candidate generated from the model.
  • Constructor Details

    • Candidate

      public Candidate()
  • Method Details

    • content

      public abstract Optional<Content> content()
      Contains the multi-part content of the response.
    • citationMetadata

      public abstract Optional<CitationMetadata> citationMetadata()
      Source attribution of the generated content.
    • finishMessage

      public abstract Optional<String> finishMessage()
      Describes the reason the model stopped generating tokens.
    • tokenCount

      public abstract Optional<Integer> tokenCount()
      Number of tokens for this candidate.
    • finishReason

      public abstract Optional<FinishReason> finishReason()
      The reason why the model stopped generating tokens. If empty, the model has not stopped generating the tokens.
    • groundingMetadata

      public abstract Optional<GroundingMetadata> groundingMetadata()
      Output only. Metadata returned when grounding is enabled. It contains the sources used to ground the generated content.
    • avgLogprobs

      public abstract Optional<Double> avgLogprobs()
      Output only. The average log probability of the tokens in this candidate. This is a length-normalized score that can be used to compare the quality of candidates of different lengths. A higher average log probability suggests a more confident and coherent response.
    • index

      public abstract Optional<Integer> index()
      Output only. The 0-based index of this candidate in the list of generated responses. This is useful for distinguishing between multiple candidates when `candidate_count` > 1.
    • logprobsResult

      public abstract Optional<LogprobsResult> logprobsResult()
      Output only. The detailed log probability information for the tokens in this candidate. This is useful for debugging, understanding model uncertainty, and identifying potential "hallucinations".
    • safetyRatings

      public abstract Optional<List<SafetyRating>> safetyRatings()
      Output only. A list of ratings for the safety of a response candidate. There is at most one rating per category.
    • urlContextMetadata

      public abstract Optional<UrlContextMetadata> urlContextMetadata()
      Output only. Metadata returned when the model uses the `url_context` tool to get information from a user-provided URL.
    • builder

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

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

      public static Candidate fromJson(String jsonString)
      Deserializes a JSON string to a Candidate object.