> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# Gemini 原生

POST https://direct.beatapi.io/v1beta/models/{model}:generateContent
Content-Type: application/json

用一个 BeatAPI 密钥，通过 Gemini generateContent 请求调用 Gemini 4 Argon、Gemini 3.8 Flash 和 Gemini 3.1 Pro。- `POST /v1beta/models/{model}:generateContent` 覆盖当前所有 Gemini 模型，流式输出用 `:streamGenerateContent?alt=sse`。
- 支持文本与图片输入、文本输出、流式输出、函数调用和思考。
- 密钥放在 `x-goog-api-key` 请求头，或作为 Bearer 令牌发送。
- 模型 ID 写在 URL 里，不在请求体里。文本请求建议使用 `https://direct.beatapi.io` 作为 base URL：它不受 Cloudflare 100 秒限制，长时间的非流式请求不会被中途切断。`https://api.beatapi.io` 同样可用；如果你的网络访问不了 `direct.beatapi.io`，请改用它作为备用。两个域名的密钥、模型和价格完全一致。图片和视频 API 只使用 `https://api.beatapi.io`。POST/v1beta/models/{model}:generateContent试一试在调试窗口里打开本接口，填入你的 BeatAPI API 密钥即可发送。调用是真实的，费用从你自己的余额中扣除。## 模型把下列 ID 之一写进 URL，替换 `{model}`。| 模型 ID                    | 上下文（tokens） | 最大输出（tokens） | 定位                                           | 输入，美元 / 100 万 tokens | 输出，美元 / 100 万 tokens |
| ------------------------ | ----------- | ------------ | -------------------------------------------- | -------------------- | -------------------- |
| `gemini-4-argon`         | —           | 1,000,000    | Google Gemini 4 旗舰模型，输出上限可达 100 万 token      | \$1.00               | \$5.00               |
| `gemini-3.8-flash`       | —           | —            | Google 智能最强的 Flash 模型，面向长程软件工程、自主智能体与复杂企业工作流 | \$0.375              | \$1.875              |
| `gemini-3.1-pro-preview` | 1,048,576   | 65,536       | 侧重推理的 Gemini 预览模型，面向智能体编程与复杂问题求解             | \$1.00               | \$6.00               |- 价格为基础档，已计入折扣。长上下文档、缓存命中输入价和缓存写入价不在本表内，见[价格表](https://beatapi.io/pricing)。
- `—` 表示目录未公布该数字。本系列仍可调用的旧 ID 见[旧型号](/text-api/legacy-models)。## 快速开始把密钥放在 `BEATAPI_API_KEY`，不要把它写进浏览器代码。模型 ID 在 URL 里，所以请求体没有 `model` 字段。以下是请求示例，不是真实的模型输出记录。从 `candidates[0].content.parts[0].text` 读取答案，再检查 `candidates[0].finishReason` 和 `usageMetadata`。HTTP 200 不能证明答案满足你的任务，请在应用里校验内容。文本请求直接返回，不要为它们轮询 `/v1/tasks`。```bash title="cURL"
curl --request POST \
  --url https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent \
  --header "x-goog-api-key: $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Design a resilient webhook retry strategy for a payments API."
        }
      ]
    }
  ]
}'
``````python title="Python"
import os
import requests

