Compare the APIs
The web search API and the web search tool provide similar search results, but the tool integrates web search into conversational workflows and requires specifying queries and configuration differently. The table below compares the two APIs.| Aspect | Web search API | Web search tool |
|---|---|---|
| Endpoint | /v1/tools/web-search | /v1/chat with the prebuilt web search tool specification |
| Request structure | Pass search parameters such as query, search_depth, etc. directly in the request body | Provide the search query as part of the conversation messages and add the web search tool in the tools array. Additional parameters (like domains to include or exclude) are specified in the tool configuration, not as direct request fields. |
| Response format | Results in answer and sources fields | Answer in choices[0].message.content and data in web_search_data field |
| Parameter control | Explicit API parameters | Most parameters specified in message prompt; only include_domains and exclude_domains as tool configuration |
Migrate your code
The tabs below show a request using the web search API and the same request using the web search tool.- Before: Web search API
- After: Web search tool
The web search API accepts search parameters directly in the request body. The following example shows an example request using the web search API. View the same request using the web search tool in the after migrating section.Response:
Map your parameters
The following table shows how web search API parameters map to the web search tool. To customize search behavior in the web search tool, include your requirements in the message prompt.| Web search API | Web search tool |
|---|---|
query | Include in the message content field |
include_domains | tools[0].function.include_domains |
exclude_domains | tools[0].function.exclude_domains |
search_depth | Include in the message prompt (for example, “perform an advanced search”) |
max_results | Include in the message prompt (for example, “limit to 10 sources”) |
time_range | Include in the message prompt (for example, “from the last week”) |
include_raw_content | Include in the message prompt (for example, “include raw source text”) |
topic | Include in the message prompt (for example, “search news articles”) |
country | Include in the message prompt (for example, “localize results to the United States”) |
chunks_per_source | Include in the message prompt (for example, “extract 3 text segments per source”) |
With the web search tool, most search parameters are specified in your message prompt rather than as separate API parameters. The model interprets your requirements and configures the search accordingly.Only
include_domains and exclude_domains are available as tool configuration parameters.Access search metadata
The web search tool response includes search metadata, including sources and raw text if requested, in theweb_search_data field: