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

# Gemini GenerateContent

> 使用 Gemini 原生内容格式生成回复

使用 `x-goog-api-key: API_KEY`。路径参数 `model` 必填。

| 字段                    | 类型           | 必填 | 说明                                               |
| --------------------- | ------------ | -- | ------------------------------------------------ |
| `contents`            | array        | 是  | 对话内容；每项含 `role` 与 `parts[]`。part 可包含文本或受模型支持的媒体。 |
| `systemInstruction`   | object       | 否  | 系统指令内容。                                          |
| `generationConfig`    | object       | 否  | 温度、topP、topK、候选数、最大输出 token、停止序列和响应 MIME/Schema。 |
| `safetySettings`      | array        | 否  | 安全类别与阈值。                                         |
| `tools`, `toolConfig` | array/object | 否  | 函数声明、代码执行、搜索等工具及配置；依模型而定。                        |
| `cachedContent`       | string       | 否  | 已缓存内容资源名。                                        |

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://api.bianxie.ai/v1beta/models/your-model:generateContent" \
    -H "x-goog-api-key: API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "contents": [{
        "role": "user",
        "parts": [{"text": "你好"}]
      }]
    }'
  ```

  ```python Python theme={null}
  import requests
  requests.post("https://api.bianxie.ai/v1beta/models/your-model:generateContent", headers={"x-goog-api-key":"API_KEY"}, json={"contents":[{"role":"user","parts":[{"text":"你好"}]}]})
  ```

  ```javascript Node.js theme={null}
  await fetch("https://api.bianxie.ai/v1beta/models/your-model:generateContent", { method: "POST", headers: { "x-goog-api-key": "API_KEY", "Content-Type": "application/json" }, body: JSON.stringify({ contents: [{ role: "user", parts: [{ text: "Hello" }] }] }) });
  ```
</CodeGroup>

响应包含 `candidates[]`、`promptFeedback`、`usageMetadata`、`modelVersion` 和 `responseId`。候选项包含内容、结束原因、安全评分等。本文档端点不声明 Gemini 的独立流式路径。
