Skip to content

API error when using Google Search and Url Context tool together #8462

@ryan-tsang

Description

@ryan-tsang

Description

Meet API error when following the example: https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai#combine-url-context-with-search-grounding

  const result = generateText({
    model: vertex('gemini-2.5-pro'),
    messages: convertToModelMessages([message]),
    tools: {
      google_search: google.tools.googleSearch({}),
      url_context: google.tools.urlContext({}),
    },
  });

terminal display server error of

APICallError [AI_APICallError]: The GenerateContentRequest proto is invalid:
  * tools[0].tool_type: one_of 'tool_type' has more than one initialized field: google_search, url_context
  ....
  data: {
    error: {
      code: 400,
      message: 'The GenerateContentRequest proto is invalid:\n' +
        "  * tools[0].tool_type: one_of 'tool_type' has more than one initialized field: google_search, url_context",
      status: 'INVALID_ARGUMENT'
    }
  },

AI SDK Version

  • ai: 5.0.32
  • @ai-sdk/google: 2.0.12
  • @ai-sdk/google-vertex: 3.0.20

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions