Repository navigation
fix(openai): emulate web_search on /v1/messages for OpenAI API key accounts - #8080
Open
SipengXie2024 wants to merge 2 commits into
Open
SipengXie2024 wants to merge 2 commits into
SipengXie2024 wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
gateway_forward.go). Claude Code on an OpenAI-platform group goes throughOpenAIGatewayService.ForwardAsAnthropic. On API key accounts that use Chat Completions,anthropicToolsToChatToolsdropsweb_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 noweb_search_tool_resultblock.ForwardAsAnthropicnow runs the same emulation check before protocol routing. The gate is moved into a sharedshouldEmulateWebSearchFor, and response writing intowriteEmulatedWebSearch. The Anthropic path keeps its current behavior.Account.GetWebSearchEmulationModenow 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 toextra.web_search_emulation.web_search_emulation.openaiflag, 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 inGetWebSearchEmulationModeand the shared gate for an OpenAI API key account.force_chat_completions). Before the change, a Claude Code style request with only aweb_search_20250305tool 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 SSEdata:line parses as JSON.vue-tsc -b && vite buildinside the Docker build).🤖 Generated with Claude Code