response = requests.post(
    "https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent",
    headers={"x-goog-api-key": os.environ["BEATAPI_API_KEY"]},
    json={
      "contents": [
        {
          "role": "user",
          "parts": [
            {
              "text": "Design a resilient webhook retry strategy for a payments API."
            }
          ]
        }
      ]
    },
    timeout=120,
)
response.raise_for_status()
print(response.json()["candidates"][0]["content"]["parts"][0]["text"])
``````javascript title="JavaScript"
const response = await fetch("https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent", {
  method: "POST",
  headers: {
    "x-goog-api-key": process.env.BEATAPI_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Design a resilient webhook retry strategy for a payments API."
          }
        ]
      }
    ]
  }),
});
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
console.log(data.candidates[0].content.parts[0].text);
```## 端点与鉴权`POST https://direct.beatapi.io/v1beta/models/{model}:generateContent`x-goog-api-key
string
必需把你的 BeatAPI 密钥放在 `x-goog-api-key` 请求头里。也接受 `Authorization: Bearer <BEATAPI_API_KEY>`。流式输出调用 `POST /v1beta/models/{model}:streamGenerateContent?alt=sse`。密钥放在 `x-goog-api-key` 请求头，或放在 `Authorization: Bearer <key>`，两种都行。`:countTokens` 不可用，会返回 `404`。## 请求参数以上是会生效的字段。其他 Gemini 字段请求里可以带，但不起作用：`generationConfig.thinkingConfig`、`generationConfig.responseMimeType`、`generationConfig.responseSchema`、`generationConfig.seed`、`safetySettings`、`toolConfig` 和 `cachedContent`。请不要依赖它们。contents
object[]
必需对话内容，最早的一轮在前。每一项有 `role`（`user` 或 `model`）和 `parts`。一个 part 可以是 `text`、`inlineData`（`mimeType` 和 base64 的 `data`）、`fileData`（`mimeType` 和 `fileUri`）、`functionCall` 或 `functionResponse`。- 当前所有 Gemini 模型都支持图片输入：用 `inlineData`，或用带图片 URL 的 `fileData`。其他媒体类型请先测试你的文件，再依赖它。
- `contents` 为空或缺失会返回 `400 bad_request`。**示例**```json
[
  {
    "role": "user",
    "parts": [
      { "text": "What is in this image?" },
      { "inlineData": { "mimeType": "image/png", "data": "<base64>" } }
    ]
  }
]
```systemInstruction
object
可选系统提示词，写成 `{ "parts": [{ "text": "..." }] }`。只使用其中的 `text` part。**示例**```json
{
  "parts": [{ "text": "Answer in one short paragraph." }]
}
```generationConfig
object
可选生成选项。以下子字段会生效：`maxOutputTokens`、`temperature`、`topP`、`topK`、`stopSequences` 和 `candidateCount`。**示例**```json
{
  "temperature": 0.7,
  "topP": 0.95,
  "maxOutputTokens": 2048,
  "stopSequences": ["END"]
}
```generationConfig.maxOutputTokens
integer
可选生成 token 数的上限，包含思考。- 接受的最大值是 1,073,741,823，更大的值返回 `400 bad_request`。请保持在上表中该模型的最大输出以内。
- Gemini 模型默认会思考，思考 token 按输出计费，并计入这个上限。值太小时会被思考用光，答案为空，`finishReason` 为 `"MAX_TOKENS"`。哪怕只要一段很短的答案，也请预留至少 1,000 token。
- `maxOutputTokens` 还用来估算请求需要的余额。过大的值即使实际输出很短，也可能被 `402 insufficient_credits` 拒绝。按实际需要设置。generationConfig.temperature
number
可选采样温度。generationConfig.topP
number
可选核采样。值为 `0` 时被忽略。generationConfig.topK
integer
可选Top-K 采样。值为 `0` 时被忽略。generationConfig.stopSequences
string[]
可选遇到这些字符串就停止生成。最多使用 4 个。generationConfig.candidateCount
integer
可选返回的候选数。除非需要多个候选，否则不要设置。tools
object[]
可选模型可以调用的函数声明，写成 `[{ "functionDeclarations": [...] }]`。每个声明有 `name`、`description` 和 `parameters`（JSON Schema）。调用以 `functionCall` part 的形式返回；运行函数后，在下一轮 `user` 里用 `functionResponse` part 返回结果。- 只使用 `functionDeclarations`。`googleSearch`、`codeExecution` 等内置工具会被忽略。**示例**```json
[
  {
    "functionDeclarations": [
      {
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
          "type": "object",
          "properties": { "city": { "type": "string" } },
          "required": ["city"]
        }
      }
    ]
  }
]
```## 响应非流式调用返回一个 JSON 对象。以下是精简后的示例。```json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "Retry with exponential backoff and jitter, and make every handler idempotent."
          }
        ]
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 19,
    "candidatesTokenCount": 16,
    "totalTokenCount": 120,
    "thoughtsTokenCount": 85
  }
}
```### 响应字段| 字段                                          | 类型        | 说明                                                                           |
| ------------------------------------------- | --------- | ---------------------------------------------------------------------------- |
| `candidates[].content.parts[].text`         | `string`  | 答案文本。                                                                        |
| `candidates[].content.parts[].functionCall` | `object`  | 一次工具调用，含 `name` 和 `args`。                                                    |
| `candidates[].finishReason`                 | `string`  | `STOP` 表示答案完整或发起了工具调用；`MAX_TOKENS` 表示达到了 `maxOutputTokens`；`SAFETY` 表示答案被过滤。 |
| `usageMetadata.promptTokenCount`            | `integer` | 输入 token 数。                                                                  |
| `usageMetadata.candidatesTokenCount`        | `integer` | 可见答案的输出 token 数。                                                             |
| `usageMetadata.thoughtsTokenCount`          | `integer` | 思考 token 数，按输出计费。思考文本本身不会返回。                                                 |
| `usageMetadata.totalTokenCount`             | `integer` | 本次调用的全部 token 数。                                                             |## 流式输出调用 `:streamGenerateContent?alt=sse`。每个事件是一行 `data: {...}`，内容是 `candidates` 对象，形状与非流式答案相同。- 最后一个事件带有 `finishReason`，例如 `"STOP"`。
- 流式响应是 `text/event-stream`。调用模型之前发生的失败，以带 HTTP 状态码的普通 JSON 错误返回，不会作为流事件出现。
- 请设置明确的超时，并安全地重连流式响应。```text
data: {"candidates":[{"content":{"role":"model","parts":[{"text":"Retry"}]},"index":0}]}

