Method: models.generateMessage

Generates a response from the model given an input MessagePrompt.

HTTP request

POST https://generativelanguage.googleapis.com/v1beta/{model=models/*}:generateMessage

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
model

string

Required. The name of the model to use.

Format: name=models/{model}.

Request body

The request body contains data with the following structure:

JSON representation
{
  "prompt": {
    object (MessagePrompt)
  },
  "temperature": number,
  "candidateCount": integer,
  "topP": number,
  "topK": integer
}
Fields
prompt

object (MessagePrompt)

Required. The structured textual input given to the model as a prompt.

Given a prompt, the model will return what it predicts is the next message in the discussion.

temperature

number

Optional. Controls the randomness of the output.

Values can range over [0.0,1.0], inclusive. A value closer to 1.0 will produce responses that are more varied, while a value closer to 0.0 will typically result in less surprising responses from the model.

candidateCount

integer

Optional. The number of generated response messages to return.

This value must be between [1, 8], inclusive. If unset, this will default to 1.

topP

number

Optional. The maximum cumulative probability of tokens to consider when sampling.

The model uses combined Top-k and nucleus sampling.

Nucleus sampling considers the smallest set of tokens whose probability sum is at least topP.

topK

integer

Optional. The maximum number of tokens to consider when sampling.

The model uses combined Top-k and nucleus sampling.

Top-k sampling considers the set of topK most probable tokens.

Response body

The response from the model.

This includes candidate messages and conversation history in the form of chronologically-ordered messages.

If successful, the response body contains data with the following structure:

JSON representation
{
  "candidates": [
    {
      object (Message)
    }
  ],
  "messages": [
    {
      object (Message)
    }
  ],
  "filters": [
    {
      object (ContentFilter)
    }
  ]
}
Fields
candidates[]

object (Message)

Candidate response messages from the model.

messages[]

object (Message)

The conversation history used by the model.

filters[]

object (ContentFilter)

A set of content filtering metadata for the prompt and response text.

This indicates which SafetyCategory(s) blocked a candidate from this response, the lowest HarmProbability that triggered a block, and the HarmThreshold setting for that category.

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.