{"record":{"id":"c9dd7207e3546400","repo":"BerriAI/litellm","slug":"dashscope-api-key-is-not-set","errorCode":null,"errorMessage":"DASHSCOPE_API_KEY is not set","messagePattern":"DASHSCOPE_API_KEY is not set","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/dashscope/image_generation/transformation.py","lineNumber":112,"sourceCode":"        optional_params: dict,\n        litellm_params: dict,\n        stream: bool | None = None,\n    ) -> str:\n        return api_base or get_secret_str(\"DASHSCOPE_API_BASE_IMAGE\") or DEFAULT_API_BASE\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    ) -> dict:\n        final_api_key: Final = api_key or get_secret_str(\"DASHSCOPE_API_KEY\")\n        if not final_api_key:\n            raise ValueError(\"DASHSCOPE_API_KEY is not set\")\n        headers[\"Authorization\"] = f\"Bearer {final_api_key}\"\n        headers[\"Content-Type\"] = \"application/json\"\n        return headers\n\n    def transform_image_generation_request(\n        self,\n        model: str,\n        prompt: str,\n        optional_params: dict,\n        litellm_params: dict,\n        headers: dict,\n    ) -> dict:\n        \"\"\"\n        Transform OpenAI-style image generation request to DashScope multimodal-generation format.\n        \"\"\"\n        parameters: Final[dict] = {}\n        for k, v in optional_params.items():\n            parameters[k] = v","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/dashscope/image_generation/transformation.py#L94-L130","documentation":"Raised during request preparation for DashScope image generation: neither an explicit api_key parameter nor the DASHSCOPE_API_KEY environment variable is available, so no Authorization header can be built. It is a plain ValueError thrown from validate_environment before any HTTP request is made.","triggerScenarios":"Calling litellm.image_generation() with a dashscope model without passing api_key and without DASHSCOPE_API_KEY set in the environment (or set to an empty string).","commonSituations":"Deploying to a new environment (container, CI) where the env var was not carried over; typos in the variable name (e.g. DASHSCOPE_KEY); expecting LiteLLM's generic API_KEY convention instead of the provider-specific name.","solutions":["Set DASHSCOPE_API_KEY in the environment: export DASHSCOPE_API_KEY=sk-...","Or pass the key explicitly: litellm.image_generation(..., api_key=key)","In server deployments, configure it as a provider environment variable in the LiteLLM proxy env settings","Verify with: python -c \"import os; print(bool(os.getenv('DASHSCOPE_API_KEY')))\""],"exampleFix":"# before\nimg = litellm.image_generation(model=\"dashscope/wanx-v1\", prompt=\"a cat\")\n\n# after\nimg = litellm.image_generation(model=\"dashscope/wanx-v1\", prompt=\"a cat\", api_key=os.environ[\"DASHSCOPE_API_KEY\"])","handlingStrategy":"validation","validationCode":"api_key = os.getenv(\"DASHSCOPE_API_KEY\")\nif not api_key:\n    raise RuntimeError(\"DASHSCOPE_API_KEY missing — set it before image generation\")","typeGuard":"def has_dashscope_key(params: dict) -> bool:\n    return bool(params.get(\"api_key\") or os.getenv(\"DASHSCOPE_API_KEY\"))","tryCatchPattern":"try:\n    img = litellm.image_generation(model=m, prompt=p, api_key=os.getenv(\"DASHSCOPE_API_KEY\"))\nexcept ValueError as e:\n    if \"DASHSCOPE_API_KEY\" in str(e):\n        raise ConfigError(\"Configure DASHSCOPE_API_KEY\") from e\n    raise","preventionTips":["Add a startup config check that asserts DASHSCOPE_API_KEY is present when dashscope models are configured","Pass api_key explicitly from your secret manager instead of relying on ambient env"],"tags":["dashscope","image-generation","authentication","config"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}