openai_web_search_tool: OpenAI built-in web_search tool

View source: R/openai_tools.R

openai_web_search_toolR Documentation

OpenAI built-in web_search tool

Description

Build the configuration for OpenAI's model-hosted web search, used via the Responses API. The model decides whether to search based on the prompt.

Usage

openai_web_search_tool(
  allowed_domains = NULL,
  user_location = NULL,
  search_context_size = NULL,
  type = c("web_search", "web_search_preview")
)

Arguments

allowed_domains

Optional character vector of domains the search is restricted to. Forwarded as filters.allowed_domains.

user_location

Optional named list with any of city, country, region, timezone for localized results.

search_context_size

Optional "low", "medium" (API default), or "high" — controls how much retrieved context the model is given.

type

The tool type identifier. Defaults to "web_search"; pass "web_search_preview" for the older preview integration.

Value

A plain list ready to drop into tools = list(...).

Examples

## Not run: 
model <- create_openai()$responses_model("gpt-5")
generate_text(
  model,
  "Latest material AAPL news?",
  tools = list(openai_web_search_tool(search_context_size = "high"))
)

## End(Not run)

aisdk documentation built on May 29, 2026, 9:07 a.m.