Models

Method: models.get

Gets information about a specific Model.

Endpoint

get https://generativelanguage.googleapis.com/v1beta/{name=models/*}

Path parameters

name string

Required. The resource name of the model.

This name should match a model name returned by the models.list method.

Format: models/{model} It takes the form models/{model}.

Request body

The request body must be empty.

Example request

Python

model_info = genai.get_model("models/gemini-1.5-flash-latest")
print(model_info)

Shell

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-pro?key=$GOOGLE_API_KEY

Response body

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

Method: models.list

Lists models available through the API.

Endpoint

get https://generativelanguage.googleapis.com/v1beta/models

Query parameters

pageSize integer

The maximum number of Models to return (per page).

The service may return fewer models. If unspecified, at most 50 models will be returned per page. This method returns at most 1000 models per page, even if you pass a larger pageSize.

pageToken string

A page token, received from a previous models.list call.

Provide the pageToken returned by one request as an argument to the next request to retrieve the next page.

When paginating, all other parameters provided to models.list must match the call that provided the page token.

Request body

The request body must be empty.

Example request

Python

print("List of models that support generateContent:\n")
for m in genai.list_models():
    if "generateContent" in m.supported_generation_methods:
        print(m.name)

print("List of models that support embedContent:\n")
for m in genai.list_models():
    if "embedContent" in m.supported_generation_methods:
        print(m.name)

Shell

curl https://generativelanguage.googleapis.com/v1beta/models?key=$GOOGLE_API_KEY

Response body

Response from ListModel containing a paginated list of Models.

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

Fields
models[] object (Model)

The returned Models.

nextPageToken string

A token, which can be sent as pageToken to retrieve the next page.

If this field is omitted, there are no more pages.

JSON representation
{
  "models": [
    {
      object (Model)
    }
  ],
  "nextPageToken": string
}

REST Resource: models

Resource: Model

Information about a Generative Language Model.

JSON representation
{
  "name": string,
  "baseModelId": string,
  "version": string,
  "displayName": string,
  "description": string,
  "inputTokenLimit": integer,
  "outputTokenLimit": integer,
  "supportedGenerationMethods": [
    string
  ],
  "temperature": number,
  "maxTemperature": number,
  "topP": number,
  "topK": integer
}
Fields
name string

Required. The resource name of the Model.

Format: models/{model} with a {model} naming convention of:

  • "{baseModelId}-{version}"

Examples:

  • models/chat-bison-001
baseModelId string

Required. The name of the base model, pass this to the generation request.

Examples:

  • chat-bison
version string

Required. The version number of the model.

This represents the major version

displayName string

The human-readable name of the model. E.g. "Chat Bison".

The name can be up to 128 characters long and can consist of any UTF-8 characters.

description string

A short description of the model.

inputTokenLimit integer

Maximum number of input tokens allowed for this model.

outputTokenLimit integer

Maximum number of output tokens available for this model.

supportedGenerationMethods[] string

The model's supported generation methods.

The method names are defined as Pascal case strings, such as generateMessage which correspond to API methods.

temperature number

Controls the randomness of the output.

Values can range over [0.0,maxTemperature], inclusive. A higher value will produce responses that are more varied, while a value closer to 0.0 will typically result in less surprising responses from the model. This value specifies default to be used by the backend while making the call to the model.

maxTemperature number

The maximum temperature this model can use.

topP number

For Nucleus sampling.

Nucleus sampling considers the smallest set of tokens whose probability sum is at least topP. This value specifies default to be used by the backend while making the call to the model.

topK integer

For Top-k sampling.

Top-k sampling considers the set of topK most probable tokens. This value specifies default to be used by the backend while making the call to the model. If empty, indicates the model doesn't use top-k sampling, and topK isn't allowed as a generation parameter.