You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Google Discovery Engine API的streamGenerateGroundedContent遇404错误求助

解决Discovery Engine streamGenerateGroundedContent 404错误

针对调用streamGenerateGroundedContent时出现的404 "Method not found"错误(GenerateGroundedContent可正常调用),以下是排查和修复方案:

核心问题及修复

1. 请求体格式错误

streamGenerateGroundedContent不支持批量请求(数组包裹的格式),而GenerateGroundedContent允许批量请求。你当前的请求体用[]包裹,这是导致错误的主要原因之一。

2. 缺少流式响应请求头

流式接口需要明确指定Accept: text/event-stream请求头,否则服务器无法正确处理流式响应逻辑。

修正后的curl命令

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
"https://discoveryengine.googleapis.com/v1beta/projects/my-project-number/locations/global:streamGenerateGroundedContent" \
-d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Summarize How to delete a data store in Vertex AI Agent Builder?"
          }
        ]
      }
    ],
    "groundingSpec": {
      "groundingSources": [
        {
          "googleSearchSource": {}
        }
      ]
    },
    "generationSpec": {
      "modelId": "gemini-1.5-flash"
    }
}'

额外排查点

  • 确保GCP项目已正确启用Discovery Engine API(原名Vertex AI Search and Conversation API),可在GCP控制台的API库中验证。
  • 更新gcloud CLI到最新版本:执行gcloud components update,避免旧版本的权限或API支持问题。
  • 若使用Ground Generation Playground仍报错,检查Playground的请求配置,确保未使用数组格式的请求体,并添加了正确的请求头。

内容的提问来源于stack exchange,提问作者Landsharko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 15:55:08