Skip to main content
POST
Chat Completion

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
model
enum<string>
required

Gemini model ID to use for completion.

Available options:
gemini-3.1-pro-preview,
gemini-3.1-flash-image,
gemini-3.1-flash-lite-preview,
gemini-3-pro-preview,
gemini-3-pro-image,
gemini-3-flash-preview,
gemini-2.5-pro,
gemini-2.5-flash,
gemini-2.5-flash-lite,
gemini-2.0-flash
Example:

"gemini-2.5-pro"

messages
object[]
required

A list of messages comprising the conversation so far.

Minimum array length: 1
Example:
max_tokens
integer

The maximum number of tokens to generate in the chat completion.

Required range: x >= 1
temperature
number
default:1

Sampling temperature between 0 and 2.

Required range: 0 <= x <= 2
Example:

1

top_p
number

Nucleus sampling threshold.

Required range: 0 <= x <= 1
frequency_penalty
number
default:0

Penalizes new tokens based on their existing frequency in the text so far.

Required range: -2 <= x <= 2
presence_penalty
number
default:0

Penalizes new tokens based on whether they appear in the text so far.

Required range: -2 <= x <= 2
stream
boolean
default:false

If true, partial message deltas will be sent as server-sent events.

stop

Sequences where the API will stop generating further tokens.

n
integer
default:1

How many chat completion choices to generate for each input message.

Required range: x >= 1
response_format
object

An object specifying the format that the model must output. Setting to {"type": "json_object"} enables JSON mode.

Response

Completion generated successfully

id
string
required
Example:

"chatcmpl-abc123"

object
string
required
Example:

"chat.completion"

created
integer
required

Unix timestamp of when the completion was created.

model
string
required
Example:

"gemini-2.5-pro"

choices
object[]
required
usage
object