Web Search
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 |
Web Search - Chat Completions API
The Chat Completions API enables Web Search via the web_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:
|
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
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://llm.siraya.pro/v1"
)
response = client.chat.completions.create(
model="anthropic/claude-opus-4.6",
messages=[
{
"role": "user",
"content": "How is the weather in Beijing today?"
}
],
extra_body={
"web_search_options": {
"search_context_size": "high",
"user_location": {
"approximate": {
"timezone": "Asia/Shanghai",
"country": "CN",
"city": "Beijing"
}
}
}
}
)
print(response.json())
curl -X POST "https://llm.siraya.pro/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "anthropic/claude-opus-4.6",
"messages": [
{
"role": "user",
"content": "How is the weather in Beijing today?"
}
],
"web_search_options": {
"search_context_size": "high",
"user_location": {
"approximate": {
"timezone": "Asia/Shanghai",
"country": "CN",
"city": "Beijing"
}
}
}
}'
Response example,
{
"id": "msg_016gnzBRiQ1zuyGAdfMZFRaY",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": ".\n\nOverall, it's a cool and mostly pleasant early spring day in Beijing. A jacket or sweater is recommended, especially for the chilly morning and evening hours. Enjoy the sunshine! ☀️",
"refusal": null,
"role": "assistant",
"annotations": null,
"audio": null,
"function_call": null,
"tool_calls": null
}
}
],
"created": 1773060007,
"model": "anthropic/claude-opus-4.6",
"object": "chat.completion",
"service_tier": null,
"system_fingerprint": null,
"usage": {
"completion_tokens": 404,
"prompt_tokens": 12095,
"total_tokens": 12499,
"completion_tokens_details": null,
"prompt_tokens_details": {
"audio_tokens": null,
"cached_tokens": null
},
"input_tokens": 0,
"output_tokens": 0,
"ttft": 0,
"server_tool_use": {
"web_search_requests": ""
}
},
"request_id": "e42a26abb0f047339a5dc1081bf9e277"
}