Feature: Add web search support via OpenAI Responses API #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds web search support when using the proxy with OpenAI models. When the Claude CLI sends a request containing a
web_searchtool, the proxy routes it to OpenAI's Responses API (which supports native web search) instead of the standard Chat Completions API.Problem
The Claude CLI supports web search via the
web_searchtool, but the standard OpenAI Chat Completions API does not support web search. This means users of the proxy could not use web search functionality.Solution
Detect
web_searchtool in incoming requests and route them to OpenAI's Responses API, which does support web search. The response is then translated back to Anthropic's format so the Claude CLI can display it correctly.Features
web_searchtool in incoming Anthropic-format requestsserver_tool_useblocks for search callsweb_search_tool_resultblocks for resultsOPENAI_BASE_URLNew Functions
has_web_search_tool()- Detect web_search in tools listconvert_anthropic_messages_to_input()- Format messages for Responses APIget_openai_web_search_model()- Map model names to web search compatible modelscall_openai_responses_api_non_streaming()- Non-streaming API callconvert_openai_responses_to_anthropic()- Response format translationhandle_web_search_streaming()- Streaming support with SSE translationUsage
No configuration needed - web search is automatically detected and routed. Just use the Claude CLI with web search as normal:
Co-authored with Claude Code