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

The Gemini model ID used for completion.

Available options:
gemini-3.1-pro-preview,
gemini-3.1-flash-image-preview,
gemini-3.1-flash-lite-preview,
gemini-3-pro-preview,
gemini-3-pro-image-preview,
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

The list of messages that make up the current conversation.

Minimum array length: 1
Example:
max_tokens
integer

Maximum number of tokens to generate in the chat completion.

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

Sampling temperature, from 0 to 2.

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

1

top_p
number

Nucleus sampling threshold.

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

Penalize new tokens based on how often they already appear in the text.

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

Penalize new tokens if they have already appeared in the text.

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

If true, partial messages are streamed via SSE.

stop

The API stops generating further tokens when these sequences appear.

n
integer
default:1

How many completion choices to generate for each input message.

Required range: x >= 1
response_format
object

Specify the format the model must output. Set {"type": "json_object"} to enable JSON mode.

Response

Completion generated successfully

id
string
required
Example:

"chatcmpl-abc123"

object
string
required
Example:

"chat.completion"

created
integer
required

Unix timestamp when the completion was created.

model
string
required
Example:

"gemini-2.5-pro"

choices
object[]
required
usage
object