Web Search

Web search allows models to access up-to-date information from the internet and provide answers with sourced citations.

Verified

On this page

Definition

Web search allows models to access up-to-date information from the internet and provide answers with sourced citations. The Responses API enables search through the web search tool; Chat Completions also offers search in specific cases. In the Responses API, the model can choose whether to search the web based on the input prompt.

The Chat Completions API supports only specialized search models for web search. Chat Completions search models always search before responding. The Responses API provides search as a tool.

At a glance

The two nodes here represent the output components of a response that uses the web search tool. By default, the model's response includes inline citations for URLs found in the web search results.

  • A web_search_call output item carries the ID of the search call, along with the action taken in web_search_call.action.
  • A message output item holds the text result in message.content[0].text and, in message.content[0].annotations, the annotations for the cited URLs.

The source does not state the order of these points, so they are listed without arrows.

How it works

New Responses API integrations use the web_search tool type. The earlier web_search_preview tool remains available for legacy integrations, but it does not support newer controls such as filters, external_web_access, and return_token_budget. A response that uses the tool includes a web_search_call item whose action can be search, which represents a web search.

The open_page action represents a page being opened and is supported in reasoning models. The find_in_page action represents searching within a page and is supported in reasoning models. The url_citation annotation supplies the cited source’s URL, title, and location.

When using Chat Completions, the model always retrieves information from the web before responding to your query. To let the model decide whether to search, switch to the Responses API with the web_search tool. With tool_choice set to auto, search is optional.

search_context_size controls how much context from web search results is made available to the model before it generates a response. Use low for a lookup that needs only a few details, medium for a balanced default, and high when the answer may require more detail from search results. This setting provides no exact token count or guaranteed number of sources or citations.

The sources field is used to view the URLs retrieved during a web search. Inline citations show the most relevant references; sources lists all URLs consulted while forming the response. Domain filtering in web search lets you limit results to a specific set of domains.

With the filters parameter, up to 100 allowed_domains or up to 100 blocked_domains can be configured. Domain filtering is only available in the Responses API with the web_search tool. In the Responses API, the web search tool can be set to fetch live content or to use only cached/indexed results.

The web_search_preview variants ignore external_web_access and behave as if external_web_access is true. The web search context window in the Responses API is limited to 128k, even when the underlying model has a larger context window.

Example

The official request below enables web search in the tools array; the accompanying response is an example of the output structure. The text result of the response is in message.content[0].text, and the annotations for the cited URLs are in message.content[0].annotations. The documentation says web search can return image results alongside regular text results.

To use image search, set search_content_types to include image. Image results are returned separately from the assistant message. To refine a search geographically, provide an approximate user location through country, city, region, or timezone.

From the official source
javascript
import OpenAI from "openai";
const client = new OpenAI();

const response = await client.responses.create({
  model: "gpt-6-astra",
  tools: [{ type: "web_search" }],
  input: "What was a positive news story from today?",
});

console.log(response.output_text);
From the official source
json
[
  {
    "type": "web_search_call",
    "id": "ws_67c9fa0502748190b7dd390736892e100be649c1a5ff9609",
    "status": "completed",
    "action": {
      "type": "search",
      "query": "latest news about AI"
    }
  },
  {
    "id": "msg_67c9fa077e288190af08fdffda2e34f20be649c1a5ff9609",
    "type": "message",
    "status": "completed",
    "role": "assistant",
    "content": [
      {
        "type": "output_text",
        "text": "On March 6, 2025, several news...",
        "annotations": [
          {
            "type": "url_citation",
            "start_index": 2606,
            "end_index": 2758,
            "url": "https://...",
            "title": "Title..."
          }
        ]
      }
    ]
  }
]
From the official source
typescript
import OpenAI from "openai";
const client = new OpenAI();

const tools: OpenAI.Responses.Tool[] = [
  {
    type: "web_search",
    // @ts-expect-error The published SDK omits the documented image-search options.
    search_content_types: ["image", "text"],
    image_settings: {
      max_results: 3,
      caption: true,
    },
  },
];

const response = await client.responses.create({
  model: "gpt-6-astra",
  reasoning: { effort: "low" },
  tools,
  include: ["web_search_call.results"],
  input:
    "Search for recent images and supporting text sources about the Golden Gate Bridge at sunset.",
});

console.log(response.output);
From the official source
json
{
  "output": [
    {
      "type": "web_search_call",
      "status": "completed",
      "results": [
        {
          "type": "image_result",
          "image_url": "https://cdn.example/golden-gate-sunset.jpg",
          "thumbnail_url": "https://cdn.example/golden-gate-sunset-thumb.jpg",
          "source_website_url": "https://example.com/source-page",
          "caption": "Golden Gate Bridge at sunset"
        }
      ]
    }
  ]
}

Sources

This page is written from the official sources below. Open them to check the original text.

Verified ·

This page is written by AI from the official sources above and checked automatically. This site has not tested it. Found a mistake? Tell us.