Skip to content

fix(openai): emulate web_search on /v1/messages for OpenAI API key accounts - #8080

Open
SipengXie2024 wants to merge 2 commits into
Wei-Shaw:mainfrom
SipengXie2024:fix/openai-messages-web-search-emulation
Open

SipengXie2024 wants to merge 2 commits into
Wei-Shaw:mainfrom
SipengXie2024:fix/openai-messages-web-search-emulation

Conversation

@SipengXie2024

@SipengXie2024 SipengXie2024 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Web search emulation (third-party search API answering web_search-only requests) only ran on the Anthropic gateway path (gateway_forward.go). Claude Code on an OpenAI-platform group goes through OpenAIGatewayService.ForwardAsAnthropic. On API key accounts that use Chat Completions, anthropicToolsToChatTools drops web_search_* tools, so the upstream (e.g. DeepSeek) never sees a tool. The model then makes up an answer, and Claude Code's WebSearch reports 0 results because there is no web_search_tool_result block.
  • ForwardAsAnthropic now runs the same emulation check before protocol routing. The gate is moved into a shared shouldEmulateWebSearchFor, and response writing into writeEmulatedWebSearch. The Anthropic path keeps its current behavior.
  • Account.GetWebSearchEmulationMode now also accepts OpenAI API key accounts. OAuth accounts stay excluded because they have native search. The account edit modal shows the existing Web Search emulation selector for OpenAI API key accounts and saves it to extra.web_search_emulation.
  • Opt-in: nothing changes until the global emulation switch is on and the account enables it. The backend also honors a channel-level web_search_emulation.openai flag, but the channel form still only shows the toggle for Anthropic.

Test plan

  • go test -tags unit ./internal/service/ ./internal/handler/ passes. New cases cover OpenAI API key / OAuth / other platforms in GetWebSearchEmulationMode and the shared gate for an OpenAI API key account.
  • Running in production on an OpenAI API key account (DeepSeek-V4.1-Flash upstream, force_chat_completions). Before the change, a Claude Code style request with only a web_search_20250305 tool came back as [thinking, text]. After the change it returns [server_tool_use, web_search_tool_result, text] with 5 results (Tavily), in both stream and non-stream mode. Every SSE data: line parses as JSON.
  • Frontend builds (vue-tsc -b && vite build inside the Docker build).

🤖 Generated with Claude Code

SipengXie2024 and others added 2 commits October 14, 2026 07:02
…counts

Chat Completions conversion drops Anthropic web_search tools, so Claude
Code's WebSearch on OpenAI-platform groups (e.g. DeepSeek upstreams)
got no web_search_tool_result and reported 0 results. Run the existing
search emulation in ForwardAsAnthropic and let OpenAI API Key accounts
opt in via extra.web_search_emulation.
Keep OpenAI non-API-key accounts on native search before channel inheritance. Cover 72 combinations of account types, modes, channel flags and global enablement in the shared interception gate.

Validation: the regression test fails in six OAuth/setup-token channel-enabled cases on the original code and passes with this guard. Related WebSearch unit tests pass. The broad service/handler test run was blocked by automatic approval review due to an unrelated daily-cloudcode-pa.googleapis.com request with unverified payload/credential use.
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