{"record":{"id":"1a4a7e3a99f580af","repo":"BerriAI/litellm","slug":"stability-api-key-is-not-set-please-set-it-via-en","errorCode":null,"errorMessage":"STABILITY_API_KEY is not set. Please set it via environment variable or pass api_key parameter.","messagePattern":"STABILITY_API_KEY is not set\\. Please set it via environment variable or pass api_key parameter\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/stability/image_edit/transformations.py","lineNumber":159,"sourceCode":"\n        endpoint: Final = self._get_model_endpoint(model)\n        return f\"{base_url}{endpoint}\"\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        litellm_params: dict | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        \"\"\"\n        Validate environment and set up headers for Stability AI.\n        \"\"\"\n        final_api_key: Final[str | None] = api_key or get_secret_str(\"STABILITY_API_KEY\")\n\n        if not final_api_key:\n            raise ValueError(\n                \"STABILITY_API_KEY is not set. Please set it via environment variable or pass api_key parameter.\"\n            )\n\n        headers[\"Authorization\"] = f\"Bearer {final_api_key}\"\n        headers[\"Accept\"] = \"application/json\"\n        return headers\n\n    def transform_image_edit_request(\n        self,\n        model: str,\n        prompt: str | None,\n        image: FileTypes | None,\n        image_edit_optional_request_params: dict,\n        litellm_params: GenericLiteLLMParams,\n        headers: dict,\n    ) -> tuple[dict, RequestFiles]:\n        \"\"\"\n        Transform OpenAI-style request to Stability AI request format.","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/stability/image_edit/transformations.py#L141-L177","documentation":"Before sending a Stability AI image-edit request, LiteLLM resolves the API key from the explicit api_key argument or the STABILITY_API_KEY environment variable (via get_secret_str). If both are empty it raises this ValueError during validate_environment, so no request reaches Stability. It is a configuration error, not an HTTP error from the provider.","triggerScenarios":"Calling litellm.image_edit(model=\"stability/...\", ...) in a shell/process where STABILITY_API_KEY is not exported and no api_key=\"sk-...\" kwarg is passed. Also when the variable exists but is empty, or is set in .env but never loaded before the call.","commonSituations":"CI jobs, Docker containers, or cron environments that don't inherit your interactive shell env; deploying code that worked locally because the key lived in ~/.bashrc; typos in the variable name (STABILITY_KEY, STABILITYAI_API_KEY); expecting the key from a different provider's env var to be reused.","solutions":["Export the variable in the runtime environment: export STABILITY_API_KEY=<your-key> (add to .env / CI secrets / Docker env).","Pass the key explicitly per call: litellm.image_edit(..., api_key=\"<your-key>\") or configure it on the Router deployment.","Verify with a quick check that the key is visible to the process (e.g. env | grep STABILITY) before retrying.","If using litellm proxy, set the key in the model deployment's litellm_params.api_key or the environment of the proxy process."],"exampleFix":"# before\nresp = litellm.image_edit(model=\"stability/stability-image-edit\", prompt=\"...\", image=fp)\n# -> ValueError: STABILITY_API_KEY is not set...\n\n# after\nimport os\nresp = litellm.image_edit(\n    model=\"stability/stability-image-edit\",\n    prompt=\"...\",\n    image=fp,\n    api_key=os.environ[\"STABILITY_API_KEY\"],\n)\n# or: export STABILITY_API_KEY=... in the shell / container","handlingStrategy":"validation","validationCode":"import os\n\n\ndef stability_edit_ready(**kwargs) -> bool:\n    \"\"\"True when a Stability image-edit call has credentials.\"\"\"\n    return bool(kwargs.get(\"api_key\") or os.environ.get(\"STABILITY_API_KEY\"))\n\n\nif not stability_edit_ready():\n    raise RuntimeError(\"configure STABILITY_API_KEY before accepting image-edit jobs\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.image_edit(model=\"stability/...\", prompt=p, image=fp)\nexcept ValueError as e:\n    if \"STABILITY_API_KEY is not set\" in str(e):\n        # config error — surface to operator, do not retry\n        alert_ops(\"missing STABILITY_API_KEY\")\n        raise\n    raise","preventionTips":["Fail fast at startup: assert required provider env vars exist before serving requests.","Pass api_key explicitly from your secrets manager instead of relying on ambient env.","In containers/CI, declare the env var in the task definition so it can never be silently absent."],"tags":["stability-ai","image-edit","api-key","environment-variables","litellm"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T11:17:13.642Z"}