litellm/tests/unit/llms/openai
linhqm e6573ba350
fix(vertex_ai): keep Gemini 3+ web search next to function tools and report searches as web_search_call items (#53423)
* fix(vertex_ai): keep web search next to function tools on Gemini 3+

Gemini 3+ accepts googleSearch, urlContext and the other search tools in the
same request as function declarations, so stop dropping them there. Vertex
takes both with no extra flag. The AI Studio route sets
include_server_side_tool_invocations itself when the final tools mix both
kinds, merged with any tool_choice toolConfig. Gemini 2.x and numeric
fine-tuned Vertex ids still drop the search tools as before

* feat(responses): report Gemini web searches as web_search_call items

Gemini 3 reports the searches it ran as GOOGLE_SEARCH toolCall parts and in
groundingMetadata.webSearchQueries. Each distinct query now becomes a completed
web_search_call output item on /v1/responses, toolCall queries first, with an
id built from the response id and the query so streaming and non-streaming
agree. Non-streaming puts them before the message. Streaming emits them when
they arrive and includes them in response.completed

Billing counts the same distinct queries, so a response that reports its
searches only as toolCall parts now bills them too. Anthropic behavior is
unchanged

* fix(vertex_ai): stream Gemini 3+ web searches before the answer on Vertex too

* fix(vertex_ai): keep the old search drop where Gemini 3+ cannot mix search with functions

Gemini 3+ models the cost map marks without function calling, like the image and Lyria
models, answered 200 with search dropped before and 400 with both kept, so they keep the
old drop. A caller who sends include_server_side_tool_invocations false keeps it too

Under drop_params, googleSearchRetrieval next to functions now drops on Gemini 3+ instead
of reaching Google and failing with a 400

Streamed searches that share a chunk with the first text or thought now open before it,
so output_item.added events keep the output order

* fix(vertex_ai): drop googleSearchRetrieval when the caller sets the flag, and close reasoning before searches

Under drop_params, a Gemini 3+ request that already sets include_server_side_tool_invocations
now drops googleSearchRetrieval like one that does not. The keep path ran after the caller-flag
early return, so the retrieval tool went to Google as given

A streamed /v1/responses call announces searches before opening the first output item only when
that chunk opens it. Otherwise searches queue after the reasoning item closes, so a thought chunk
followed by a searches-and-text chunk no longer closes the reasoning item after the searches

The opt-out reads only include_server_side_tool_invocations, since the camelCase spelling never
reaches map_openai_params through completion or the proxy

* test(vertex_ai): cover the sync stream order and simplify the search-tool checks

The sync /v1/responses stream now runs the same chunk-sharing cases as the async one, so a
search that shares a chunk with the first output must open before it on both paths

The cost-map lookup checks the route row and the bare model only, the retrieval check reads
the camelCase key that reaches it, and the tests now cover a missing cost-map row, an opt-out
set in optional_params, and drop_params set globally

* fix(vertex_ai): read search-with-functions support from the cost map and count searches from tool calls

Gemini models keep search tools next to function declarations only when their
cost-map row sets supports_search_tools_with_functions. Search items and
web_search_requests now come from the server-side tool call queries and fall
back to groundingMetadata.webSearchQueries only when no tool call reported one,
since Vertex repeats each tool call query in grounding without its site: operators.

* fix(gemini): keep googleSearchRetrieval only for the caller flag, honor camelCase opt-out, bill cyber searches per query, stream reasoning before searches

Gemini 3+ drops googleSearchRetrieval next to function tools again unless the
caller set include_server_side_tool_invocations without drop_params, so a
request that answered 200 before never turns into a 400. The camelCase
includeServerSideToolInvocations false now keeps the old drop. Both
gemini-3.8-flash-cyber rows bill search per query like gemini-3.8-flash.
Search call ids hash the query with a per-process HMAC key. Streamed
Responses output now opens reasoning before search items, matching the
non-streamed order.

* fix(gemini): honor includeServerSideToolInvocations false sent through completion

The camelCase flag reaches optional_params only after map_openai_params runs, so
the earlier opt-out check never saw it and Gemini 3+ still kept search tools next
to function tools. transform_request_body now reads the flag it pops, drops the
search tools with the old warning, and leaves toolConfig without
includeServerSideToolInvocations. The regression test goes through
get_optional_params like completion does

* fix(gemini): drop search next to functions when tool_choice forces a call, give cyber rows the Gemini 3 search free tier

* fix(gemini): drop search next to functions when tool_choice is none

A tool_choice of none maps to functionCallingConfig mode NONE, which Gemini applies to function declarations only, so a kept googleSearch or urlContext could still run. Gemini 3+ now keeps the old drop for none, like it does for required and a named function.

* fix(gemini): keep the old search drop when an extra_body tool config opts out

A caller toolConfig or tool_config in extra_body that turns includeServerSideToolInvocations off, or pins functionCallingConfig mode to ANY or NONE, now drops search tools next to functions the way tool_choice does, instead of sending them and failing on AI Studio

* fix(gemini): put the server-side tool flag in the context cache with the search tools

When a cache_control message and mixed search and function tools reach a
Gemini 3+ model, the cache step built the cached content from the raw tools
and then sent toolConfig next to cachedContent, which Google rejects with a 400

The tool fields are now settled before the cache step, so the cached content
carries the search tool, the function tools and the includeServerSideToolInvocations
flag, and the generateContent call beside cachedContent carries neither. A
caller who turns server-side tools off still caches the functions without search

* fix(guardrails): scan Gemini web search queries in /v1/responses output like Claude's

Gemini web_search_call items now carry a gsearch_ tool id, so the Responses
guardrail handler and the Cato, Cisco and Purview hooks scan their queries the
same way they scan Claude's hosted searches. Native OpenAI search calls stay
untouched.

* fix(vertex_ai): scope Gemini search call id hashes to their response

The id suffix hashed only the query, so the same query got the same suffix in every response one worker served. Hash the response id with the query so ids differ across responses and stay stable within one

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-23 07:29:54 +00:00
..
chat fix(guardrails): write rewritten tool_calls from the Generic Guardrail API back to the client (#50413) 2026-11-18 15:25:29 -08:00
completion fix(openai): relay param and plain message from OpenAI-compatible backend errors (#53217) 2026-11-20 15:53:54 -08:00
decisions fix(decisions): match OpenAI format answers to questions by name (#52597) 2026-11-18 12:55:45 -08:00
embeddings fix(gemini): support explicit text in embedding inputs (#53135) 2026-11-20 11:05:11 -08:00
evals fix(llms): join api_base and route with one shared helper (#47535) 2026-10-21 06:59:32 +00:00
image_generation refactor(images): remove dall-e-2 and dall-e-3 code paths (#48703) 2026-10-28 17:48:09 -07:00
image_variations fix(openai): keep the upstream error body on e.response for OpenAI and Azure errors (#49079) 2026-10-29 23:30:02 -07:00
live feat(realtime)!: serve GPT-Live over WebRTC with sideband attach, and bill WebRTC calls from a proxy sideband (#53282) 2026-11-21 22:49:26 -08:00
realtime feat(realtime)!: support latest OpenAI audio models (#35600) 2026-11-03 07:27:52 +00:00
responses fix(vertex_ai): keep Gemini 3+ web search next to function tools and report searches as web_search_call items (#53423) 2026-11-23 07:29:54 +00:00
speech test: add package initializers to migrated unit test directories 2026-09-20 11:52:07 +00:00
transcriptions feat(provider)!: add ResetData and stop sending OPENAI_API_KEY to keyless JSON-configured providers (#50819) 2026-11-20 22:20:25 -08:00
vector_store_files fix(proxy)!: return provider-matching 4xx for the LIT-8062 status code follow-ups (#45537) 2026-10-13 11:42:39 -07:00
vector_stores test: add package initializers to migrated unit test directories 2026-09-20 11:52:07 +00:00
videos feat(videos): add first-class OpenRouter video request fields (#50319) 2026-11-06 16:50:48 -08:00
__init__.py test(unit): make every tests/unit directory a package so pytest collection is unique 2026-09-20 11:50:59 +00:00
test_cost_calculation.py feat(fal_ai): bill fal video clips by duration and resolution (#51679) 2026-11-13 12:55:55 -08:00
test_data_residency.py feat(openai): bill gov.api.openai.com FedRAMP endpoint with 1.1x uplift (#49951) 2026-11-04 08:57:42 -08:00
test_gpt_reasoning_transformation.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_is_model_gpt_5_model.py refactor(llms): rename model-version transformation files to family names (#48509) 2026-10-26 18:53:16 -07:00
test_o_series_transformation.py fix(openai): stop stripping cache_control from the caller's own messages and tools (#35602) 2026-10-31 00:29:10 -07:00
test_openai.py fix(openai): preserve omitted headers for chat and embeddings (#53132) 2026-11-20 10:29:22 -08:00
test_openai_audio_speech.py fix(cost): bill OpenAI token-priced aac and flac speech on the length of the returned audio (#53308) 2026-11-21 19:53:23 +00:00
test_openai_authentication_error.py test: migrate local_testing SDK and provider tests out of build_and_test (#45760) 2026-10-10 23:14:25 +00:00
test_openai_common_utils.py fix(logging): warn when drop_params drops a requested reasoning level on the remaining paths (#48933) 2026-10-30 08:48:43 -07:00
test_openai_empty_response.py fix(openai): send chat completions through client.post so the SDK's per-message param transform stops holding the event loop (#46967) 2026-10-16 18:06:01 -07:00
test_openai_file_content_streaming.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_openai_image_edit_transformation.py fix(cost): bill SVG authoring usage on OpenAI image responses (#52571) 2026-11-18 13:04:49 -08:00
test_openai_workload_identity.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_organization_costs.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_use_chat_completions_api_no_leak.py fix(openai): send chat completions through client.post so the SDK's per-message param transform stops holding the event loop (#46967) 2026-10-16 18:06:01 -07:00