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

# Gemini文本&图片

# ominiapi Gemini 原生格式接口文档

## 1. 通用信息

**Base URL**

```text theme={null}
https://www.ominiapi.com
```

**请求头**

```http theme={null}
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

**接口格式**

```http theme={null}
POST /v1beta/models/{model}:generateContent/
```

`model` 为路径参数，表示要调用的模型名称。实际可用模型以 ominiapi/new-api 后台渠道配置为准。

## 2. 文本生成接口

### 接口地址

```http theme={null}
POST /v1beta/models/{model}:generateContent/
```

### 请求 URL 示例

```text theme={null}
https://www.ominiapi.com/v1beta/models/gemini-3.1-pro-preview:generateContent/
```

### 请求参数

| 参数                                 | 类型      | 必填 | 说明              |
| ---------------------------------- | ------- | -- | --------------- |
| `contents`                         | array   | 是  | 输入内容列表          |
| `contents[].role`                  | string  | 否  | 消息角色，通常为 `user` |
| `contents[].parts`                 | array   | 是  | 内容片段列表          |
| `contents[].parts[].text`          | string  | 是  | 文本提示词           |
| `generationConfig`                 | object  | 否  | 生成配置            |
| `generationConfig.maxOutputTokens` | integer | 否  | 最大输出 token 数    |

### 请求体示例

```json theme={null}
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "用一句话描述量子纠缠"
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 500
  }
}
```

### curl 示例

```bash theme={null}
curl -X POST "https://www.ominiapi.com/v1beta/models/gemini-3.1-pro-preview:generateContent/" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "用一句话描述量子纠缠"
          }
        ]
      }
    ],
    "generationConfig": {
      "maxOutputTokens": 500
    }
  }'
```

### 响应示例

```json theme={null}
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "量子纠缠是两个或多个粒子即使相隔很远，其状态仍会相互关联的量子现象。"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 10,
    "candidatesTokenCount": 28,
    "totalTokenCount": 38
  }
}
```

## 3. 图片生成接口

### 接口地址

```http theme={null}
POST /v1beta/models/{model}:generateContent/
```

### 请求 URL 示例

```text theme={null}
https://www.ominiapi.com/v1beta/models/gemini-3-pro-image:generateContent/
```

### 请求参数

| 参数                                         | 类型     | 必填 | 说明                              |
| ------------------------------------------ | ------ | -- | ------------------------------- |
| `contents`                                 | array  | 是  | 输入内容列表                          |
| `contents[].role`                          | string | 否  | 消息角色，通常为 `user`                 |
| `contents[].parts`                         | array  | 是  | 内容片段列表                          |
| `contents[].parts[].text`                  | string | 是  | 图片生成提示词                         |
| `generationConfig.responseModalities`      | array  | 是  | 响应类型，图片生成使用 `["TEXT", "IMAGE"]` |
| `generationConfig.imageConfig.aspectRatio` | string | 否  | 图片宽高比，如 `16:9`、`4:3`、`1:1`      |
| `generationConfig.imageConfig.imageSize`   | string | 否  | 图片尺寸档位，如 `1K`、`2K`、`4K`         |

### 请求体示例

```json theme={null}
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "A futuristic cyberpunk city, cinematic lighting, 8k resolution, highly detailed"
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"],
    "imageConfig": {
      "aspectRatio": "16:9",
      "imageSize": "4K"
    }
  }
}
```

### curl 示例

```bash theme={null}
curl -X POST "https://www.ominiapi.com/v1beta/models/gemini-3-pro-image:generateContent/" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "A futuristic cyberpunk city, cinematic lighting, 8k resolution, highly detailed"
          }
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["TEXT", "IMAGE"],
      "imageConfig": {
        "aspectRatio": "16:9",
        "imageSize": "4K"
      }
    }
  }'
```

### 响应示例

返回图片可能是 base64，也可能是图片 URL。

**base64 响应示例**

```json theme={null}
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "BASE64_IMAGE_DATA"
            }
          }
        ]
      }
    }
  ]
}
```

**URL 响应示例**

```json theme={null}
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "fileData": {
              "fileUri": "https://example.com/generated-image.png"
            }
          }
        ]
      }
    }
  ]
}
```

## 4. 图片编辑接口

### 接口地址

```http theme={null}
POST /v1beta/models/{model}:generateContent/
```

### 请求 URL 示例

```text theme={null}
https://www.ominiapi.com/v1beta/models/gemini-3-pro-image:generateContent/
```

### 请求参数

| 参数                                         | 类型     | 必填 | 说明                                           |
| ------------------------------------------ | ------ | -- | -------------------------------------------- |
| `contents[].parts[].text`                  | string | 是  | 图片编辑提示词                                      |
| `contents[].parts[].inline_data.mime_type` | string | 是  | 源图 MIME 类型，如 `image/png`、`image/jpeg`        |
| `contents[].parts[].inline_data.data`      | string | 是  | 源图 base64 数据，不包含 `data:image/...;base64,` 前缀 |
| `generationConfig.responseModalities`      | array  | 是  | 响应类型，图片编辑使用 `["TEXT", "IMAGE"]`              |
| `generationConfig.imageConfig.aspectRatio` | string | 否  | 图片宽高比                                        |
| `generationConfig.imageConfig.imageSize`   | string | 否  | 图片尺寸档位                                       |

### 请求体示例

```json theme={null}
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "把图片改成赛博朋克风格"
        },
        {
          "inline_data": {
            "mime_type": "image/png",
            "data": "BASE64_IMAGE_DATA"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"],
    "imageConfig": {
      "aspectRatio": "16:9",
      "imageSize": "4K"
    }
  }
}
```

### curl 示例

```bash theme={null}
curl -X POST "https://www.ominiapi.com/v1beta/models/gemini-3-pro-image:generateContent/" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "把图片改成赛博朋克风格"
          },
          {
            "inline_data": {
              "mime_type": "image/png",
              "data": "BASE64_IMAGE_DATA"
            }
          }
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["TEXT", "IMAGE"],
      "imageConfig": {
        "aspectRatio": "16:9",
        "imageSize": "4K"
      }
    }
  }'
```

### 响应示例

```json theme={null}
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "BASE64_IMAGE_DATA"
            }
          }
        ]
      }
    }
  ]
}
```
