搜索网络并获取带有实时信息的 AI 驱动答案
POST /v1beta/models/gemini-2.5-pro:generateContent{
"tools": [
{
"google_search": {}
}
]
}{
"tools": [
{
"google_search": {
"timeRangeFilter": {
"startTime": "2024-01-01T00:00:00Z",
"endTime": "2024-12-31T23:59:59Z"
}
}
}
]
}| Parameter | Type | Required | Default | Range / Example | Description |
|---|---|---|---|---|---|
tools | array | No | - | - | 请求使用的工具数组。 |
tools.googleSearch | object | No | - | - | Google Search Grounding 的配置。 |
tools.googleSearch.timeRangeFilter | object | No | - | - | 可选的搜索时间范围过滤器。 |
tools.googleSearch.timeRangeFilter.startTime | string | No | - | 2024-01-01T00:00:00Z or timestamp | 可选的搜索开始时间,ISO 8601 格式或时间戳。 |
tools.googleSearch.timeRangeFilter.endTime | string | No | - | 2024-01-01T00:00:00Z or timestamp | 可选的搜索结束时间,ISO 8601 格式或时间戳。注意:对于 Gemini 3 模型,时间跨度不能超过 24 小时。 |
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Based on my search, Spain won the Euro 2024...",
"thoughtSignature": "Cv0oAY89a19fZ/pV0io*****"
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 1097,
"candidatesTokenCount": 403,
"totalTokenCount": 2779
},
"modelVersion": "gemini-2.5-pro"
}| Error Code | Error Name | Description |
|---|---|---|
| 401 | Unauthorized | API 密钥缺失或无效 |
| 403 | Forbidden | 您的 API 密钥没有访问此资源的权限,或余额不足以执行请求的操作 |
| 429 | Too Many Requests | 您已超出速率限制 |
| 500 | Internal server error | 发生内部服务器错误 |
| 503 | Content policy violation | 内容因安全问题被阻止(实际状态码为 400) |