> ## 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 原生协议将对话放在 `contents[].parts[]` 中，并通过 `x-goog-api-key` 鉴权。路径中的模型 ID 以[实时模型页](https://api.bianxie.ai/pricing)为准。

## 文本生成

```bash 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": "用一句话解释量子计算。"}]
    }],
    "generationConfig": {
      "temperature": 0.7,
      "maxOutputTokens": 1024
    }
  }'
```

多轮对话按顺序增加 `contents` 项，角色通常为 `user` 和 `model`。系统指令使用顶层 `systemInstruction`；温度、停止序列、最大输出长度和结构化输出配置位于 `generationConfig`。

## 返回结构

```json theme={null}
{
  "candidates": [{
    "content": {"role": "model", "parts": [{"text": "量子计算利用..."}]},
    "finishReason": "STOP"
  }],
  "usageMetadata": {
    "promptTokenCount": 12,
    "candidatesTokenCount": 24,
    "totalTokenCount": 36
  }
}
```

主要文本位于 `candidates[0].content.parts[]`。请求被安全策略拦截时，请检查 `promptFeedback` 和候选项的安全评分。
