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

# Web Search

> Understand how search-capable behavior differs by model and API surface.

Web search lets a model look beyond the prompt and ground an answer in fresh web results.

Support depends on both the selected model and the API surface you use.

## Support Matrix

| API                | How to enable it                                                                   | Notes                                               |
| ------------------ | ---------------------------------------------------------------------------------- | --------------------------------------------------- |
| `Responses`        | `tools: [{"type": "web_search"}]`                                                  | Best starting point for new search-enabled LLM work |
| `Chat Completions` | `web_search_options`                                                               | Use when you already need the chat protocol         |
| `Messages`         | versioned server tool such as `{"type":"web_search_20250305","name":"web_search"}` | Use when you already need Anthropic compatibility   |

## When To Use It

* fresh or time-sensitive answers
* grounded answers with citations
* workflows where the model should retrieve context instead of relying only on training data

## Enablement Shapes

<Tabs>
  <Tab title="Responses">
    New search-enabled LLM workflows should usually start here.

    ```json theme={null}
    {
      "model": "gpt-4.1",
      "input": "Find recent reporting about AI regulation in the UK and cite your sources.",
      "tools": [
        {
          "type": "web_search"
        }
      ]
    }
    ```
  </Tab>

  <Tab title="Chat Completions">
    `Chat Completions` enables search through a dedicated request field rather
    than through chat `tools`.

    ```json theme={null}
    {
      "model": "gpt-4.1",
      "messages": [
        {
          "role": "user",
          "content": "Find recent reporting about AI regulation in the UK and cite your sources."
        }
      ],
      "web_search_options": {}
    }
    ```
  </Tab>

  <Tab title="Messages">
    `Messages` uses a versioned Anthropic-style server tool.

    ```json theme={null}
    {
      "model": "claude-sonnet-4.5",
      "max_tokens": 512,
      "messages": [
        {
          "role": "user",
          "content": "Find recent reporting about AI regulation in the UK and cite your sources."
        }
      ],
      "tools": [
        {
          "type": "web_search_20250305",
          "name": "web_search"
        }
      ]
    }
    ```
  </Tab>
</Tabs>

## Recommended Example

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.naga.ac/v1",
      api_key="YOUR_API_KEY",
  )

  response = client.responses.create(
      model="gpt-4.1",
      input="Find recent reporting about AI regulation in the UK and cite your sources.",
      tools=[{"type": "web_search"}],
  )

  print(response.output_text)
  ```

  ```javascript Node.js theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://api.naga.ac/v1',
    apiKey: 'YOUR_API_KEY',
  });

  const response = await client.responses.create({
    model: 'gpt-4.1',
    input: 'Find recent reporting about AI regulation in the UK and cite your sources.',
    tools: [{ type: 'web_search' }],
  });

  console.log(response.output_text);
  ```

  ```bash cURL theme={null}
  curl https://api.naga.ac/v1/responses \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4.1",
      "input": "Find recent reporting about AI regulation in the UK and cite your sources.",
      "tools": [
        {
          "type": "web_search"
        }
      ]
    }'
  ```
</CodeGroup>

## Citations And Annotations

When search is active, citations often appear as annotations rather than only inside the generated text. Inspect the structured response, not just the final prose.

For `Chat Completions`, search is enabled through the separate `web_search_options` field rather than through chat `tools`.

## Practical Advice

* use web search for fresh or time-sensitive questions, not for everything
* verify that your chosen model actually supports search-enabled behavior
* inspect annotations or citations if your app needs to display sources
* keep a non-search fallback if your product can still answer from stored context

## API-Specific Guides

* [Responses Web Search](/api/responses/web-search)
* [Chat Completions Web Search](/api/chat-completions/web-search)
* [Messages Web Search](/api/messages/web-search)
* [Models](/get-started/models)
