Gemini models are accessible using the OpenAI libraries (Python and TypeScript / Javascript) along with the REST API by updating three lines of code and using your Gemini API key. Read more about this feature in the compatibility guide.
ChatCompletionsRequest
- JSON representation
- StreamOptions
- ChatTool
- ChatFunction
- ResponseFormat
- ResponseFormatSchema
- AudioOptions
Request for chat completions.
model
string
Required. The name of the Model
to use for generating the completion. The model name will prefixed by "models/" if no slash appears in it.
Required. The chat history to use for generating the completion. Supports single and multi-turn queries. Note: This is a polymorphic field, it is deserialized to a InternalChatMessage.
stream
boolean
Optional. Whether to stream the response or return a single response.
If true, the "object" field in the response will be "chat.completion.chunk". Otherwise it will be "chat.completion".
Optional. Options for streaming requests.
Optional. The set of tools the model can generate calls for. Each tool declares its signature.
Optional. Controls whether the model should use a tool or not, and which tool to use. Can be either: - The string "none", to disable tools. - The string "auto", to let the model decide. - The string "required", to force the model to use a tool. - A function name descriptor object, specifying the tool to use. The last option follows the following schema: { "type": "function", "function": {"name" : "the_function_name"} }
modalities[]
string
Optional. Modalities for the request.
n
integer
Optional. Amount of candidate completions to generate. Must be a positive integer. Defaults to 1 if not set.
Optional. The set of character sequences that will stop output generation. Note: This is a polymorphic field. It is meant to contain a string or repeated strings.
maxCompletionTokens
integer
Optional. The maximum number of tokens to include in a response candidate. Must be a positive integer.
maxTokens
integer
Optional. The maximum number of tokens to include in a response candidate. Must be a positive integer. This field is deprecated by the SDK.
temperature
number
Optional. Controls the randomness of the output.
topP
number
Optional. The maximum cumulative probability of tokens to consider when sampling.
Optional. Defines the format of the response. If not set, the response will be formatted as text.
Optional. Options for audio generation.
parallelToolCalls
boolean
Optional. Whether to call tools in parallel. Included here for compatibility with the SDK, but only false is supported.
presencePenalty
number
Optional. Penalizes new tokens based on previous appearances. Valid ranges are [-2, 2]. Default is 0.
user
string
Optional. The user name used for tracking the request. Not used, only for compatibility with the SDK.
JSON representation |
---|
{ "model": string, "messages": [ { object } ], "stream": boolean, "streamOptions": { object ( |
StreamOptions
Options for streaming requests.
includeUsage
boolean
Optional. If set, include usage statistics in the response.
JSON representation |
---|
{ "includeUsage": boolean } |
ChatTool
A tool that the model can generate calls for.
Required. The name of the tool.
type
string
Required. Required, must be "function".
JSON representation |
---|
{
"function": {
object ( |
ChatFunction
A function that the model can generate calls for.
name
string
Required. The name of the function.
description
string
Optional. A description of the function.
Optional. The parameters of the function.
strict
boolean
Optional. Whether the schema validation is strict. If true, the model will fail if the schema is not valid. NOTE: This parameter is currently ignored.
JSON representation |
---|
{ "name": string, "description": string, "parameters": { object }, "strict": boolean } |
ResponseFormat
Defines the format of the response.
type
string
Required. Type of the response. Can be either: - "text": Format the response as text. - "json_object": Format the response as a JSON object. - "jsonSchema": Format the response as a JSON object following the given schema.
Optional. The JSON schema to follow. Only used if type is "jsonSchema".
JSON representation |
---|
{
"type": string,
"jsonSchema": {
object ( |
ResponseFormatSchema
Schema for the response.
description
string
Optional. Description of the object represented by the schema.
name
string
Required. Name of the object type represented by the schema.
strict
boolean
Optional. Whether the schema validation is strict. If true, the model will fail if the schema is not valid. NOTE: This parameter is currently ignored.
Optional. The JSON schema to follow.
JSON representation |
---|
{ "description": string, "name": string, "strict": boolean, "schema": { object } } |
AudioOptions
Options for audio generation.
voice
string
Optional. The voice to use for the audio response.
format
string
Optional. The format of the audio response. Can be either: - "wav": Format the response as a WAV file. - "mp3": Format the response as an MP3 file. - "flac": Format the response as a FLAC file. - "opus": Format the response as an OPUS file. - "pcm16": Format the response as a PCM16 file.
JSON representation |
---|
{ "voice": string, "format": string } |
GenerateEmbeddingsEmbedding
An embedding vector generated by the model.
object
string
Output only. Always "embedding", required by the SDK.
index
integer
Output only. Index of the embedding in the list of embeddings.
Output only. The embedding vector generated for the input. Can be either a list of floats or a base64 string encoding the a list of floats with C-style layout (Numpy compatible).
JSON representation |
---|
{ "object": string, "index": integer, "embedding": value } |
GenerateEmbeddingsRequest
Request for embedding generation.
Required. The input to generate embeddings for. Can be a string, or a list of strings. The SDK supports a list of numbers and list of list of numbers, but this is not yet implemented.
model
string
Required. Model to generate the embeddings for.
encodingFormat
string
Optional. The format of the encoding. Must be either "float" or "base64".
dimensions
integer
Optional. Dimensional size of the generated embeddings.
JSON representation |
---|
{ "input": value, "model": string, "encodingFormat": string, "dimensions": integer } |
GenerateEmbeddingsResponse
Response for embedding generation.
object
string
Output only. Always "embedding", required by the SDK.
Output only. A list of the requested embeddings.
model
string
Output only. Model used to generate the embeddings.
JSON representation |
---|
{
"object": string,
"data": [
{
object ( |
GenerateImagesRequest
Request for image generation.
prompt
string
Required. A text description of the desired image(s). The maximum length is 1000 characters.
model
string
Optional. Model to generate the images for.
n
integer
Optional. Number of images to generate.
quality
string
Optional. The quality of the image that will be generated. "hd" creates images with finer details and greater consistency across the image.
responseFormat
string
Optional. The format in which the generated images are returned. Must be one of url or b64Json
size
string
Optional. The size of the generated images
style
string
Optional. The style of the generated images. Must be one of vivid or natural.
user
string
Optional. A unique identifier representing your end-user
JSON representation |
---|
{ "prompt": string, "model": string, "n": integer, "quality": string, "responseFormat": string, "size": string, "style": string, "user": string } |
GenerateImagesResponse
Response for image generation.
object
string
Output only. Always "image", required by the SDK.
Output only. A list of the generated images.
model
string
Output only. Model used to generate the images.
JSON representation |
---|
{
"object": string,
"data": [
{
object ( |
Image
An image generated by the model.
b64_json
string
The base64-encoded JSON of the generated image.
JSON representation |
---|
{ "b64_json": string } |
HttpBody
Message that represents an arbitrary HTTP body. It should only be used for payload formats that can't be represented as JSON, such as raw binary or an HTML page.
This message can be used both in streaming and non-streaming API methods in the request as well as the response.
It can be used as a top-level request field, which is convenient if one wants to extract parameters from either the URL or HTTP template into the request fields and also want access to the raw HTTP body.
Example:
message GetResourceRequest {
// A unique request id.
string requestId = 1;
// The raw HTTP body is bound to this field.
google.api.HttpBody http_body = 2;
}
service ResourceService {
rpc GetResource(GetResourceRequest)
returns (google.api.HttpBody);
rpc UpdateResource(google.api.HttpBody)
returns (google.protobuf.Empty);
}
Example with streaming methods:
service CaldavService {
rpc GetCalendar(stream google.api.HttpBody)
returns (stream google.api.HttpBody);
rpc UpdateCalendar(stream google.api.HttpBody)
returns (stream google.api.HttpBody);
}
Use of this type only changes how the request and response bodies are handled, all other features will continue to work unchanged.
contentType
string
The HTTP Content-Type header value specifying the content type of the body.
The HTTP request/response body as raw binary.
A base64-encoded string.
extensions[]
object
Application specific response metadata. Must be set in the first response for streaming APIs.
An object containing fields of an arbitrary type. An additional field "@type"
contains a URI identifying the type. Example: { "id": 1234, "@type": "types.example.com/standard/id" }
.
JSON representation |
---|
{ "contentType": string, "data": string, "extensions": [ { "@type": string, field1: ..., ... } ] } |
SdkGetModelRequest
Request for getting a model.
model
string
Required. The name of the model to get.
JSON representation |
---|
{ "model": string } |
SdkListModelsResponse
Response for list models.
object
string
Output only. Always "list", required by the SDK.
Output only. A list of the requested embeddings.
JSON representation |
---|
{
"object": string,
"data": [
{
object ( |
SdkModel
The model object.
id
string
Output only. Id of the model.
object
string
Output only. Always "model", required by the SDK.
Output only. The Unix timestamp (in seconds) when the model was created.
owned_by
string
Output only. The organization that owns the model.
JSON representation |
---|
{ "id": string, "object": string, "created": string, "owned_by": string } |