URL context

POST /v1beta/models/gemini-2.5-pro:generateContent

MethodPOST
Path/v1beta/models/gemini-2.5-pro:generateContent
Typehttp
Status1
Module2102810
Folder61214320

说明

官方文档:https://ai.google.dev/gemini-api/docs/url-context?hl=zh-cn

借助网址上下文工具,您可以网址的形式向模型提供更多上下文。通过在请求中添加网址,模型将访问这些网页中的内容(只要不是限制部分中列出的网址类型),从而为回答提供信息并提高回答质量。

网址上下文工具适用于以下任务:

提取数据:从多个网址中提取价格、名称或关键发现等特定信息。 比较文档:分析多份报告、文章或 PDF,以找出差异并跟踪趋势。 综合和创建内容:结合多个来源网址中的信息,生成准确的摘要、博文或报告。 分析代码和文档:指向 GitHub 代码库或技术文档,以解释代码、生成设置说明或回答问题。

概览

MethodPOST
Path/v1beta/models/gemini-2.5-pro:generateContent
Typehttp
Status1
Module2102810
Folder61214320

参数

{
  "query": [
    {
      "name": "key",
      "required": true,
      "description": "",
      "id": "b4inb5ENt1",
      "type": "string",
      "enable": true,
      "sampleValue": "{{YOUR_API_KEY}}"
    }
  ],
  "header": [
    {
      "name": "Content-Type",
      "required": true,
      "description": "",
      "id": "fuFf2peRev",
      "type": "string",
      "enable": true,
      "sampleValue": "application/json"
    }
  ]
}

请求体

{
  "type": "application/json",
  "parameters": [],
  "jsonSchema": {
    "type": "object",
    "properties": {
      "contents": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "parts": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "required": [
      "contents"
    ]
  },
  "mediaType": "",
  "examples": [
    {
      "mediaType": "application/json",
      "value": "{\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"Interpreting this website https://www.youtube.com/watch?v=QCvF8mCPwdQ\"\n        }\n      ]\n    }\n  ],\n  \"tools\": [\n    {\n      \"UrlContext\": {}\n    }\n  ]\n}",
      "name": "示例"
    }
  ],
  "oasExtensions": ""
}

响应

[
  {
    "id": 698912946,
    "name": "成功",
    "code": 200,
    "contentType": "json",
    "jsonSchema": {
      "type": "object",
      "properties": {}
    },
    "itemSchema": {},
    "description": "",
    "mediaType": "",
    "headers": [],
    "oasExtensions": ""
  }
]