Skip to content

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
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

ParameterTypeRequiredDescription
web_search_optionsobjectNoWeb search configuration
web_search_options.search_context_sizestringNo

Search context size:

  • low
  • medium
  • high
web_search_options.user_locationobjectNoUser location info for localized search results
web_search_options.user_location.typestringYesLocation type, fixed as approximate
web_search_options.user_location.citystringNoCity name
web_search_options.user_location.countrystringNoCountry code (2-letter ISO, e.g. CN, US)
web_search_options.user_location.regionstringNoRegion/province
web_search_options.user_location.timezonestringNoTimezone (IANA format, e.g. Asia/Shanghai)

Example

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://llm.siraya.ai/v1"
)

response = client.chat.completions.create(
    model="gpt-5.4-pro",
    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.model_dump_json(indent=2))
curl -X POST "https://llm.siraya.ai/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-5.4-pro",
    "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": "resp_09c1b55da08da5060069c83024d4ec81...",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "As of **17:00 on Saturday, March 28, 2026 (Beijing time)**, Beijing is **19.9°C** with **light rain**, **southwest wind level 3**, **20% humidity**...",
        "role": "assistant",
        "annotations": null
      }
    }
  ],
  "created": 1774727204,
  "model": "gpt-5.4-pro",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 529,
    "prompt_tokens": 9914,
    "total_tokens": 10443
  }
}