{"record":{"id":"10b353834380bb42","repo":"BerriAI/litellm","slug":"openai-api-key-is-required-for-evals-api","errorCode":null,"errorMessage":"OPENAI_API_KEY is required for Evals API","messagePattern":"OPENAI_API_KEY is required for Evals API","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/openai/evals/transformation.py","lineNumber":59,"sourceCode":"\n    @property\n    def custom_llm_provider(self) -> LlmProviders:\n        return LlmProviders.OPENAI\n\n    def validate_environment(self, headers: dict, litellm_params: GenericLiteLLMParams | None) -> dict:\n        \"\"\"Add OpenAI-specific headers\"\"\"\n        import litellm\n        from litellm.secret_managers.main import get_secret_str\n\n        # Get API key following OpenAI pattern\n        api_key = None\n        if litellm_params:\n            api_key = litellm_params.api_key\n\n        api_key = api_key or litellm.api_key or litellm.openai_key or get_secret_str(\"OPENAI_API_KEY\")\n\n        if not api_key:\n            raise ValueError(\"OPENAI_API_KEY is required for Evals API\")\n\n        # Add required headers\n        headers[\"Authorization\"] = f\"Bearer {api_key}\"\n        headers[\"Content-Type\"] = \"application/json\"\n\n        return headers\n\n    def get_complete_url(\n        self,\n        api_base: str | None,\n        endpoint: str,\n        eval_id: str | None = None,\n    ) -> str:\n        \"\"\"Get complete URL for OpenAI Evals API\"\"\"\n        if api_base is None:\n            api_base = \"https://api.openai.com\"\n\n        if eval_id:","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/openai/evals/transformation.py#L41-L77","documentation":"litellm's OpenAI Evals API integration requires an API key before it can build Authorization headers. It checks, in order: litellm_params.api_key, litellm.api_key, litellm.openai_key, and the OPENAI_API_KEY environment variable (via the secret manager). If none is found it raises ValueError('OPENAI_API_KEY is required for Evals API') because anonymous access to the Evals API is impossible.","triggerScenarios":"Calling litellm evals endpoints (create/retrieve/list runs, e.g. via litellm.evaluate or the evals handler) without api_key in the request params, without litellm.api_key/litellm.openai_key being set globally, and without OPENAI_API_KEY exported in the environment (or present in a .env/Doppler/etc. source the secret manager reads).","commonSituations":"CI jobs and Docker containers where the env var was never injected; notebooks that call evals before litellm.api_key = 'sk-...' is set; .env files not loaded because python-dotenv was never invoked; using Azure or other providers for chat but calling OpenAI Evals without realizing it specifically needs an OpenAI key.","solutions":["Export OPENAI_API_KEY in the environment where the code runs: export OPENAI_API_KEY=sk-... (or add it to your .env and load it)","Pass the key explicitly in the call params (api_key=...) or set litellm.api_key = 'sk-...' before calling evals","For Docker/CI, inject the variable at runtime (docker run -e OPENAI_API_KEY=..., GitHub/Actions secret, etc.) rather than baking it into images","If using a secret manager, confirm get_secret_str('OPENAI_API_KEY') can actually resolve it (correct provider enabled and configured)"],"exampleFix":"# before\nresult = litellm.analyze_evals(...)  # ValueError: OPENAI_API_KEY is required for Evals API\n\n# after\nimport litellm\nlitellm.api_key = os.environ[\"OPENAI_API_KEY\"]  # or pass api_key=... in params\nresult = litellm.analyze_evals(...)","handlingStrategy":"validation","validationCode":"import os, litellm\nfrom litellm.secret_managers.main import get_secret_str\n\ndef has_openai_key_for_evals() -> bool:\n    return bool(\n        getattr(litellm, \"api_key\", None)\n        or getattr(litellm, \"openai_key\", None)\n        or get_secret_str(\"OPENAI_API_KEY\")\n        or os.getenv(\"OPENAI_API_KEY\")\n    )\n\nassert has_openai_key_for_evals(), \"set OPENAI_API_KEY before running evals\"","typeGuard":null,"tryCatchPattern":"try:\n    run_evals()\nexcept ValueError as e:\n    if \"OPENAI_API_KEY is required\" in str(e):\n        raise SystemExit(\"Export OPENAI_API_KEY and re-run\") from e\n    raise","preventionTips":["Set OPENAI_API_KEY in your process environment (or .env loaded via dotenv) at startup, before any evals call","Prefer passing api_key explicitly in evals params over relying on ambient global state","Add a startup key-check assertion so configuration failures happen at boot, not mid-evaluation","In Docker/CI, inject the secret at runtime and never assume it is inherited from the host shell"],"tags":["authentication","missing-api-key","evals","env-var","openai"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}