{"record":{"id":"c2b3612f16bab19b","repo":"BerriAI/litellm","slug":"apiserpent-api-key-is-not-set-set-apiserpent-api","errorCode":null,"errorMessage":"APISERPENT_API_KEY is not set. Set `APISERPENT_API_KEY` environment variable.","messagePattern":"APISERPENT_API_KEY is not set\\. Set `APISERPENT_API_KEY` environment variable\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/apiserpent/search/transformation.py","lineNumber":64,"sourceCode":"    def _is_deep_search(optional_params: dict) -> bool:\n        return bool(optional_params.get(DEEP_SEARCH_PARAM))\n\n    def validate_environment(\n        self,\n        headers: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n        **kwargs,\n    ) -> dict:\n        api_key = self.resolve_server_api_key(\n            caller_api_key=api_key,\n            caller_api_base=api_base,\n            key_env_vars=(\"APISERPENT_API_KEY\",),\n            base_env_var=\"APISERPENT_API_BASE\",\n            default_api_base=APISERPENT_BASE,\n        )\n        if not api_key:\n            raise ValueError(\"APISERPENT_API_KEY is not set. Set `APISERPENT_API_KEY` environment variable.\")\n        headers[\"X-API-Key\"] = api_key\n        headers[\"Content-Type\"] = \"application/json\"\n        return headers\n\n    def get_complete_url(\n        self,\n        api_base: str | None,\n        optional_params: dict,\n        data: dict | list[dict] | None = None,\n        **kwargs,\n    ) -> str:\n        \"\"\"\n        Build the search URL. APISerpent uses GET, so the transformed request is\n        serialized into the query string. The endpoint path (quick vs deep) is\n        always applied; an ``api_base`` / ``APISERPENT_API_BASE`` override only\n        changes the host. The ``endswith`` guard keeps this idempotent, since the\n        handler re-invokes this method with the already-resolved URL as api_base.\n        \"\"\"","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/apiserpent/search/transformation.py#L46-L82","documentation":"Credential resolution for the apiserpent search provider. validate_headers resolves the API key from the caller-supplied api_key or the APISERPENT_API_KEY env var; if nothing resolves, a ValueError is raised before any HTTP call. The SerpApi-style search endpoint requires this key in the X-API-Key header.","triggerScenarios":"Invoking apiserpent search without an api_key argument while APISERPENT_API_KEY is not exported in the process env. The API base can default fine (APISERPENT_BASE), but a missing key always aborts.","commonSituations":"New integration before the key was provisioned; key present in .env but the file not loaded (dotenv not run); CI jobs missing the secret; key named differently (e.g. SERPAPI_API_KEY) by mistake.","solutions":["export APISERPENT_API_KEY=your-key before starting the app.","Or pass api_key explicitly on the call / in the model's litellm_params.","If using dotenv, confirm load_dotenv() runs before the first search call."],"exampleFix":"# before\nresults = litellm.search(query=\"litellm\", web_search_provider=\"apiserpent\")  # no key\n\n# after\nimport os\nos.environ[\"APISERPENT_API_KEY\"] = \"your-key\"\nresults = litellm.search(query=\"litellm\", web_search_provider=\"apiserpent\")","handlingStrategy":"validation","validationCode":"import os\n\ndef apiserpent_key_present() -> bool:\n    return bool(os.getenv(\"APISERPENT_API_KEY\"))","typeGuard":null,"tryCatchPattern":"try:\n    results = litellm.search(query=q, web_search_provider=\"apiserpent\")\nexcept ValueError as e:\n    if \"APISERPENT_API_KEY\" in str(e):\n        return http_error(503, \"search provider not configured\")\n    raise","preventionTips":["Provision and export APISERPENT_API_KEY before enabling the apiserpent provider.","Call load_dotenv() at app start if the key lives in .env.","Add a startup config check listing every enabled provider and its key presence."],"tags":["apiserpent","auth","api-key","search","environment"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}