Skip to content

Conversation

@charignon
Copy link

Summary

This PR adds web search support when using the proxy with OpenAI models. When the Claude CLI sends a request containing a web_search tool, 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_search tool, 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_search tool 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

  • Detects web_search tool in incoming Anthropic-format requests
  • Routes to OpenAI Responses API with appropriate model mapping
  • Converts Anthropic messages to Responses API input format
  • Translates OpenAI response back to Anthropic format including:
    • server_tool_use blocks for search calls
    • web_search_tool_result blocks for results
    • Citation annotations
  • Supports both streaming and non-streaming modes
  • Works with custom OPENAI_BASE_URL

New Functions

  • has_web_search_tool() - Detect web_search in tools list
  • convert_anthropic_messages_to_input() - Format messages for Responses API
  • get_openai_web_search_model() - Map model names to web search compatible models
  • call_openai_responses_api_non_streaming() - Non-streaming API call
  • convert_openai_responses_to_anthropic() - Response format translation
  • handle_web_search_streaming() - Streaming support with SSE translation

Usage

No configuration needed - web search is automatically detected and routed. Just use the Claude CLI with web search as normal:

/web_search what is the weather today

Co-authored with Claude Code

When the Claude CLI sends a request with web_search tool, this routes it to
OpenAI's Responses API (which supports native web search) instead of the
standard Chat Completions API.

Features:
- Detects web_search tool in incoming requests
- Routes to OpenAI Responses API with appropriate model
- Converts Anthropic messages to Responses API input format
- Translates OpenAI response back to Anthropic format with citations
- Supports both streaming and non-streaming modes
- Works with custom OPENAI_BASE_URL

This enables web search functionality when using the proxy with OpenAI models,
which was previously not possible since the Chat Completions API does not
support web search.

Co-authored with Claude Code (https://claude.ai/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant