Gemini 函数调用接口 (Function Calling)

POST https://api.apizt.com/v1beta/models/gemini-3.8-flash:generateContent 在线调试 →

本页使用 gemini-3.8-flash,适用于文本与多模态理解;输出为文本。原生思考字段是 generationConfig.thinkingConfig.thinkingLevel(low/medium/high)。查看协议和型号边界。

▼ Authorization

在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token

示例: Authorization: Bearer ********************

官方文档:https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn&example=meeting

请求参数

Header 参数
Authorizationstring必需
Bearer Token;从环境变量 tokenba_API_KEY 读取。
Content-Typestring必需
示例:application/json
Body 参数application/json
contentsarray必需
结构见完整 JSON 示例。
toolsarray可选
结构见完整 JSON 示例。

完整 JSON 请求体

{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "安排 Bob 和 Alice 在 2026-10-15 10:00 讨论项目计划。"
        }
      ]
    }
  ],
  "tools": [
    {
      "functionDeclarations": [
        {
          "name": "schedule_meeting",
          "description": "Schedules a meeting with specified attendees at a given time and date.",
          "parameters": {
            "type": "object",
            "properties": {
              "attendees": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "List of people attending the meeting."
              },
              "date": {
                "type": "string",
                "description": "Date of the meeting (e.g., '2024-07-29')"
              },
              "time": {
                "type": "string",
                "description": "Time of the meeting (e.g., '15:00')"
              },
              "topic": {
                "type": "string",
                "description": "The subject or topic of the meeting."
              }
            },
            "required": [
              "attendees",
              "date",
              "time",
              "topic"
            ]
          }
        }
      ]
    }
  ]
}

请求示例代码

curl --fail-with-body --request POST 'https://api.apizt.com/v1beta/models/gemini-3.8-flash:generateContent' \
  --header "Authorization: Bearer ${tokenba_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "安排 Bob 和 Alice 在 2026-10-15 10:00 讨论项目计划。"
        }
      ]
    }
  ],
  "tools": [
    {
      "functionDeclarations": [
        {
          "name": "schedule_meeting",
          "description": "Schedules a meeting with specified attendees at a given time and date.",
          "parameters": {
            "type": "object",
            "properties": {
              "attendees": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "List of people attending the meeting."
              },
              "date": {
                "type": "string",
                "description": "Date of the meeting (e.g., '\''2024-07-29'\'')"
              },
              "time": {
                "type": "string",
                "description": "Time of the meeting (e.g., '\''15:00'\'')"
              },
              "topic": {
                "type": "string",
                "description": "The subject or topic of the meeting."
              }
            },
            "required": [
              "attendees",
              "date",
              "time",
              "topic"
            ]
          }
        }
      ]
    }
  ]
}'
async function main() {
  const headers = {
  "Authorization": "Bearer " + process.env.tokenba_API_KEY,
  "Content-Type": "application/json"
};
  const body = JSON.stringify({
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "安排 Bob 和 Alice 在 2026-10-15 10:00 讨论项目计划。"
        }
      ]
    }
  ],
  "tools": [
    {
      "functionDeclarations": [
        {
          "name": "schedule_meeting",
          "description": "Schedules a meeting with specified attendees at a given time and date.",
          "parameters": {
            "type": "object",
            "properties": {
              "attendees": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "List of people attending the meeting."
              },
              "date": {
                "type": "string",
                "description": "Date of the meeting (e.g., '2024-07-29')"
              },
              "time": {
                "type": "string",
                "description": "Time of the meeting (e.g., '15:00')"
              },
              "topic": {
                "type": "string",
                "description": "The subject or topic of the meeting."
              }
            },
            "required": [
              "attendees",
              "date",
              "time",
              "topic"
            ]
          }
        }
      ]
    }
  ]
});
  const response = await fetch("https://api.apizt.com/v1beta/models/gemini-3.8-flash:generateContent", { method: "POST", headers, body });
  if (!response.ok) throw new Error("HTTP " + response.status + ": " + await response.text());
  console.log(await response.text());
}
main().catch(console.error);
import os
import requests

