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

# Gemini原生格式

> Google Gemini 原生 `generateContent` 生图。

**路径：** `POST https://api.omniall.ai/v1beta/models/{model}:generateContent`

PDF / 短视频参考生图推荐使用 `gemini-nano-banana-2.1`。
`inlineData.data` 填原始 Base64，不要带 `data:` 前缀。
输出图片在 `candidates[].content.parts[].inlineData`。

鉴权：`Authorization: Bearer sk-...` 或 `x-goog-api-key`。


## 香蕉 2.1（`gemini-nano-banana-2.1`）

原生 `generateContent` 支持文生图、图生图，以及 **PDF 参考**、**短视频参考**。

| 输入 | `inlineData.mimeType` | `inlineData.data` |
| - | - | - |
| 图片 | `image/jpeg` / `image/png` 等 | 原始 Base64（不要 `data:` 前缀） |
| PDF | `application/pdf` | 原始 Base64 |
| 短视频 | `video/mp4` | 原始 Base64 |

生图时务必在 `generationConfig.responseModalities` 中包含 `IMAGE`。

### PDF 参考生图（完整）

```bash theme={null}
export BASE_URL="https://api.omniall.ai"
export API_KEY="sk-xxx"
PDF_B64=$(base64 < reference.pdf | tr -d '\n')

cat > request.json <<EOF
{
  "contents": [{
    "role": "user",
    "parts": [
      {"inlineData": {"mimeType": "application/pdf", "data": "$PDF_B64"}},
      {"text": "读取附件 PDF 的每一页。先按页序列出编号、颜色和形状，再生成一张保留这些信息的参考图。"}
    ]
  }],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"],
    "imageConfig": {"aspectRatio": "3:2", "imageSize": "1K"}
  }
}
EOF

curl --fail-with-body --max-time 180 \
  "$BASE_URL/v1beta/models/gemini-nano-banana-2.1:generateContent" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @request.json -o response.json
```

### 短视频参考生图（完整）

```bash theme={null}
VIDEO_B64=$(base64 < reference.mp4 | tr -d '\n')

cat > request.json <<EOF
{
  "contents": [{
    "role": "user",
    "parts": [
      {"inlineData": {"mimeType": "video/mp4", "data": "$VIDEO_B64"}},
      {"text": "观看完整视频，先按出现顺序列出各场景中的编号、颜色和形状，再生成一张按该顺序排列的参考图。"}
    ]
  }],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"],
    "imageConfig": {"aspectRatio": "3:2", "imageSize": "1K"}
  }
}
EOF

curl --fail-with-body --max-time 180 \
  "$BASE_URL/v1beta/models/gemini-nano-banana-2.1:generateContent" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @request.json -o response.json
```

从 `candidates[].content.parts[].inlineData` 读取输出图片（遍历全部 parts，跳过 `thought: true`）。优先使用短小的 H.264 MP4 与小体积 PDF；Base64 约膨胀三分之一。

### 可选：Thinking

香蕉 2.1 支持 `thinkingLevel`：`minimal` / `medium`（默认）/ `high`。常规接入可省略；需要时写入 `generationConfig.thinkingConfig`：

```json theme={null}
"generationConfig": {
  "responseModalities": ["TEXT", "IMAGE"],
  "imageConfig": { "aspectRatio": "3:2", "imageSize": "1K" },
  "thinkingConfig": {
    "thinkingLevel": "high",
    "includeThoughts": false
  }
}
```

