GenerateContentResponse

Response from the model supporting multiple candidates.

Note on safety ratings and content filtering. They are reported for both prompt in GenerateContentResponse.prompt_feedback and for each candidate in finishReason and in safetyRatings. The API contract is that: - either all requested candidates are returned or no candidates at all - no candidates are returned only if there was something wrong with the prompt (see promptFeedback) - feedback on each candidate is reported on finishReason and safetyRatings.

JSON representation
{
  "candidates": [
    {
      object (Candidate)
    }
  ],
  "promptFeedback": {
    object (PromptFeedback)
  }
}
Fields
candidates[]

object (Candidate)

Candidate responses from the model.

promptFeedback

object (PromptFeedback)

Returns the prompt's feedback related to the content filters.

Candidate

A response candidate generated from the model.

JSON representation
{
  "content": {
    object (Content)
  },
  "finishReason": enum (FinishReason),
  "safetyRatings": [
    {
      object (SafetyRating)
    }
  ],
  "citationMetadata": {
    object (CitationMetadata)
  },
  "tokenCount": integer,
  "index": integer
}
Fields
content

object (Content)

Output only. Generated content returned from the model.

finishReason

enum (FinishReason)

Optional. Output only. The reason why the model stopped generating tokens.

If empty, the model has not stopped generating the tokens.

safetyRatings[]

object (SafetyRating)

List of ratings for the safety of a response candidate.

There is at most one rating per category.

citationMetadata

object (CitationMetadata)

Output only. Citation information for model-generated candidate.

This field may be populated with recitation information for any text included in the content. These are passages that are "recited" from copyrighted material in the foundational LLM's training data.

tokenCount

integer

Output only. Token count for this candidate.

index

integer

Output only. Index of the candidate in the list of candidates.

FinishReason

Defines the reason why the model stopped generating tokens.

Enums
FINISH_REASON_UNSPECIFIED Default value. This value is unused.
STOP Natural stop point of the model or provided stop sequence.
MAX_TOKENS The maximum number of tokens as specified in the request was reached.
SAFETY The candidate content was flagged for safety reasons.
RECITATION The candidate content was flagged for recitation reasons.
OTHER Unknown reason.

SafetyRating

Safety rating for a piece of content.

The safety rating contains the category of harm and the harm probability level in that category for a piece of content. Content is classified for safety across a number of harm categories and the probability of the harm classification is included here.

JSON representation
{
  "category": enum (HarmCategory),
  "probability": enum (HarmProbability),
  "blocked": boolean
}
Fields
category

enum (HarmCategory)

Required. The category for this rating.

probability

enum (HarmProbability)

Required. The probability of harm for this content.

blocked

boolean

Was this content blocked because of this rating?

HarmProbability

The probability that a piece of content is harmful.

The classification system gives the probability of the content being unsafe. This does not indicate the severity of harm for a piece of content.

Enums
HARM_PROBABILITY_UNSPECIFIED Probability is unspecified.
NEGLIGIBLE Content has a negligible chance of being unsafe.
LOW Content has a low chance of being unsafe.
MEDIUM Content has a medium chance of being unsafe.
HIGH Content has a high chance of being unsafe.

CitationMetadata

A collection of source attributions for a piece of content.

JSON representation
{
  "citationSources": [
    {
      object (CitationSource)
    }
  ]
}
Fields
citationSources[]

object (CitationSource)

Citations to sources for a specific response.

CitationSource

A citation to a source for a portion of a specific response.

JSON representation
{
  "startIndex": integer,
  "endIndex": integer,
  "uri": string,
  "license": string
}
Fields
startIndex

integer

Optional. Start of segment of the response that is attributed to this source.

Index indicates the start of the segment, measured in bytes.

endIndex

integer

Optional. End of the attributed segment, exclusive.

uri

string

Optional. URI that is attributed as a source for a portion of the text.

license

string

Optional. License for the GitHub project that is attributed as a source for segment.

License info is required for code citations.

PromptFeedback

A set of the feedback metadata the prompt specified in GenerateContentRequest.content.

JSON representation
{
  "blockReason": enum (BlockReason),
  "safetyRatings": [
    {
      object (SafetyRating)
    }
  ]
}
Fields
blockReason

enum (BlockReason)

Optional. If set, the prompt was blocked and no candidates are returned. Rephrase your prompt.

safetyRatings[]

object (SafetyRating)

Ratings for safety of the prompt. There is at most one rating per category.

BlockReason

Specifies what was the reason why prompt was blocked.

Enums
BLOCK_REASON_UNSPECIFIED Default value. This value is unused.
SAFETY Prompt was blocked due to safety reasons. You can inspect safetyRatings to understand which safety category blocked it.
OTHER Prompt was blocked due to unknown reaasons.