Method: models.generateContent

Generates a response from the model given an input GenerateContentRequest.

HTTP request

POST https://generativelanguage.googleapis.com/v1/{model=models/*}:generateContent

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
model

string

Required. The name of the Model to use for generating the completion.

Format: name=models/{model}.

Request body

The request body contains data with the following structure:

JSON representation
{
  "contents": [
    {
      object (Content)
    }
  ],
  "safetySettings": [
    {
      object (SafetySetting)
    }
  ],
  "generationConfig": {
    object (GenerationConfig)
  }
}
Fields
contents[]

object (Content)

Required. The content of the current conversation with the model.

For single-turn queries, this is a single instance. For multi-turn queries, this is a repeated field that contains conversation history + latest request.

safetySettings[]

object (SafetySetting)

Optional. A list of unique SafetySetting instances for blocking unsafe content.

This will be enforced on the GenerateContentRequest.contents and GenerateContentResponse.candidates. There should not be more than one setting for each SafetyCategory type. The API will block any contents and responses that fail to meet the thresholds set by these settings. This list overrides the default settings for each SafetyCategory specified in the safetySettings. If there is no SafetySetting for a given SafetyCategory provided in the list, the API will use the default safety setting for that category. Harm categories HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT, HARM_CATEGORY_HARASSMENT are supported.

generationConfig

object (GenerationConfig)

Optional. Configuration options for model generation and outputs.

Response body

If successful, the response body contains an instance of GenerateContentResponse.

Authorization scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/generative-language
  • https://www.googleapis.com/auth/generative-language.tuning
  • https://www.googleapis.com/auth/generative-language.tuning.readonly
  • https://www.googleapis.com/auth/generative-language.retriever
  • https://www.googleapis.com/auth/generative-language.retriever.readonly

For more information, see the Authentication Overview.