Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge origin/litellm_internal_staging into feat/tinyfish-search-headers-and-extras

Chenlu Ji711ef5dbf0a5
diff --cc litellm/llms/tinyfish/search/transformation.py
index aea0dfe8b8e,ba9ca2e1bde..ae11b4bcc57
--- a/litellm/llms/tinyfish/search/transformation.py
+++ b/litellm/llms/tinyfish/search/transformation.py
@@@ -23,13 -22,13 +23,13 @@@ from litellm.llms.base_llm.search.trans
)
from litellm.secret_managers.main import get_secret_str
- _UrlEncodableParams = TypeAdapter(dict[str, str | int | float | bool])
- _StrList = TypeAdapter(list[str])
- _StrFrozenSet = TypeAdapter(frozenset[str])
-_UrlEncodableParams: Final = TypeAdapter(dict[str, str | int | bool])
++_UrlEncodableParams: Final = TypeAdapter(dict[str, str | int | float | bool])
+ _StrList: Final = TypeAdapter(list[str])
+ _StrFrozenSet: Final = TypeAdapter(frozenset[str])
- _TINYFISH_PARAMS_KEY = "_tinyfish_params"
- _TINYFISH_DOCS_URL = "https://docs.tinyfish.ai/search-api"
- _TINYFISH_RESULT_CAP = 10 # Client-side truncation cap for max_results
+ _TINYFISH_PARAMS_KEY: Final = "_tinyfish_params"
+ _TINYFISH_DOCS_URL: Final = "https://docs.tinyfish.ai/search-api"
+ _TINYFISH_RESULT_CAP: Final = 10 # TinyFish's natural per-page SERP ceiling
class TinyfishSearchConfig(BaseSearchConfig):
@@@ -139,18 -138,20 +139,18 @@@
raw_max,
)
- raw_supported: object = (
+ raw_supported: Final[object] = (
self.get_supported_perplexity_optional_params() # any-ok: base class returns bare set
)
- supported_perplexity = _StrFrozenSet.validate_python(raw_supported)
+ supported_perplexity: Final = _StrFrozenSet.validate_python(raw_supported)
for param, value in optional_params.items():
if param not in supported_perplexity and param not in request_data:
- # `fetch` expects a JSON-encoded object on the wire; accept the
- # natural Python dict form and serialize here so callers don't
- # have to pre-stringify.
- if isinstance(value, dict):
+ # Serialize dicts/lists as JSON so structured params survive urlencode.
+ if isinstance(value, (dict, list)):
value = json.dumps(value, separators=(",", ":"))
# `urlencode` would render Python bool as "True"/"False"
- # (capitalized). ux-labs validators require lowercase
- # "true"/"false" (e.g. `include_thumbnail`); normalize here.
+ # (capitalized). TinyFish Search's bool params require lowercase
+ # "true"/"false" strings on the wire; normalize here.
elif isinstance(value, bool):
value = "true" if value else "false"
request_data[param] = value
@@@ -239,13 -222,8 +239,13 @@@
_emit_parameter_warnings(parsed)
- max_results = self._caller_max_results or _TINYFISH_RESULT_CAP
+ max_results: Final = self._caller_max_results or _TINYFISH_RESULT_CAP
- return SearchResponse(results=list(parsed.results[:max_results]))
+ # Truncate in place so all pydantic-populated fields survive — declared and extras.
+ parsed.results = list(parsed.results[:max_results])
+ raw_headers = dict(raw_response.headers)
+ parsed._hidden_params["headers"] = raw_headers
+ parsed._hidden_params["additional_headers"] = process_response_headers(raw_headers)
+ return parsed
def _wrap_error(
self,
@@@ -265,16 -243,16 +265,16 @@@
carry the ``TinyFish Search:`` prefix — the bare error already names
the host in the URL, so attribution is implicit there.
"""
- # ux-labs frontend wraps every error body as {"error": {"code", "message", "details"?}}.
+ # TinyFish Search wraps every error body as {"error": {"code", "message", "details"?}}.
# Best-effort unwrap to surface the inner message; fall back to the raw body
- # for non-ux-labs responses (CDN HTML pages, other JSON envelopes, plain text).
+ # for other envelope shapes (CDN HTML pages, other JSON envelopes, plain text).
inner_message = error_message
try:
- body: object = json.loads(error_message) # any-ok: json.loads -> Any
+ body: Final[object] = json.loads(error_message) # any-ok: json.loads -> Any
if isinstance(body, dict):
- error_obj: object = body.get("error") # any-ok: untyped dict
+ error_obj: Final[object] = body.get("error") # any-ok: untyped dict
if isinstance(error_obj, dict):
- candidate: object = error_obj.get("message") # any-ok: untyped dict
+ candidate: Final[object] = error_obj.get("message") # any-ok: untyped dict
if isinstance(candidate, str) and candidate:
inner_message = candidate
except (json.JSONDecodeError, TypeError):