POST https://studio.dataeyes.ai/v1beta/models/{model}:generateContent
POST https://studio.dataeyes.ai/v1beta/models/{model}:streamGenerateContent?alt=sse/v1beta/models/gemini-3.8-flash:generateContent。| 方式 | 示例 |
|---|---|
请求头 x-goog-api-key(SDK 默认) | x-goog-api-key: sk-xxx |
请求头 Authorization | Authorization: Bearer sk-xxx |
URL 参数 key | ...:generateContent?key=sk-xxx |
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "我是一个人工智能助手,致力于高效地为您解答疑问、提供创意和协助完成各种任务。",
"thoughtSignature": "……"
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 11,
"candidatesTokenCount": 20,
"thoughtsTokenCount": 301,
"totalTokenCount": 332
},
"modelVersion": "gemini-3.8-flash"
}thoughtsTokenCount。| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
contents | array | 是 | 对话内容。每项包含 role(user 或 model)和 parts 数组 |
systemInstruction | object | 否 | 系统指令,如 {"parts": [{"text": "..."}]} |
generationConfig | object | 否 | 生成设置,见下表 |
tools | array | 否 | 工具:functionDeclarations、googleSearch、urlContext、codeExecution |
generationConfig 常用字段:| 字段 | 说明 |
|---|---|
temperature | 采样温度 |
maxOutputTokens | 输出 token 上限 |
thinkingConfig | 思考设置,如 {"thinkingLevel": "low"};加 "includeThoughts": true 返回思考摘要 |
responseMimeType | 设为 application/json 输出 JSON |
responseSchema | 配合 responseMimeType 约束 JSON 结构 |
parts 中可以放文本(text)、公网文件(fileData)、Base64 文件(inlineData)、函数调用结果(functionResponse)。:streamGenerateContent?alt=sse,每个 data: 块都是一个完整结构的响应片段,用量以最后一块的 usageMetadata 为准。thinkingLevel 控制思考深度(low、high);includeThoughts 为 true 时返回思考摘要。"thought": true 的 part,排在回答之前:{
"parts": [
{ "text": "**My Thought Process in Deconstructing This Logic Puzzle** ……", "thought": true },
{ "text": "**乙**说的是真话。……", "thoughtSignature": "……" }
]
}text:"{\"name\":\"张三\",\"age\":28,\"city\":\"杭州\",\"job\":\"产品经理\"}"functionCall:{
"parts": [
{
"functionCall": { "name": "get_weather", "args": { "city": "上海" } },
"thoughtSignature": "……"
}
]
}contents 中依次放入原始问题、模型返回的 part(原样保留,包括 thoughtSignature)和 functionResponse:{
"contents": [
{"role": "user", "parts": [{"text": "上海今天天气怎么样?"}]},
{"role": "model", "parts": [
{"functionCall": {"name": "get_weather", "args": {"city": "上海"}}, "thoughtSignature": "……"}
]},
{"role": "user", "parts": [
{"functionResponse": {"name": "get_weather", "response": {"city": "上海", "weather": "多云", "temperature": 22}}}
]}
],
"tools": [ ……与第一步相同…… ]
}上海今天的天气是多云,当前气温约为 22℃。| 工具 | 写法 | 作用 |
|---|---|---|
| Google 搜索 | "tools": [{"googleSearch": {}}] | 联网搜索后回答,来源在 groundingMetadata |
| URL 上下文 | "tools": [{"urlContext": {}}] | 读取提示词中的网址内容,结果在 urlContextMetadata |
| 代码执行 | "tools": [{"codeExecution": {}}] | 模型编写并运行 Python 代码,返回 executableCode 与 codeExecutionResult |
groundingMetadata(节选):{
"webSearchQueries": ["Nobel Prize in Physics 2026 winners", "2026年 诺贝尔物理学奖"],
"groundingChunks": [
{ "web": { "uri": "https://vertexaisearch.cloud.google.com/grounding-api-redirect/……", "title": "nobelprize.org" } }
]
}mimeType 改为 application/pdf。