# Web Search

### Overview <a href="#overview" id="overview"></a>

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 <a href="#supported-protocols" id="supported-protocols"></a>

| 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 <a href="#id-1-chat-completions-api" id="id-1-chat-completions-api"></a>

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

#### Parameters <a href="#parameters" id="parameters"></a>

<table><thead><tr><th width="323.80206298828125">Parameter</th><th>Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td><code>web_search_options</code></td><td>object</td><td>No</td><td>Web search configuration</td></tr><tr><td><code>web_search_options.search_context_size</code></td><td>string</td><td>No</td><td><p>Search context size: </p><ul><li><code>low</code> </li><li><code>medium</code> </li><li><code>high</code></li></ul></td></tr><tr><td><code>web_search_options.user_location</code></td><td>object</td><td>No</td><td>User location info for localized search results</td></tr><tr><td><code>web_search_options.user_location.type</code></td><td>string</td><td>Yes</td><td>Location type, fixed as <code>approximate</code></td></tr><tr><td><code>web_search_options.user_location.city</code></td><td>string</td><td>No</td><td>City name</td></tr><tr><td><code>web_search_options.user_location.country</code></td><td>string</td><td>No</td><td>Country code (2-letter ISO, e.g. <code>CN</code>, <code>US</code>)</td></tr><tr><td><code>web_search_options.user_location.region</code></td><td>string</td><td>No</td><td>Region/province</td></tr><tr><td><code>web_search_options.user_location.timezone</code></td><td>string</td><td>No</td><td>Timezone (IANA format, e.g. <code>Asia/Shanghai</code>)</td></tr></tbody></table>

#### Example <a href="#example" id="example"></a>

{% tabs %}
{% tab title="Python" %}

```python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://llm.onerouter.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())
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl -X POST "https://llm.onerouter.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"
                }
            }
    }
  }'
```

{% endtab %}
{% endtabs %}

Response example,

```json
{
  "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"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infronai.gitbook.io/docs/features/web-search.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
