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 theweb_search_options parameter.
Parameters
Example
2. Messages API (Anthropic-compatible)
The Messages API enables Web Search using theweb_search_20250305 type within the tools parameter.
Parameters
Example
3. Responses API (OpenAI Responses)
The Responses API enables Web Search using theweb_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 viagoogleSearch in the tools parameter.
Parameters
In Vertex AI, Web Search is enabled via thegoogleSearch 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 costmedium: Balanced choice for most scenarioshigh: 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 useallowed_domains or blocked_domains to control the search scope:
4. Limit the Number of Searches
In the Messages API, usemax_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
- Billing: Web Search incurs additional charges; see the pricing documentation for details.
- Latency: Enabling Web Search increases response latency because a real-time search must be performed.
- Availability: Not all models support Web Search; confirm support for your target model.
- Result Accuracy: Web Search results come from the live web; accuracy depends on the search engine and source websites.
FAQ
Q: How can I tell whether the model performed a Web Search?
A: You can determine this in the following ways:- Chat Completions: Check for
url_citationinmessage.annotations - Messages: Check
usage.server_tool_use.web_search_requests - Responses: Look for
web_search_callitems inoutput - Vertex AI: Check whether
groundingMetadataexists
Q: Why are there sometimes no search results returned?
A: Possible reasons include:- The question does not require real-time information; the model decides not to search
- Search results are not relevant to the question and are filtered by the model
- Network issues cause the search to fail
Q: How can I optimize search performance?
A: Recommendations:- Ask clear, specific questions
- Use an appropriate search context size
- Provide user location information to get localized results
- Use domain filtering in the Messages API to focus the search scope