RFC 0049 — Web search on OpenAI: the Responses API for provider tools
Status: implemented (2026-11-21) · Target: 0.52.0 · builds on AI SDK, RFC 0048 · see Decisions
Summary
.web_search(…) runs on Anthropic only. With Provider::OpenAI the chat
fails with Error::Unsupported, because OpenAI offers web search only
through its Responses API (POST /v1/responses), and the SDK speaks Chat
Completions. A failover from Anthropic to OpenAI therefore can't keep a
search, and an app with only an OpenAI key can't search at all.
This RFC adds a second OpenAI driver over the Responses API, used when an OpenAI chat asks for web search:
let answer = ai.chat()
.provider(Provider::OpenAI)
.instructions("Answer with up-to-date facts and cite sources.")
.web_search(
WebSearch::new()
.allow(["rust-lang.org", "docs.rs"])
.location(UserLocation { country: Some("NO".into()), ..Default::default() }),
)
.tool(lookup_customer) // the app's own tools still run
.prompt("What changed in the latest Rust release?")
.await?;
// And the same chat can fail over between the two labs.
ai.chat()
.provider(Provider::Anthropic)
.failover([Provider::OpenAI])
.web_search(WebSearch::new())
.prompt("…")
.await?;
- The same
WebSearchfor both labs:allowandlocationmap onto OpenAI's tool; the options OpenAI has no equivalent for are handled per open question 2. - The app's tools, structured output and streaming work in a web-search chat on OpenAI as they do on Chat Completions.
- Web fetch and code execution stay Anthropic's: OpenAI has no tool
that fetches a given URL, and its code interpreter is another tool than
Anthropic's programmatic tool calling. Asking OpenAI for them stays
Error::Unsupported, now saying which tool.
Motivation
- The roadmap's AI SDK line has "OpenAI provider tools via the Responses API" next, after RFC 0048.
- Failover is half there: a chat with web search fails over from
Anthropic only to providers that can't search, so the fallback always
fails with
Unsupported. - An app with one lab's key chooses the lab by what it has, not by which features the SDK implements for it.
Current state (0.52, after RFC 0048)
ProviderTool { WebSearch, WebFetch, CodeExecution }, withanthropic_spec(ai/src/provider_tool.rs).openai::runandopenai::stream(Chat Completions) returnError::Unsupported("provider tools … require the Anthropic provider")when any provider tool is set.openai::streamtakes no tools at all.- Chat Completions on every OpenAI-shaped provider since RFC 0048.
Design
When the Responses API is used
An OpenAI chat with .web_search(…) goes to openai_responses::run /
stream. Every other OpenAI chat stays on Chat Completions (open
question 1). The other OpenAI-shaped providers (Gemini, Groq, …) keep
Unsupported for provider tools: none of them is documented to take the
Responses API's tools.
The request
POST {base}/v1/responses:
instructionsfrom the system prompt;inputthe conversation as{role, content}items.tools: the app's tools as{type: "function", name, description, parameters}(flat, not nested underfunctionas in Chat Completions), and{type: "web_search"}, withfilters.allowed_domainsfromallowanduser_location({type: "approximate", country, city, region, timezone}) fromlocation.- Structured output:
text.format = {type: "json_schema", name, schema, strict: false}. On Chat Completions the SDK forces a tool call; the Responses API has the format itself. max_output_tokens,temperature,stream.
The tool loop
The answer's output is a list of items. message items carry the text
(content[].type == "output_text"); function_call items (call_id,
name, arguments) are the app's tools to run; web_search_call items
are the search, already done by OpenAI. While there are function_calls,
the SDK runs them and sends the next request with the previous output
items and a {type: "function_call_output", call_id, output} per call
appended to input, up to max_steps. It doesn't use
previous_response_id, so nothing is stored server-side across steps
(store: false).
Streaming
SSE events: response.output_text.delta (delta) becomes
StreamChunk::Delta; response.completed carries response.usage
(input_tokens, output_tokens) for StreamChunk::Done;
response.failed and error events become an Error::Api. A streamed
chat with web search and without the app's tools, as streaming is today.
Citations
The answer's url_citation annotations (url, title) aren't surfaced
today on either lab: Response holds the text. Open question 3.
Testing
Offline against a local server (ai/tests/openai_responses.rs): the
request (URL, tool specs, filters, location, store: false, structured
format), a function-call round trip with a web search in the same answer,
a stream, an error event, failover from Anthropic to OpenAI with web
search, and web_fetch on OpenAI still Unsupported. One opt-in live
test (ELYRA_AI_LIVE=1, OPENAI_API_KEY).
Implementation plan
ai/src/openai_responses.rs: request, tool loop, stream, readingoutput.ProviderTool::openai_spec, the checks for options and tools OpenAI lacks;chat.rsdispatches an OpenAI chat with web search to the new driver.- Tests, docs (
ai.md: provider tools for both labs), roadmap, CHANGELOG.
Open questions
Answered in Decisions.
- The Responses API for every OpenAI chat, or only with web search? It's OpenAI's newer API, and moving everything over leaves one OpenAI driver to keep. It's also a change to every OpenAI chat that works today, for no change in what they can do. Recommendation: only with web search, for now. Chat Completions stays the path for OpenAI and for every OpenAI-shaped provider; a move can come with a reason (a feature only the Responses API has).
WebSearchoptions OpenAI has no equivalent for (max, the number of searches;block, excluded domains): an error, or ignored? Recommendation:blockis anError::Unsupportedthat names it (a blocklist silently dropped shows the results it was meant to keep out).maxis ignored with atracingwarning once per client: it bounds cost, not what's shown, and failover from Anthropic should still work with it set.- Citations: add
Response::citations() -> &[Citation](url,title) for both labs now? Recommendation: not in this RFC. It's new API for both drivers and the stream, and wants its own design (where a citation points in the text). The text still says what it cites when the instructions ask for sources. - Streaming with the app's tools on the Responses API: possible there, and not possible on Chat Completions today. Recommendation: no; streaming keeps one rule on both labs (no app tools), and changing that is its own RFC.
Not in this RFC
- OpenAI's other built-in tools: file search, code interpreter, image generation, computer use, remote MCP.
previous_response_idand server-stored conversations.- Web search on Gemini, Groq and the others, each with its own.
- Citations (open question 3).
Alternatives considered
- Web search on Chat Completions through OpenAI's search models
(
gpt-4o-search-previewand its successors): no new driver, but the app has to pick a special model, it can't be combined with the app's tools, and it has no domain filter. - Keep
Unsupportedand document Anthropic as the lab for search: what the SDK says today, and the failover gap stays.
As built
As designed, with these specifics:
- No streaming path.
Chat::streamsends no provider tools on either lab today (its request carries none), so a Responses API stream would never be reached;openai_responseshasrunonly. A streamed chat with web search is the same as one without, as before. - The
maxwarning is aneprintlnonce per process, as the SDK's other once-only notes are (the Anthropic temperature one); the SDK doesn't depend ontracing. - Stateless steps: each request has
store: falseandinclude: ["reasoning.encrypted_content"], and carries the previous answer's output items back as they came (searches, reasoning, calls) before eachfunction_call_output, so a reasoning model's steps hold together without a stored response. - A
status: "failed"response is anError::Apiwith its message; arefusalcontent part isError::Refused; an error body goes through RFC 0048'serror_message. - The other OpenAI-shaped providers'
Unsupportednow says which tools run where. - Tests:
ai/tests/openai_responses.rsagainst a local server (shared withproviders.rsinai/tests/common): the request (path, auth, instructions, input,store, the web search tool with filters and location), the app's tool around a search with the second request's input, structured output astext.format,block/web_fetch/another provider failing before sending, a failed response, a refusal and a 400, and failover from Anthropic (529) to OpenAI keeping the search. One opt-in live test. No live call has been made.
Decisions
- The Responses API only for an OpenAI chat with web search; Chat Completions stays the path for every other OpenAI chat and every OpenAI-shaped provider.
blockon OpenAI isError::Unsupported, naming it;maxis ignored there, with atracingwarning once per client.- No citations in this RFC.
- Streaming keeps one rule on both labs: no app tools.