BerriAI/litellm · error · ValueError

TINYFISH_API_KEY is not set. Set `TINYFISH_API_KEY` environm

Error message

TINYFISH_API_KEY is not set. Set `TINYFISH_API_KEY` environment variable.

What it means

For Tinyfish web search, LiteLLM resolves the credential through resolve_server_api_key using the caller's api_key argument or the TINYFISH_API_KEY environment variable. If neither is present it raises this ValueError in validate_environment, before the search request is dispatched. The resolved key would be sent as the X-API-Key header.

Source

Thrown at litellm/llms/tinyfish/search/transformation.py:67

    def get_http_method(self) -> Literal["GET", "POST"]:
        return "GET"

    def validate_environment(
        self,
        headers: dict[str, str],
        api_key: str | None = None,
        api_base: str | None = None,
        **kwargs: object,
    ) -> dict[str, str]:
        resolved_key: Final = self.resolve_server_api_key(
            caller_api_key=api_key,
            caller_api_base=api_base,
            key_env_vars=("TINYFISH_API_KEY",),
            base_env_var="TINYFISH_API_BASE",
            default_api_base=self.TINYFISH_API_BASE,
        )
        if not resolved_key:
            raise ValueError("TINYFISH_API_KEY is not set. Set `TINYFISH_API_KEY` environment variable.")
        return {**headers, "X-API-Key": resolved_key, "Accept": "application/json"}

    def get_complete_url(
        self,
        api_base: str | None,
        optional_params: dict[str, object],
        data: dict[str, object] | list[dict[str, object]] | None = None,
        **kwargs: object,
    ) -> str:
        resolved_base: Final = api_base or get_secret_str("TINYFISH_API_BASE") or self.TINYFISH_API_BASE
        if isinstance(data, dict) and _TINYFISH_PARAMS_KEY in data:
            validated_params: Final = _UrlEncodableParams.validate_python(data[_TINYFISH_PARAMS_KEY])
            return f"{resolved_base}?{urlencode(validated_params, doseq=True)}"
        return resolved_base

    def transform_search_request(
        self,
        query: str | list[str],

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set TINYFISH_API_KEY in the runtime environment of the litellm process.
  2. Pass api_key explicitly on the web_search call or via proxy model_list litellm_params.
  3. Check the variable is exported and non-empty in the exact process making the call.
  4. Optionally set TINYFISH_API_BASE as well if you use a non-default Tinyfish endpoint.

Example fix

# before
results = litellm.web_search(query="tinyfish llm search", provider="tinyfish")
# -> ValueError: TINYFISH_API_KEY is not set...

# after
import os
results = litellm.web_search(
    query="tinyfish llm search",
    provider="tinyfish",
    api_key=os.environ["TINYFISH_API_KEY"],
)
Defensive patterns

Strategy: validation

Validate before calling

import os


def tinyfish_search_ready(api_key: str | None = None) -> bool:
    return bool(api_key or os.environ.get("TINYFISH_API_KEY"))


if not tinyfish_search_ready():
    raise RuntimeError("TINYFISH_API_KEY not configured — cannot use tinyfish provider")

Try / catch

try:
    results = litellm.web_search(query=q, provider="tinyfish")
except ValueError as e:
    if "TINYFISH_API_KEY is not set" in str(e):
        results = litellm.web_search(query=q, provider="tavily")  # fallback provider
    else:
        raise

Prevention

When it happens

Trigger: Invoking litellm.web_search(provider='tinyfish', ...) (or the equivalent proxy route) when TINYFISH_API_KEY is not set in the process environment and no api_key kwarg is supplied.

Common situations: Adding the Tinyfish provider to a gateway without provisioning its key; local development where the key is in a different shell's env; deploying to serverless (Lambda/Cloud Run) where env vars must be configured in the platform; renaming from another provider's key variable and missing the update.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/e0be9128eec99a6f. Report an issue: GitHub.