headers = {"Authorization": "Bearer " + os.environ["tokenba_API_KEY"]}
payload = {'contents': [{'role': 'user',
               'parts': [{'text': '安排 Bob 和 Alice 在 2026-10-15 10:00 讨论项目计划。'}]}],
 'tools': [{'functionDeclarations': [{'name': 'schedule_meeting',
                                      'description': 'Schedules a meeting with '
                                                     'specified attendees at a given '
                                                     'time and date.',
                                      'parameters': {'type': 'object',
                                                     'properties': {'attendees': {'type': 'array',
                                                                                  'items': {'type': 'string'},
                                                                                  'description': 'List '
                                                                                                 'of '
                                                                                                 'people '
                                                                                                 'attending '
                                                                                                 'the '
                                                                                                 'meeting.'},
                                                                    'date': {'type': 'string',
                                                                             'description': 'Date '
                                                                                            'of '
                                                                                            'the '
                                                                                            'meeting '
                                                                                            '(e.g., '
                                                                                            "'2024-07-29')"},
                                                                    'time': {'type': 'string',
                                                                             'description': 'Time '
                                                                                            'of '
                                                                                            'the '
                                                                                            'meeting '
                                                                                            '(e.g., '
                                                                                            "'15:00')"},
                                                                    'topic': {'type': 'string',
                                                                              'description': 'The '
                                                                                             'subject '
                                                                                             'or '
                                                                                             'topic '
                                                                                             'of '
                                                                                             'the '
                                                                                             'meeting.'}},
                                                     'required': ['attendees',
                                                                  'date',
                                                                  'time',
                                                                  'topic']}}]}]}
response = requests.post('https://api.apizt.com/v1beta/models/gemini-3.8-flash:generateContent', headers=headers, json=payload, timeout=120)
response.raise_for_status()
print(response.text)

返回响应

文本位于 candidates[].content.parts[].text。按 Part 类型解析;工具调用为 functionCall,图片或音频为 inlineData,思考摘要可带 thought。工具循环需保留 thoughtSignature。

以下为结构示例,不代表实际调用结果。

{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "functionCall": {
              "name": "schedule_meeting",
              "args": {
                "attendees": [
                  "Bob",
                  "Alice"
                ],
                "date": "2026-10-15",
                "time": "10:00",
                "topic": "项目计划"
              }
            }
          }
        ]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 10,
    "candidatesTokenCount": 8,
    "totalTokenCount": 18
  }
}

当前模型与版本

依据 apizt 价格页,同步于 。以下型号按目录声明的协议与本页用途筛选;不代表所有参数和功能通用。切换前请核对型号说明、令牌分组与参数差异。Gemini 原生接口需同时替换 URL 中的模型 ID。

模型 ID能力标签支持分组
gemini-3.8-flash对话,识图,工具
分组(9)

Aistudio-Gemini-1、Aistudio-Gemini-2、Aistudio-Gemini-3、Aistudio-Gemini-4、Anti-Gemini-1、Cli-Gemini-1、Vertex-Gemini-1、Vertex-Gemini-2、Vertex-Gemini-3

gemini-3.1-pro-preview对话,思考,多模态
分组(9)

Aistudio-Gemini-1、Aistudio-Gemini-2、Aistudio-Gemini-3、Aistudio-Gemini-4、Anti-Gemini-1、Cli-Gemini-1、Vertex-Gemini-1、Vertex-Gemini-2、Vertex-Gemini-3

gemini-3.5-flash-lite对话,工具,识图
分组(9)

Aistudio-Gemini-1、Aistudio-Gemini-2、Aistudio-Gemini-3、Aistudio-Gemini-4、Anti-Gemini-1、Cli-Gemini-1、Vertex-Gemini-1、Vertex-Gemini-2、Vertex-Gemini-3

gemini-3-flash-preview对话,识图,工具
分组(9)

Aistudio-Gemini-1、Aistudio-Gemini-2、Aistudio-Gemini-3、Aistudio-Gemini-4、Anti-Gemini-1、Cli-Gemini-1、Vertex-Gemini-1、Vertex-Gemini-2、Vertex-Gemini-3

gemini-3.7-flash对话,识图,工具
分组(9)

Aistudio-Gemini-1、Aistudio-Gemini-2、Aistudio-Gemini-3、Aistudio-Gemini-4、Anti-Gemini-1、Cli-Gemini-1、Vertex-Gemini-1、Vertex-Gemini-2、Vertex-Gemini-3

gemini-3.1-flash-lite对话,工具,识图
分组(9)

Aistudio-Gemini-1、Aistudio-Gemini-2、Aistudio-Gemini-3、Aistudio-Gemini-4、Anti-Gemini-1、Cli-Gemini-1、Vertex-Gemini-1、Vertex-Gemini-2、Vertex-Gemini-3

gemini-3.5-flash对话,工具,识图
分组(9)

Aistudio-Gemini-1、Aistudio-Gemini-2、Aistudio-Gemini-3、Aistudio-Gemini-4、Anti-Gemini-1、Cli-Gemini-1、Vertex-Gemini-1、Vertex-Gemini-2、Vertex-Gemini-3

gemini-2.5-pro对话,识图,思考
分组(8)

Aistudio-Gemini-2、Aistudio-Gemini-3、Aistudio-Gemini-4、Anti-Gemini-1、Cli-Gemini-1、Vertex-Gemini-1、Vertex-Gemini-2、Vertex-Gemini-3

共列入 16 个候选型号。查看完整模型、版本与接口目录。