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
| Protocol | Endpoint | Web Search Parameter |
|---|---|---|
| Chat Completions (OpenAI-compatible) | /v1/chat/completions | web_search_options |
| Messages (Anthropic-compatible) | /v1/messages | web_search_20250305 within tools |
| Responses (OpenAI Responses) | /v1/responses | web_search family within tools |
| Vertex AI (Google-compatible) | /api/vertex-ai/v1/... | googleSearch within tools |
1. Chat Completions API
The Chat Completions API enables Web Search via theweb_search_options parameter.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
web_search_options | object | No | Web search configuration |
web_search_options.search_context_size | string | No | Search context size: low / medium / high |
web_search_options.user_location | object | No | User location info for localized search results |
web_search_options.user_location.type | string | Yes | Location type, fixed as approximate |
web_search_options.user_location.city | string | No | City name |
web_search_options.user_location.country | string | No | Country code (2-letter ISO, e.g. CN, US) |
web_search_options.user_location.region | string | No | Region/province |
web_search_options.user_location.timezone | string | No | Timezone (IANA format, e.g. Asia/Shanghai) |
Example
2. Messages API (Anthropic-compatible)
The Messages API enables Web Search using theweb_search_20250305 type within the tools parameter.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
tools[].type | string | Yes | Tool type, fixed as web_search_20250305 |
tools[].name | string | Yes | Tool name, fixed as web_search |
tools[].allowed_domains | array | No | Allowlist of domains to search |
tools[].blocked_domains | array | No | Blocklist of domains to exclude |
tools[].max_uses | number | No | Max number of searches in a single request |
tools[].user_location | object | No | User location info |
tools[].user_location.type | string | Yes | Location type, fixed as approximate |
tools[].user_location.city | string | No | City name |
tools[].user_location.country | string | No | Country code (ISO 3166-1 alpha-2) |
tools[].user_location.region | string | No | Region |
tools[].user_location.timezone | string | No | Timezone (IANA format) |
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
| Type | Description |
|---|---|
web_search | Web search (generally available) |
web_search_2025_08_26 | Web search 2025 version |
web_search_preview | Web search preview |
web_search_preview_2025_03_11 | Web search preview 2025 version |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
tools[].type | string | Yes | Web Search type |
tools[].search_context_size | string | No | Search context size: low / medium / high |
tools[].filters | object | No | Search filters (only for web_search type) |
tools[].filters.allowed_domains | array | No | Allowlist of domains |
tools[].user_location | object | No | User location info |
tools[].user_location.type | string | Yes | Location type, fixed as approximate |
tools[].user_location.city | string | No | City name |
tools[].user_location.country | string | No | Country code (2-letter ISO) |
tools[].user_location.region | string | No | Region/state code |
tools[].user_location.timezone | string | No | Timezone (IANA format) |
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
tools[].googleSearch | object | Yes | Google Search configuration (an empty object enables it) |
Grounding Information in the Response
| Field | Type | Description |
|---|---|---|
groundingMetadata.webSearchQueries | array | Executed search queries |
groundingMetadata.groundingChunks | array | Evidence chunks |
groundingMetadata.groundingChunks[].web.uri | string | Source URL |
groundingMetadata.groundingChunks[].web.title | string | Source title |
groundingMetadata.groundingChunks[].web.domain | string | Source domain |
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:| Event Type | Description |
|---|---|
response.web_search_call.in_progress | Web Search call started |
response.web_search_call.searching | Search in progress |
response.web_search_call.completed | Search completed |
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