google_search 工具(Gemini 1.5 系列旧名 googleSearchRetrieval)提供原生联网搜索 + Grounding 引用。OpenAI-Hub 透传 Google 官方协议,并支持在 /v1/chat/completions 兼容模式下用 google_search 类型。gemini-2.5-flash、gemini-2.5-pro、gemini-3-pro 等。⚠️ Gemini 1.5 系列使用旧名 googleSearchRetrieval,2.0+ 改为google_search,请按所选模型选择对应字段。
:streamGenerateContent?alt=sse&key=...,请求体相同。{
"contents": [{ "role": "user", "parts": [{ "text": "..." }] }],
"tools": [
{
"googleSearchRetrieval": {
"dynamicRetrievalConfig": {
"mode": "MODE_DYNAMIC",
"dynamicThreshold": 0.7
}
}
}
]
}dynamicThreshold (0.0–1.0):模型置信度低于该阈值才会触发检索。越高越省钱、越少检索。/v1/chat/completions:tools[].google_search 字段,引用以 tool_calls 形式回传。google_search (2.0+)| 字段 | 类型 | 说明 |
|---|---|---|
google_search | object | 占位对象,目前固定空 {} |
googleSearchRetrieval (1.5)| 字段 | 类型 | 说明 |
|---|---|---|
dynamicRetrievalConfig.mode | enum | MODE_DYNAMIC / MODE_UNSPECIFIED |
dynamicRetrievalConfig.dynamicThreshold | float | 0.0–1.0 自适应检索阈值 |
{
"candidates": [
{
"content": {
"role": "model",
"parts": [{ "text": "根据猫眼数据,2026 年五一档票房冠军是..." }]
},
"groundingMetadata": {
"webSearchQueries": ["2026 五一档电影票房"],
"groundingChunks": [
{
"web": {
"uri": "https://piaofang.maoyan.com/...",
"title": "猫眼专业版 - 五一档票房"
}
}
],
"groundingSupports": [
{
"segment": { "startIndex": 0, "endIndex": 50, "text": "..." },
"groundingChunkIndices": [0],
"confidenceScores": [0.95]
}
],
"searchEntryPoint": {
"renderedContent": "<style>...</style><div class=\"google-search-suggestion\">...</div>"
}
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 18,
"candidatesTokenCount": 320,
"totalTokenCount": 338
}
}⚠️ searchEntryPoint.renderedContent是 Google 政策强制要求展示的「搜索建议条」HTML,前端必须原样渲染(合规要求)。
| 字段 | 说明 |
|---|---|
webSearchQueries | 模型自动生成的搜索词列表 |
groundingChunks[].web.uri / .title | 检索到的网页源 |
groundingSupports[].segment | 回答中哪一段引用了哪个 chunk |
groundingSupports[].confidenceScores | 每段引用的置信度 |
searchEntryPoint.renderedContent | Google 强制 UI 元素(必须展示) |
google_search 与自定义函数 functionDeclarations 并行(1.5 系列只能二选一):{
"contents": [...],
"tools": [
{ "google_search": {} },
{
"functionDeclarations": [
{
"name": "get_weather",
"parameters": { "type": "object", "properties": { "city": { "type": "string" } } }
}
]
}
]
}curl --location --request POST 'https://api.openai-hub.com/v1beta/models/:generateContent' \
--header 'Authorization: Bearer sk-0ABIEXVjh9****Qckjy'{}