Skip to main content

Web Search

This document explains how to use the Web Search feature on the ShuYou platform. ShuYou supports invoking Web Search via multiple compatible protocols, including Chat Completions, Messages, Responses, and Vertex AI.

Overview

Web Search allows an AI model to access real-time web information while generating an answer, enabling more accurate and up-to-date responses. This feature is particularly useful for:
  • Querying breaking news and current events
  • Getting the latest product information and pricing
  • Looking up dynamic data such as weather and stock quotes
  • Accessing the latest technical documentation and resources

Supported Protocols

1. Chat Completions API

The Chat Completions API enables Web Search via the web_search_options parameter.

Parameters

Example

2. Messages API (Anthropic-compatible)

The Messages API enables Web Search using the web_search_20250305 type within the tools parameter.

Parameters

Example

3. Responses API (OpenAI Responses)

The Responses API enables Web Search using the web_search family of types within the tools parameter.

Supported Web Search Types

Parameters

Example

4. Vertex AI API (Google-compatible)

The Vertex AI API enables Google Search Grounding via googleSearch in the tools parameter.

Parameters

In Vertex AI, Web Search is enabled via the googleSearch tool, and source information is returned in groundingMetadata in the response.

Grounding Information in the Response

Example

Response Format Comparison

Chat Completions Response

Messages Response

Responses Response

Vertex AI Response

Streaming Events (Responses API)

When using streaming mode with the Responses API, you may receive the following Web Search-related events:

Best Practices

1. Choose the Right Search Context Size

  • low: Suitable for simple queries; faster responses and lower cost
  • medium: Balanced choice for most scenarios
  • high: Suitable for complex questions that require deeper research

2. Provide User Location Information

To get more relevant localized results, provide user location information:

3. Use Domain Filtering Appropriately

In the Messages API, you can use allowed_domains or blocked_domains to control the search scope:

4. Limit the Number of Searches

In the Messages API, use max_uses to control the maximum number of searches per request to manage cost:

5. Handle Citation Information

Always check and display citation information in responses to help users verify the reliability of the sources.

Notes

  1. Billing: Web Search incurs additional charges; see the pricing documentation for details.
  2. Latency: Enabling Web Search increases response latency because a real-time search must be performed.
  3. Availability: Not all models support Web Search; confirm support for your target model.
  4. Result Accuracy: Web Search results come from the live web; accuracy depends on the search engine and source websites.

FAQ

A: You can determine this in the following ways:
  • Chat Completions: Check for url_citation in message.annotations
  • Messages: Check usage.server_tool_use.web_search_requests
  • Responses: Look for web_search_call items in output
  • Vertex AI: Check whether groundingMetadata exists

Q: Why are there sometimes no search results returned?

A: Possible reasons include:
  1. The question does not require real-time information; the model decides not to search
  2. Search results are not relevant to the question and are filtered by the model
  3. Network issues cause the search to fail

Q: How can I optimize search performance?

A: Recommendations:
  1. Ask clear, specific questions
  2. Use an appropriate search context size
  3. Provide user location information to get localized results
  4. Use domain filtering in the Messages API to focus the search scope