`includeThoughts` 只控制是否返回思考正文，不会关闭内部思考。档位说明见 [概述 · Thinking](/zh-CN/api-reference/image-gemini#可选thinking思考档位)。


## OpenAPI

````yaml zh-CN/openapi/gemini-native-image.yaml POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: Omniall AI — Gemini原生格式
  version: 1.1.0
  description: >
    Google Gemini 原生 `generateContent` 生图（Omniall AI 转发）。


    **路径：** `POST https://api.omniall.ai/v1beta/models/{model}:generateContent`


    支持模型示例：`gemini-nano-banana-2.1`、`gemini-3.1-flash-image-preview`、`gemini-3-pro-image-preview`。

    生图请设置 `generationConfig.responseModalities` 包含 `IMAGE`。


    参考输入通过 `parts[].inlineData`：

    - 图片：`image/jpeg`、`image/png` 等

    - PDF：`application/pdf`（香蕉 2.1+）

    - 短视频：`video/mp4`（香蕉 2.1+）


    可选 Thinking（香蕉 2.1）：`generationConfig.thinkingConfig.thinkingLevel` 为
    `minimal` / `medium`（默认）/ `high`；

    `includeThoughts` 仅控制是否返回思考正文。


    鉴权：`Authorization: Bearer sk-...` 或 `x-goog-api-key`。
servers:
  - url: https://api.omniall.ai
security: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      tags:
        - Gemini图像
      summary: Gemini原生格式
      description: >
        Google Gemini 原生 `generateContent` 生图。


        **路径：** `POST
        https://api.omniall.ai/v1beta/models/{model}:generateContent`


        PDF / 短视频参考生图推荐使用 `gemini-nano-banana-2.1`。

        `inlineData.data` 填原始 Base64，不要带 `data:` 前缀。

        输出图片在 `candidates[].content.parts[].inlineData`。


        鉴权：`Authorization: Bearer sk-...` 或 `x-goog-api-key`。
      operationId: geminiNativeImageGenerateContent
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
            example: gemini-nano-banana-2.1
          description: >-
            Gemini 图像模型
            ID。示例：`gemini-nano-banana-2.1`、`gemini-3.1-flash-image-preview`。
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
            example: Bearer sk-...
          description: Bearer API Key。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
              description: Gemini 原生生图请求体。
              properties:
                contents:
                  type: array
                  description: 对话轮次。可混合文本与一个或多个 `inlineData` 媒体部件。
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        example: user
                      parts:
                        type: array
                        items:
                          type: object
                          properties:
                            text:
                              type: string
                              description: 文本提示词 / 编辑指令。
                            inlineData:
                              type: object
                              description: 内联媒体（图片 / PDF / 短 MP4），Base64。
                              properties:
                                mimeType:
                                  type: string
                                  description: >-
                                    MIME：`image/jpeg`、`application/pdf`、`video/mp4`
                                    等。
                                  example: application/pdf
                                data:
                                  type: string
                                  description: Base64 载荷，不要带 `data:` 前缀。
                generationConfig:
                  type: object
                  properties:
                    responseModalities:
                      type: array
                      items:
                        type: string
                      description: 生图必须包含 `IMAGE`。
                      example:
                        - TEXT
                        - IMAGE
                    imageConfig:
                      type: object
                      properties:
                        aspectRatio:
                          type: string
                          description: 宽高比，如 1:1、3:2、16:9。
                          enum:
                            - '1:1'
                            - '2:3'
                            - '3:2'
                            - '3:4'
                            - '4:3'
                            - '4:5'
                            - '5:4'
                            - '9:16'
                            - '16:9'
                            - '21:9'
                          example: '3:2'
                        imageSize:
                          type: string
                          description: 分辨率档位：1K / 2K / 4K。
                          enum:
                            - 1K
                            - 2K
                            - 4K
                          example: 1K
                    thinkingConfig:
                      type: object
                      description: >
                        可选。香蕉 2.1 Thinking：`thinkingLevel` 为 `minimal` /
                        `medium`（默认）/ `high`。

                        `includeThoughts` 只控制是否返回思考正文，不会关闭内部思考。
                      properties:
                        thinkingLevel:
                          type: string
                          description: 思考档位。
                          enum:
                            - minimal
                            - medium
                            - high
                          example: high
                        includeThoughts:
                          type: boolean
                          description: 是否在响应中返回思考内容。
                          example: false
            examples:
              文生图:
                summary: 文生图（香蕉 2.1）
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 生成一张黄色陶瓷马克杯放在木桌上的产品图。
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '3:2'
                      imageSize: 1K
              图生图:
                summary: 图生图
                value:
                  contents:
                    - role: user
                      parts:
                        - inlineData:
                            mimeType: image/jpeg
                            data: BASE64参考图
                        - text: 基于参考图，在同一画布下生成此物品的三视图，必须白色背景
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '16:9'
                      imageSize: 2K
              多图参考:
                summary: 多图参考
                value:
                  contents:
                    - role: user
                      parts:
                        - inlineData:
                            mimeType: image/jpeg
                            data: BASE64_REF_1
                        - inlineData:
                            mimeType: image/png
                            data: BASE64_REF_2
                        - text: 将两张参考图合并为一张干净的产品排版，保留颜色与形状。
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '3:2'
                      imageSize: 1K
              PDF参考生图:
                summary: PDF 参考生图（香蕉 2.1）
                value:
                  contents:
                    - role: user
                      parts:
                        - inlineData:
                            mimeType: application/pdf
                            data: PDF完整Base64不要带前缀
                        - text: 读取附件 PDF 的每一页。先按页序列出编号、颜色和形状，再生成一张保留这些信息的参考图。
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '3:2'
                      imageSize: 1K
              短视频参考生图:
                summary: 短视频参考生图（香蕉 2.1）
                value:
                  contents:
                    - role: user
                      parts:
                        - inlineData:
                            mimeType: video/mp4
                            data: MP4完整Base64不要带前缀
                        - text: 观看完整视频，先按出现顺序列出各场景中的编号、颜色和形状，再生成一张按该顺序排列的参考图。
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '3:2'
                      imageSize: 1K
      responses:
        '200':
          description: 成功 — 从 `candidates[].content.parts` 读取文字/图片。
        '400':
          description: 请求错误
        '401':
          description: 未授权
        '413':
          description: 请求体过大（Base64 约膨胀 1/3）

````

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