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

# Gemini generateContent

> Gemini 兼容的内容生成接口。

使用 `/v1beta/models/{model}:generateContent` 调用 Gemini 兼容接口。

```bash theme={null}
curl https://apiany.ai/v1beta/models/gemini-3.5-flash:generateContent \
  -H "Authorization: Bearer $APIANY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [
          { "text": "解释为什么媒体生成任务适合异步处理。" }
        ]
      }
    ]
  }'
```

路径中的 `model` 是 APIAny.AI 的公开模型 ID。

## 流式

把路径里的 `:generateContent` 换成 `:streamGenerateContent`，即可获得
Gemini SSE 流（逐块返回增量 `candidates`）。

```bash theme={null}
curl https://apiany.ai/v1beta/models/gemini-3.5-flash:streamGenerateContent \
  -H "Authorization: Bearer $APIANY_API_KEY" \
  -H "Content-Type: application/json" -N \
  -d '{ "contents": [ { "parts": [ { "text": "你好" } ] } ] }'
```

## 结构化输出

用 `generationConfig.responseMimeType: "application/json"` 配合 `responseSchema`
得到 JSON 输出：

```json theme={null}
{
  "contents": [{ "parts": [{ "text": "抽取姓名和年龄" }] }],
  "generationConfig": {
    "responseMimeType": "application/json",
    "responseSchema": {
      "type": "object",
      "properties": { "name": { "type": "string" }, "age": { "type": "integer" } }
    }
  }
}
```

## 参数

支持 `generationConfig`：`temperature`、`topP`、`topK`、`maxOutputTokens`、
`stopSequences`、`responseMimeType`、`responseSchema`、`responseModalities`
（含 `IMAGE` 时返回图片）。另支持顶层 `tools`（functionDeclarations）与
`systemInstruction`。