data: {"candidates":[{"content":{"role":"model","parts":[{"text":" with backoff"}]},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":19,"candidatesTokenCount":16,"totalTokenCount":120,"thoughtsTokenCount":85}}
```## 错误| 错误或现象                                           | 原因                                                   | 处理                                                      |
| ----------------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------- |
| `400`：需要 `contents`                             | `contents` 为空或缺失。                                    | 在 `contents` 里至少放一轮对话。                                  |
| `400`：`maxOutputTokens` 无效                      | `generationConfig.maxOutputTokens` 超过 1,073,741,823。 | 调低到你实际需要的值。                                             |
| `402 insufficient_credits`                      | 余额低于请求的价格，常见原因是 `maxOutputTokens` 过大。                | 充值，或调低 `maxOutputTokens`。                               |
| `403 forbidden`                                 | 账号使用的是免费额度，而该模型不在免费清单里；或该模型不在密钥所属分组的范围内。             | 充值、改用免费模型，或使用分组能访问该模型的密钥。                               |
| `404 not_found`                                 | 模型 ID 不存在、该密钥没有开通它，或调用了 `:countTokens`。              | 用 `GET /v1/models` 查看已开通的模型。                            |
| `429 rate_limit_exceeded`                       | 达到账号或免费模型的限额。                                        | 等待 `Retry-After` 指定的时间后重试。                              |
| `200`，但 `finishReason: "MAX_TOKENS"` 且没有 `text` | 思考在写出答案之前就用完了 `maxOutputTokens`。                     | 调高 `generationConfig.maxOutputTokens`；哪怕答案很短，也至少 1,000。 |### HTTP 错误速查Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。| HTTP 状态码 | 错误码                                                      | 怎么做                                             |
| -------- | -------------------------------------------------------- | ----------------------------------------------- |
| 400      | `bad_request`、`content_policy_violation`                 | 修正请求或输入，不要原样重发。                                 |
| 401      | `missing_api_key`、`invalid_api_key`                      | 检查密钥，不要重试。                                      |
| 402      | `insufficient_credits`                                   | 充值，或提高密钥额度。过大的 `max_tokens` 也可能触发。              |
| 403      | `forbidden`                                              | 模型不在该密钥的分组或 IP 白名单内，或免费额度不能调用该模型。               |
| 404      | `not_found`                                              | 模型不存在：用 `GET /v1/models` 查看已开通的模型。              |
| 429      | `rate_limit_exceeded`                                    | 等待 `Retry-After` 或 `retry_after_seconds` 后退避重试。 |
| 500      | `internal_error`、`temporary_error`                       | 退避后重试一两次。                                       |
| 503      | `model_unavailable`、`upstream_timeout`、`temporary_error` | 退避重试，或换用其他模型。                                   |完整的错误码表和重试策略见[错误码](/errors#text-endpoints)。## 注意事项- Gemini 模型也可以用 Chat Completions、Responses 和 Anthropic Messages 调用，见 Gemini 的其他页面。
- 思考 token 按输出 token 计费。请为思考和答案一起预留输出额度，不要只按答案估算。
- 密钥只放在可信的服务端，记录响应里的请求 ID，只对 `429`、`500` 和 `503` 重试。

Reference: https://docs.beatapi.io/api-reference/text-api/gemini-native

## Authentication

- `Authorization` header (bearer token, required) — Send your API key as `Authorization: Bearer <BEATAPI_API_KEY>`.

## Servers

- `https://direct.beatapi.io` (Direct, default)
- `https://api.beatapi.io` (API)

## Request

### Path parameters

- `model` (enum, required)
  - Allowed values: `gemini-4-argon`, `gemini-3.8-flash`, `gemini-3.1-pro-preview`

### Body (application/json)

This endpoint expects an object.

- `contents` (list of V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItems, required) — 对话内容，最早的一轮在前。每一项有 `role`（`user` 或 `model`）和 `parts`。一个 part 可以是 `text`、`inlineData`（`mimeType` 和 base64 的 `data`）、`fileData`（`mimeType` 和 `fileUri`）、`functionCall` 或 `functionResponse`。 当前所有 Gemini 模型都支持图片输入：用 `inlineData`，或用带图片 URL 的 `fileData`。其他媒体类型请先测试你的文件，再依赖它。 `contents` 为空或缺失会返回 `400 bad_request`。
- `systemInstruction` (V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaSystemInstruction, optional) — 系统提示词，写成 `{ "parts": [{ "text": "..." }] }`。只使用其中的 `text` part。
- `generationConfig` (V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaGenerationConfig, optional) — 生成选项。以下子字段会生效：`maxOutputTokens`、`temperature`、`topP`、`topK`、`stopSequences` 和 `candidateCount`。
- `tools` (list of V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaToolsItems, optional) — 模型可以调用的函数声明，写成 `[{ "functionDeclarations": [...] }]`。每个声明有 `name`、`description` 和 `parameters`（JSON Schema）。调用以 `functionCall` part 的形式返回；运行函数后，在下一轮 `user` 里用 `functionResponse` part 返回结果。 只使用 `functionDeclarations`。`googleSearch`、`codeExecution` 等内置工具会被忽略。

## Response

### 200

非流式调用返回一个 JSON 对象。以下是精简后的示例。

- `candidates` (list of V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaCandidatesItems, optional)
- `usageMetadata` (V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaUsageMetadata, optional)

## Errors

### 400 Bad Request Error

`bad_request`、`content_policy_violation` 修正请求或输入，不要原样重发。 Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 401 Unauthorized Error

`missing_api_key`、`invalid_api_key` 检查密钥，不要重试。 Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 402 Payment Required Error

`insufficient_credits` 充值，或提高密钥额度。过大的 `max_tokens` 也可能触发。 Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 403 Forbidden Error

`forbidden` 模型不在该密钥的分组或 IP 白名单内，或免费额度不能调用该模型。 Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 404 Not Found Error

`not_found` 模型不存在：用 `GET /v1/models` 查看已开通的模型。 Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 429 Too Many Requests Error

`rate_limit_exceeded` 等待 `Retry-After` 或 `retry_after_seconds` 后退避重试。 Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 500 Internal Server Error

`internal_error`、`temporary_error` 退避后重试一两次。 Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

### 503 Service Unavailable Error

`model_unavailable`、`upstream_timeout`、`temporary_error` 退避重试，或换用其他模型。 Gemini 原生端点的错误只有一种格式 `{"error": {"message", "type": "beatapi_error", "code"}}`：错误码在 `error.code`，request id 附在 `message` 末尾，没有 `retryable` 字段。详见[错误码](/errors#text-endpoints)。

- `map from string to any`

## Types

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItems

- `parts` (list of V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItems, required)
- `role` (string, optional)

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaSystemInstruction

系统提示词，写成 `{ "parts": [{ "text": "..." }] }`。只使用其中的 `text` part。

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaGenerationConfig

生成选项。以下子字段会生效：`maxOutputTokens`、`temperature`、`topP`、`topK`、`stopSequences` 和 `candidateCount`。

- `maxOutputTokens` (integer, optional) — 生成 token 数的上限，包含思考。 接受的最大值是 1,073,741,823，更大的值返回 `400 bad_request`。请保持在上表中该模型的最大输出以内。 Gemini 模型默认会思考，思考 token 按输出计费，并计入这个上限。值太小时会被思考用光，答案为空，`finishReason` 为 `"MAX_TOKENS"`。哪怕只要一段很短的答案，也请预留至少 1,000 token。 `maxOutputTokens` 还用来估算请求需要的余额。过大的值即使实际输出很短，也可能被 `402 insufficient_credits` 拒绝。按实际需要设置。
- `temperature` (double, optional) — 采样温度。
- `topP` (double, optional) — 核采样。值为 `0` 时被忽略。
- `topK` (integer, optional) — Top-K 采样。值为 `0` 时被忽略。
- `stopSequences` (list of string, optional) — 遇到这些字符串就停止生成。最多使用 4 个。
- `candidateCount` (integer, optional) — 返回的候选数。除非需要多个候选，否则不要设置。

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaToolsItems

### V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaCandidatesItems

- `content` (V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaCandidatesItemsContent, optional)
- `finishReason` (string, optional) — `STOP` 表示答案完整或发起了工具调用；`MAX_TOKENS` 表示达到了 `maxOutputTokens`；`SAFETY` 表示答案被过滤。

### V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaUsageMetadata

- `promptTokenCount` (integer, optional) — 输入 token 数。
- `candidatesTokenCount` (integer, optional) — 可见答案的输出 token 数。
- `thoughtsTokenCount` (integer, optional) — 思考 token 数，按输出计费。思考文本本身不会返回。
- `totalTokenCount` (integer, optional) — 本次调用的全部 token 数。

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItems

- `text` (string, optional)
- `inlineData` (V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItemsInlineData, optional)
- `fileData` (V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItemsFileData, optional)
- `functionCall` (V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItemsFunctionCall, optional)
- `functionResponse` (V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItemsFunctionResponse, optional)

### V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaCandidatesItemsContent

- `parts` (list of V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaCandidatesItemsContentPartsItems, optional)

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItemsInlineData

- `mimeType` (string, optional)
- `data` (string, optional)

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItemsFileData

- `mimeType` (string, optional)
- `fileUri` (string, optional)

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItemsFunctionCall

### V1BetaModelsModelGenerateContentPostRequestBodyContentApplicationJsonSchemaContentsItemsPartsItemsFunctionResponse

### V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaCandidatesItemsContentPartsItems

- `text` (string, optional) — 答案文本。
- `functionCall` (V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaCandidatesItemsContentPartsItemsFunctionCall, optional) — 一次工具调用，含 `name` 和 `args`。

### V1BetaModelsModelGenerateContentPostResponsesContentApplicationJsonSchemaCandidatesItemsContentPartsItemsFunctionCall

一次工具调用，含 `name` 和 `args`。

## Examples

**Request**

```json
{
  "contents": [
    {
      "parts": [
        {
          "text": "Design a resilient webhook retry strategy for a payments API."
        }
      ],
      "role": "user"
    }
  ]
}
```

**Response**

```json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Retry with exponential backoff and jitter, and make every handler idempotent."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 19,
    "candidatesTokenCount": 16,
    "thoughtsTokenCount": 85,
    "totalTokenCount": 120
  }
}
```

**SDK Code**

```python 快速开始
import requests

url = "https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent"

payload = { "contents": [
        {
            "parts": [{ "text": "Design a resilient webhook retry strategy for a payments API." }],
            "role": "user"
        }
    ] }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 快速开始
const url = 'https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"contents":[{"parts":[{"text":"Design a resilient webhook retry strategy for a payments API."}],"role":"user"}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 快速开始
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent"

	payload := strings.NewReader("{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Design a resilient webhook retry strategy for a payments API.\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 快速开始
require 'uri'
require 'net/http'

url = URI("https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Design a resilient webhook retry strategy for a payments API.\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java 快速开始
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Design a resilient webhook retry strategy for a payments API.\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ]\n}")
  .asString();
```

```php 快速开始
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent', [
  'body' => '{
  "contents": [
    {
      "parts": [
        {
          "text": "Design a resilient webhook retry strategy for a payments API."
        }
      ],
      "role": "user"
    }
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 快速开始
using RestSharp;

var client = new RestClient("https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Design a resilient webhook retry strategy for a payments API.\"\n        }\n      ],\n      \"role\": \"user\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 快速开始
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["contents": [
    [
      "parts": [["text": "Design a resilient webhook retry strategy for a payments API."]],
      "role": "user"
    ]
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```