Skip to main content
POST /v1beta/models/{model}:generateContent Send the gateway token in x-goog-api-key. Put the model in the path and use contents with optional systemInstruction in the body. Roles are user / model, with text in parts[]. Check promptFeedback, candidate count, and finishReason before reading candidates[].content.parts. Empty candidates, safety blocks, tools, and truncated output are not complete text answers. The native Gemini guide and complete TypeScript example cover paths, authentication, runnable code, and failures. SSE uses a separate action, :streamGenerateContent?alt=sse. This operation describes nonstreaming generateContent only; tool, multimodal, and generation configuration fields are not fully expanded. /v1beta/...:countTokens is not implemented and currently returns 404. Verified revision: d851a5faa49a00abaafd27bf91b311506fbfbc52. Source files are recorded in this operation’s x-source-files. The Python native SSE and tool-loop example offers text and tool modes, preserving native result association and signatures. 阅读中文

Media content parts

Native contents[].parts[] can contain inlineData: {mimeType, data} or fileData: {mimeType, fileUri}; inline data is plain Base64. The target upstream must support the format and source. videoMetadata and mediaResolution are conditional native extensions, not a universal gateway transcoding or frame-extraction service. Media input does not change the response protocol or completion checks. The audited gateway scope provides no Gemini Files upload/management or Interactions endpoints; SDK auto-upload introduces extra unsupported requests. Start with the complete non-streaming video example; streamed output still follows this endpoint’s SSE events.

Built-in tools and native result metadata

Use tools[].googleSearch, urlContext, or codeExecution with an empty object to enable a supported native tool. Inspect candidate groundingMetadata / urlContextMetadata, or content parts executableCode / codeExecutionResult. STOP alone does not prove execution. The current native handler forwards the original response JSON; do not infer the same behavior for converted protocols or unknown fields replayed in requests. Runnable example and completion rules.

Authorizations

x-goog-api-key
string
header
required

网关令牌 / Gateway token

Path Parameters

model
string
required

裸模型 ID,不含 models/ 和动作后缀 / Bare model ID without models/ or an action suffix.

Example:

"YOUR_MODEL_ID"

Body

application/json
contents
object[]
required
Minimum array length: 1
systemInstruction
object
tools
object[]

Response

检查原生完成状态及内容 / Check native completion status and content.

candidates
object[]
promptFeedback
object
usageMetadata
object