Skip to main content
POST

Models you can use

See GET /v1/models for the full list.

Multi-turn conversations

Alternate role: user and role: model entries in the contents array to build a multi-turn conversation.

Media recognition

Add an inlineData entry in parts with a mimeType (e.g. image/jpeg, application/pdf, audio/mpeg, video/mp4) and the base64-encoded file data.

Streaming

Replace :generateContent in the path with :streamGenerateContent?alt=sse to switch to SSE streaming mode.

Safety filtering

Use safetySettings to adjust the blocking threshold for each harm category.

System instructions

Pass a system-level prompt via systemInstruction, using the same parts format as contents.

Authorizations

Authorization
string
header
required

Bearer token authentication, format: Authorization: Bearer sk-xxxxxx. Get your API key in the console.

Path Parameters

model
string
required

Model name, e.g. gemini-2.5-pro or gemini-2.5-flash.

Example:

"gemini-2.5-pro"

Body

application/json

Gemini generateContent request body, used for both text chat and media recognition.

contents
object[]

Conversation contents in chronological order. Each element has a role (user or model) and a parts array of content fragments.

generationConfig
object

Generation parameter configuration.

safetySettings
object[]

Safety filter settings to adjust blocking thresholds per harm category.

tools
object[]

Tool list for function calling.

systemInstruction
object

System-level instruction in the same format as a contents element.

Response

Successful response

Gemini generateContent response body.

candidates
object[]

List of candidate responses generated by the model.

usageMetadata
object

Token usage statistics.