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

# Gemini 原生格式

> 使用 Gemini 原生接口（generateContent / streamGenerateContent）进行对话与多模态交互。

## 接口

| 用途 | 路径 |
| - | - |
| 文本/多模态生成 | `POST /v1beta/models/{model}:generateContent` |
| 流式输出 | `POST /v1beta/models/{model}:streamGenerateContent?alt=sse` |

原生接口支持 `Authorization: Bearer <TOKEN>` 鉴权，也支持 `x-goog-api-key: <TOKEN>`。

## 快速开始

```bash theme={null}
curl -X POST "https://api.gregapi.com/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "你好"}]}]
  }'
```

## 流式输出

```bash theme={null}
curl -N "https://api.gregapi.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "写一首诗"}]}]
  }'
```

## 多模态输入

原生接口通过 `contents[].parts[]` 承载多模态内容：文本用 `text`，媒体用 `inline_data`（`mime_type` + Base64 `data`）。

### 音频理解

```bash theme={null}
curl -X POST "https://api.gregapi.com/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "转写这段音频"},
        {"inline_data": {"mime_type": "audio/mp3", "data": "<BASE64>"}}
      ]
    }]
  }'
```

图片同理使用 `inline_data`，`mime_type` 为 `image/png`、`image/jpeg` 等。`gemini-3-pro-preview-file` 模型支持通过 URL 直接分析视频文件，详细用法请参阅视频分析文档。

## 思考模式（Reasoning）

Gemini 2.5 和 3 系列支持思考推理能力，通过 `generationConfig.thinkingConfig` 配置。

Gemini 3 系列使用 `thinkingLevel`：

```json theme={null}
{
  "generationConfig": {
    "thinkingConfig": {"thinkingLevel": "high"}
  }
}
```

Gemini 2.5 系列使用 `thinkingBudget`：

```json theme={null}
{
  "generationConfig": {
    "thinkingConfig": {"thinkingBudget": 8192}
  }
}
```

## 生成参数

| 参数 | 说明 | 默认值 |
| - | - | - |
| `temperature` | 随机性，0-2 | 1.0 |
| `max_tokens` | 最大输出 token 数 | 模型默认 |
| `top_p` | 核采样概率 | 0.95 |
| `stop` | 停止序列 | - |

Gemini 3 建议保持 `temperature` 为 1.0，过低可能导致推理性能下降。

## SDK 示例（Python · Google SDK）

```python theme={null}
from google import genai

client = genai.Client(
    api_key="your-token",
    http_options={"base_url": "https://api.gregapi.com"},
)

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="你好",
)
print(response.text)
```


## OpenAPI

````yaml openapi/llm.yaml POST /v1beta/models/{model}:generateContent
openapi: 3.0.3
info:
  title: GregAPI 大语言模型
  version: 1.0.0
  description: GregAPI 统一网关下的大语言模型（LLM）接口，覆盖通用对话补全、多模态响应，以及各家原生消息与生成协议。
servers:
  - url: https://api.gregapi.com
security:
  - bearerAuth: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: Gemini 原生格式
      description: 使用 Gemini 原生接口（generateContent）进行对话与多模态交互，支持文本与多模态内容生成。
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
            example: gemini-2.5-flash
          description: 模型名称
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
              properties:
                contents:
                  type: array
                  description: 对话内容数组
                  items:
                    type: object
                    properties:
                      parts:
                        type: array
                        items:
                          type: object
                generationConfig:
                  type: object
                  description: 生成配置，如 temperature、thinkingConfig
            example:
              contents:
                - parts:
                    - text: 你好
      responses:
        '200':
          description: 成功返回生成结果
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

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