> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inputapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini generateContent

> Generate native Gemini content through a model path.

`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](/en/guides/native-gemini) 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](/en/guides/native-gemini-streaming) offers text and tool modes, preserving native result association and signatures.

[阅读中文](/zh/api-reference/gemini-generate)

## 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](/en/guides/video-understanding); 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](/en/guides/gemini-builtins).


## OpenAPI

````yaml openapi/relay.json POST /v1beta/models/{model}:generateContent
openapi: 3.0.3
info:
  title: API — Core inference API
  version: 0.5.0
  description: >-
    面向接入的精选规范，不是全部管理或供应商接口。 / Curated integration specification, not the entire
    management or provider API.
  license:
    name: AGPL-3.0-or-later
servers:
  - url: https://gateway.example.com
    description: >-
      Example only; replace with your gateway origin and optional path prefix,
      without /v1.
security:
  - BearerAuth: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: Gemini 原生生成 / Native Gemini generation
      description: >-
        精选文本接入字段；允许扩展字段不代表所有渠道支持。原生流式和工具扩展见指南。 / Selected text integration
        fields; accepting extensions does not guarantee channel support. See the
        guide for native streaming and tool boundaries.
      operationId: generateGeminiContent
      parameters:
        - name: model
          in: path
          required: true
          description: >-
            裸模型 ID，不含 models/ 和动作后缀 / Bare model ID without models/ or an action
            suffix.
          schema:
            type: string
            example: YOUR_MODEL_ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
              properties:
                contents:
                  type: array
                  minItems: 1
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                      parts:
                        type: array
                        items:
                          type: object
                          properties:
                            text:
                              type: string
                            thought:
                              type: boolean
                            thoughtSignature:
                              type: string
                            functionCall:
                              type: object
                              properties:
                                id:
                                  type: string
                                name:
                                  type: string
                                args:
                                  type: object
                                  additionalProperties: true
                              additionalProperties: true
                            functionResponse:
                              type: object
                              properties:
                                id:
                                  type: string
                                name:
                                  type: string
                                response:
                                  type: object
                                  additionalProperties: true
                              additionalProperties: true
                            inlineData:
                              type: object
                              required:
                                - mimeType
                                - data
                              properties:
                                mimeType:
                                  type: string
                                  example: video/mp4
                                data:
                                  type: string
                                  description: >-
                                    纯 Base64，不带 Data URL 前缀 / Plain Base64, no
                                    Data URL prefix
                              description: >-
                                原生内联媒体，格式与大小依模型 / Native inline media;
                                model-dependent formats and limits
                            fileData:
                              type: object
                              properties:
                                mimeType:
                                  type: string
                                fileUri:
                                  type: string
                              description: >-
                                上游可访问的 URI；不是网关上传服务 / Upstream-accessible URI,
                                not a gateway upload service
                            videoMetadata:
                              type: object
                              additionalProperties: true
                              description: >-
                                模型依赖的原生扩展；请核对实际上游结构 / Model-dependent native
                                extension; verify the upstream structure
                            mediaResolution:
                              type: object
                              additionalProperties: true
                              description: >-
                                模型依赖的原生扩展；请核对实际上游结构 / Model-dependent native
                                extension; verify the upstream structure
                            executableCode:
                              type: object
                              properties:
                                language:
                                  type: string
                                  example: PYTHON
                                code:
                                  type: string
                              additionalProperties: true
                            codeExecutionResult:
                              type: object
                              properties:
                                outcome:
                                  type: string
                                  description: 检查 OUTCOME_OK / Check OUTCOME_OK
                                output:
                                  type: string
                              additionalProperties: true
                          additionalProperties: true
                    additionalProperties: true
                systemInstruction:
                  type: object
                  properties:
                    role:
                      type: string
                    parts:
                      type: array
                      items:
                        type: object
                        properties:
                          text:
                            type: string
                          thought:
                            type: boolean
                          thoughtSignature:
                            type: string
                          functionCall:
                            type: object
                            properties:
                              id:
                                type: string
                              name:
                                type: string
                              args:
                                type: object
                                additionalProperties: true
                            additionalProperties: true
                          functionResponse:
                            type: object
                            properties:
                              id:
                                type: string
                              name:
                                type: string
                              response:
                                type: object
                                additionalProperties: true
                            additionalProperties: true
                        additionalProperties: true
                  additionalProperties: true
                tools:
                  type: array
                  items:
                    type: object
                    properties:
                      functionDeclarations:
                        type: array
                        items:
                          type: object
                          required:
                            - name
                          properties:
                            name:
                              type: string
                            description:
                              type: string
                            parameters:
                              type: object
                              additionalProperties: true
                              description: >-
                                工具参数 Schema；示例额外执行本地校验 / Tool parameter schema;
                                examples also validate locally.
                          additionalProperties: true
                      googleSearch:
                        type: object
                        additionalProperties: true
                        description: >-
                          以空对象启用；依赖原生模型及渠道支持 / Enable with an empty object;
                          native model and channel support required
                        example: {}
                      urlContext:
                        type: object
                        additionalProperties: true
                        description: >-
                          以空对象启用；依赖原生模型及渠道支持 / Enable with an empty object;
                          native model and channel support required
                        example: {}
                      codeExecution:
                        type: object
                        additionalProperties: true
                        description: >-
                          以空对象启用；依赖原生模型及渠道支持 / Enable with an empty object;
                          native model and channel support required
                        example: {}
                    additionalProperties: true
              additionalProperties: true
      responses:
        '200':
          description: 检查原生完成状态及内容 / Check native completion status and content.
          content:
            application/json:
              schema:
                type: object
                properties:
                  candidates:
                    type: array
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                        content:
                          type: object
                          properties:
                            role:
                              type: string
                            parts:
                              type: array
                              items:
                                type: object
                                properties:
                                  text:
                                    type: string
                                  thought:
                                    type: boolean
                                  thoughtSignature:
                                    type: string
                                  functionCall:
                                    type: object
                                    properties:
                                      id:
                                        type: string
                                      name:
                                        type: string
                                      args:
                                        type: object
                                        additionalProperties: true
                                    additionalProperties: true
                                  functionResponse:
                                    type: object
                                    properties:
                                      id:
                                        type: string
                                      name:
                                        type: string
                                      response:
                                        type: object
                                        additionalProperties: true
                                    additionalProperties: true
                                  executableCode:
                                    type: object
                                    properties:
                                      language:
                                        type: string
                                        example: PYTHON
                                      code:
                                        type: string
                                    additionalProperties: true
                                  codeExecutionResult:
                                    type: object
                                    properties:
                                      outcome:
                                        type: string
                                        description: 检查 OUTCOME_OK / Check OUTCOME_OK
                                      output:
                                        type: string
                                    additionalProperties: true
                                additionalProperties: true
                          additionalProperties: true
                        finishReason:
                          type: string
                        groundingMetadata:
                          type: object
                          additionalProperties: true
                          properties:
                            groundingChunks:
                              type: array
                              items:
                                type: object
                                additionalProperties: true
                            groundingSupports:
                              type: array
                              items:
                                type: object
                                additionalProperties: true
                            searchEntryPoint:
                              type: object
                              additionalProperties: true
                          description: >-
                            保留来源与原始 part 的关联；片段偏移为 UTF-8 字节 / Preserve source
                            and original part association; segment offsets are
                            UTF-8 bytes
                        urlContextMetadata:
                          type: object
                          additionalProperties: true
                          properties:
                            urlMetadata:
                              type: array
                              items:
                                type: object
                                properties:
                                  retrievedUrl:
                                    type: string
                                  urlRetrievalStatus:
                                    type: string
                          description: >-
                            原生响应中的读取状态，HTTP 成功不代表读取成功 / Native retrieval status;
                            HTTP success does not establish retrieval success
                      additionalProperties: true
                  promptFeedback:
                    type: object
                    additionalProperties: true
                  usageMetadata:
                    type: object
                    additionalProperties: true
                additionalProperties: true
              example:
                candidates:
                  - index: 0
                    finishReason: STOP
                    content:
                      role: model
                      parts:
                        - text: Hello.
        default:
          description: >-
            网关或上游错误，结构可能随协议变化 / Gateway or upstream error; structure may vary by
            protocol.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
      security:
        - GeminiApiKey: []
        - BearerAuth: []
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 模型调用 API Key，不是控制台登录凭据 / Model API key, not console login credentials
    GeminiApiKey:
      type: apiKey
      in: header
      name: x-goog-api-key
      description: 网关令牌 / Gateway token

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.