> ## Documentation Index
> Fetch the complete documentation index at: https://docs.requesty.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Web Search

> Enable AI models to search the web for real-time information

Requesty supports native web search across major providers. Pass a single tool definition and Requesty translates it to the right provider format automatically.

<Info>
  **Native web search providers:** Vertex AI (Google), Azure OpenAI, OpenAI, Anthropic, xAI, Perplexity
</Info>

<Note>
  **[Browse models with web search](https://app.requesty.ai/model-library)** in the Requesty Console. Look for `supports_web_search: true` in the [List Models](/api-reference/endpoint/models-list) response.
</Note>

## How It Works

Each provider implements web search differently. Requesty normalizes these differences behind a single tool definition that works across all three inference endpoints:

| Endpoint               | Format                  | Tool definition                                                                     |
| ---------------------- | ----------------------- | ----------------------------------------------------------------------------------- |
| `/v1/chat/completions` | OpenAI Chat Completions | `"tools": [{ "type": "web_search" }]`                                               |
| `/v1/responses`        | OpenAI Responses API    | `"tools": [{ "type": "web_search" }]`                                               |
| `/v1/messages`         | Anthropic Messages      | `"tools": [{ "type": "web_search_20250305", "name": "web_search", "max_uses": 5 }]` |

We recommend using streaming (`"stream": true`) for all web search requests. Streaming delivers citations and content in real time, and avoids the extra latency of waiting for the full search to finish.

## Usage

<Tabs>
  <Tab title="Chat Completions">
    **`POST /v1/chat/completions`** - Add `{ "type": "web_search" }` to the `tools` array.

    <CodeGroup>
      ```bash cURL theme={"dark"}
      curl https://router.requesty.ai/v1/chat/completions \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer YOUR_REQUESTY_API_KEY" \
        -d '{
          "model": "anthropic/claude-sonnet-4-20250514",
          "messages": [
            { "role": "user", "content": "What are the latest news in London today?" }
          ],
          "tools": [{ "type": "web_search" }],
          "stream": true
        }'
      ```

      ```python Python theme={"dark"}
      from openai import OpenAI

      client = OpenAI(
          api_key="YOUR_REQUESTY_API_KEY",
          base_url="https://router.requesty.ai/v1",
      )

      stream = client.chat.completions.create(
          model="anthropic/claude-sonnet-4-20250514",
          messages=[
              {"role": "user", "content": "What are the latest news in London today?"}
          ],
          tools=[{"type": "web_search"}],
          stream=True,
      )

      for chunk in stream:
          if chunk.choices[0].delta.content:
              print(chunk.choices[0].delta.content, end="")
      ```

      ```typescript TypeScript theme={"dark"}
      import OpenAI from 'openai';

      const client = new OpenAI({
        apiKey: 'YOUR_REQUESTY_API_KEY',
        baseURL: 'https://router.requesty.ai/v1',
      });

      const stream = await client.chat.completions.create({
        model: 'anthropic/claude-sonnet-4-20250514',
        messages: [
          { role: 'user', content: 'What are the latest news in London today?' }
        ],
        tools: [{ type: 'web_search' }],
        stream: true,
      });

      for await (const chunk of stream) {
        const content = chunk.choices[0]?.delta?.content;
        if (content) process.stdout.write(content);
      }
      ```
    </CodeGroup>

    Just change the `model` to switch providers:

    ```python theme={"dark"}
    # Vertex / Gemini
    model="vertex/google/gemini-2.5-pro"

    # xAI / Grok
    model="xai/grok-3"

    # Perplexity
    model="perplexity/sonar-pro"
    ```

    **Response** includes `web_search` metadata on streamed chunks with citation URLs and titles:

    ```json theme={"dark"}
    {
      "choices": [{
        "delta": {
          "content": "Based on the search results...",
          "web_search": {
            "content": [
              { "url": "https://example.com/news", "title": "London News" }
            ]
          }
        }
      }]
    }
    ```
  </Tab>

  <Tab title="Responses API">
    **`POST /v1/responses`** - Add `{ "type": "web_search" }` to the `tools` array.

    <CodeGroup>
      ```bash cURL theme={"dark"}
      curl https://router.requesty.ai/v1/responses \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer YOUR_REQUESTY_API_KEY" \
        -d '{
          "model": "openai-responses/gpt-4.1",
          "input": "What are the latest developments in artificial intelligence?",
          "tools": [{ "type": "web_search" }],
          "stream": true
        }'
      ```

      ```python Python theme={"dark"}
      from openai import OpenAI

      client = OpenAI(
          api_key="YOUR_REQUESTY_API_KEY",
          base_url="https://router.requesty.ai/v1",
      )

      response = client.responses.create(
          model="openai-responses/gpt-4.1",
          input="What are the latest developments in artificial intelligence?",
          tools=[{"type": "web_search"}],
          stream=True,
      )

      for event in response:
          if hasattr(event, 'type') and event.type == 'response.completed':
              for item in event.response.output:
                  if item.type == 'message':
                      for content in item.content:
                          if content.type == 'output_text':
                              print(content.text)
      ```

      ```typescript TypeScript theme={"dark"}
      import OpenAI from 'openai';

      const client = new OpenAI({
        apiKey: 'YOUR_REQUESTY_API_KEY',
        baseURL: 'https://router.requesty.ai/v1',
      });

      const response = await client.responses.create({
        model: 'openai-responses/gpt-4.1',
        input: 'What are the latest developments in artificial intelligence?',
        tools: [{ type: 'web_search' }],
      });

      for (const item of response.output) {
        if (item.type === 'message') {
          for (const content of item.content) {
            if (content.type === 'output_text') {
              console.log(content.text);
            }
          }
        }
      }
      ```
    </CodeGroup>

    **Response** includes `web_search_call` items and `url_citation` annotations on text content:

    ```json theme={"dark"}
    {
      "output": [
        {
          "type": "web_search_call",
          "id": "ws_abc123",
          "status": "completed"
        },
        {
          "type": "message",
          "role": "assistant",
          "content": [{
            "type": "output_text",
            "text": "Recent AI developments include...",
            "annotations": [{
              "type": "url_citation",
              "url": "https://example.com/ai-news",
              "title": "AI News Today",
              "start_index": 0,
              "end_index": 35
            }]
          }]
        }
      ]
    }
    ```
  </Tab>

  <Tab title="Messages API">
    **`POST /v1/messages`** - Uses Anthropic's native `web_search_20250305` tool type.

    <CodeGroup>
      ```bash cURL theme={"dark"}
      curl https://router.requesty.ai/v1/messages \
        -H "Content-Type: application/json" \
        -H "x-api-key: YOUR_REQUESTY_API_KEY" \
        -H "anthropic-version: 2023-06-01" \
        -d '{
          "model": "anthropic/claude-sonnet-4-20250514",
          "max_tokens": 4096,
          "messages": [
            { "role": "user", "content": "What are the latest developments in artificial intelligence?" }
          ],
          "tools": [{
            "type": "web_search_20250305",
            "name": "web_search",
            "max_uses": 5
          }],
          "stream": true
        }'
      ```

      ```python Python theme={"dark"}
      import anthropic

      client = anthropic.Anthropic(
          api_key="YOUR_REQUESTY_API_KEY",
          base_url="https://router.requesty.ai",
      )

      with client.messages.stream(
          model="anthropic/claude-sonnet-4-20250514",
          max_tokens=4096,
          messages=[
              {"role": "user", "content": "What are the latest developments in artificial intelligence?"}
          ],
          tools=[{
              "type": "web_search_20250305",
              "name": "web_search",
              "max_uses": 5,
          }],
      ) as stream:
          response = stream.get_final_message()

      for block in response.content:
          if block.type == "text":
              print(block.text)
      ```

      ```typescript TypeScript theme={"dark"}
      import Anthropic from '@anthropic-ai/sdk';

      const client = new Anthropic({
        apiKey: 'YOUR_REQUESTY_API_KEY',
        baseURL: 'https://router.requesty.ai',
      });

      const stream = client.messages.stream({
        model: 'anthropic/claude-sonnet-4-20250514',
        max_tokens: 4096,
        messages: [
          { role: 'user', content: 'What are the latest developments in artificial intelligence?' }
        ],
        tools: [{
          type: 'web_search_20250305',
          name: 'web_search',
          max_uses: 5,
        }],
      });

      const response = await stream.finalMessage();

      for (const block of response.content) {
        if (block.type === 'text') {
          console.log(block.text);
        }
      }
      ```
    </CodeGroup>

    **Response** includes `server_tool_use`, `web_search_tool_result`, and text blocks with `citations`:

    ```json theme={"dark"}
    {
      "content": [
        {
          "type": "server_tool_use",
          "id": "srvtoolu_abc123",
          "name": "web_search",
          "input": { "query": "latest AI developments" }
        },
        {
          "type": "web_search_tool_result",
          "tool_use_id": "srvtoolu_abc123",
          "content": [{
            "type": "web_search_result",
            "url": "https://example.com/ai-news",
            "title": "AI News Today",
            "encrypted_content": "..."
          }]
        },
        {
          "type": "text",
          "text": "Recent AI developments include...",
          "citations": [{
            "type": "web_search_result_location",
            "url": "https://example.com/ai-news",
            "title": "AI News Today",
            "cited_text": "Recent breakthroughs in..."
          }]
        }
      ]
    }
    ```
  </Tab>
</Tabs>

<Note>
  Web search requires models with tool use support. Check the [Model Library](https://app.requesty.ai/model-library) to confirm web search support for specific models.
</Note>
