litellm/tests/unit/search
Mateo Wang 82dfb4b7ac
feat(search): let litellm.search() call a search tool on a LiteLLM proxy (#55286)
* feat(search): let litellm.search() call a search tool on a LiteLLM proxy

Adds a litellm_proxy search provider that posts to <api_base>/search/<search_tool_name> with the caller's virtual key and returns the proxy's SearchResponse unchanged. BaseSearchConfig gets a forwarded_litellm_params() hook so only this provider receives search_tool_name.

* fix(search): call the downstream tool a proxy search tool names

A litellm_proxy search tool now calls the tool its own litellm_params.search_tool_name names, never the local alias the request used. The search tool create API keeps that key, and a proxy tool without it is a 400 before any request.

* fix(search): pass a proxy search tool's downstream name in test_connection

* fix(search): keep the litellm_proxy provider out of the dashboard's provider list

The dashboard's search tool form has no field for the base URL or the downstream tool name, so a litellm_proxy tool created there could never work. Config-file and API-created tools keep working.

* fix(search): reach slash-named proxy tools, bill the cost the proxy reports, keep tool settings on dashboard edit

* fix(search_tools): keep the stored api key when the dashboard sends back its masked value

* fix(search_tools): restore a masked key only for the same provider and base URL, and never echo the stored key

A dashboard edit that switches the provider or base URL no longer sends the old provider's stored key to the new host, and the PUT response now shows the params the caller sent. The shared search env-key guard now says the key came from the environment, since an SDK caller's own env var hits it too

* fix(search): send only the tool's key to a downstream proxy, and accept an api_base ending in /search

When a litellm_proxy search call has its own key, every caller header the proxy reads as a key is dropped, so only that key reaches the downstream proxy. A base whose path already ends in /search gets only /<tool> added

* fix(search): keep a proxy tool named search at its own route

The SDK builds the downstream URL twice, and the /search base rule added a third search segment for a tool named search

* fix(search): let API gateway key headers through and keep an api_base query string at the end

Round 3 dropped every header a proxy can read as a key, which also dropped an API gateway's x-api-key or Ocp-Apim-Subscription-Key. A LiteLLM proxy reads those only without an Authorization header, so only the caller's Authorization and the proxy's own key header are dropped now. An api_base query string used to end up in the middle of the search URL
2026-12-04 11:57:45 -08:00
..
__init__.py
test_main.py feat(search): let litellm.search() call a search tool on a LiteLLM proxy (#55286) 2026-12-04 11:57:45 -08:00