{"record":{"id":"3074888d7f43e092","repo":"BerriAI/litellm","slug":"gradientai-api-key-not-found","errorCode":null,"errorMessage":"GradientAI API key not found","messagePattern":"GradientAI API key not found","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gradient_ai/chat/transformation.py","lineNumber":90,"sourceCode":"            \"include_guardrails_info\",\n            \"provide_citations\",\n            \"retrieval_method\",\n        ]\n        return supported_params\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n    ):\n        api_key = api_key or get_secret_str(\"GRADIENT_AI_API_KEY\")\n        if api_key is None:\n            raise ValueError(\"GradientAI API key not found\")\n        if headers is None:\n            headers = {}\n        headers[\"Authorization\"] = f\"Bearer {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        api_key: str | None,\n        model: str,\n        optional_params: dict,\n        litellm_params: dict,\n        stream: bool | None = None,\n    ) -> str:\n        gradient_ai_endpoint: Final = get_secret_str(\"GRADIENT_AI_AGENT_ENDPOINT\")\n        complete_url = f\"{GRADIENT_AI_SERVERLESS_ENDPOINT}/v1/chat/completions\"\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/gradient_ai/chat/transformation.py#L72-L108","documentation":"Thrown by GradientAIChatConfig.validate_environment when no API key can be resolved. LiteLLM first uses the api_key argument passed to the completion call, then falls back to the GRADIENT_AI_API_KEY environment variable (via get_secret_str); if both are absent it raises this ValueError before any HTTP request is made. It is a configuration error, not a network or provider error.","triggerScenarios":"Calling litellm.completion(..., model='gradient_ai/<model>') with neither api_key= supplied nor the GRADIENT_AI_API_KEY env var set (also fails if the secret is set to an empty string, since get_secret_str returns None for empty values).","commonSituations":"Local dev machine where .env was not loaded; CI/production where the secret was not injected; typo in the env var name (e.g. GRADIENTAI_API_KEY); using a custom key manager but forgetting to pass it per-request.","solutions":["Set the environment variable: export GRADIENT_AI_API_KEY=<your key> (or add it to your .env / secret manager).","Or pass the key explicitly per call: litellm.completion(model='gradient_ai/...', api_key='...', messages=[...]).","If using a proxy (LiteLLM proxy), add the gradient_ai key to the virtual key's model settings / environment config.","Verify with a quick check that the variable is visible to the process (e.g. `env | grep GRADIENT`) — empty strings do not count as set."],"exampleFix":"# before\nresponse = litellm.completion(model='gradient_ai/llama-3.1-8b-instruct', messages=[{'role':'user','content':'hi'}])\n# raises ValueError: GradientAI API key not found\n\n# after\nresponse = litellm.completion(\n    model='gradient_ai/llama-3.1-8b-instruct',\n    messages=[{'role':'user','content':'hi'}],\n    api_key=os.environ['GRADIENT_AI_API_KEY'],\n)","handlingStrategy":"validation","validationCode":"import os\n\ndef has_gradient_ai_key(api_key: str | None = None) -> bool:\n    return bool(api_key or os.environ.get(\"GRADIENT_AI_API_KEY\"))\n\nif not has_gradient_ai_key():\n    raise RuntimeError(\"GRADIENT_AI_API_KEY is not set; refusing to call gradient_ai\")","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model=\"gradient_ai/...\", messages=msgs, api_key=key)\nexcept ValueError as e:\n    if \"API key not found\" in str(e):\n        # config problem, not transient — fail loudly / alert\n        raise","preventionTips":["Set GRADIENT_AI_API_KEY in your secret manager and assert it is non-empty at app startup before any gradient_ai call.","Pass api_key explicitly from your secret store instead of relying on ambient env when running in shared environments."],"tags":["gradient-ai","authentication","configuration","api-key","env-vars"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}