{"record":{"id":"2c2832cdb6c7af96","repo":"invoke-ai/InvokeAI","slug":"alibaba-cloud-dashscope-api-key-is-not-configured","errorCode":null,"errorMessage":"Alibaba Cloud DashScope API key is not configured","messagePattern":"Alibaba Cloud DashScope API key is not configured","errorType":"exception","errorClass":"ExternalProviderRequestError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/external_generation/providers/alibabacloud.py","lineNumber":51,"sourceCode":"_TASK_POLL_INTERVAL = 5  # seconds\n_TASK_POLL_TIMEOUT = 300  # seconds\n_DOWNLOAD_TIMEOUT = 60  # seconds\n_DOWNLOAD_MAX_BYTES = 32 * 1024 * 1024  # 32 MiB safety cap on image downloads\n_RETRY_STATUS_CODES = {429, 500, 502, 503, 504}\n_MAX_RETRIES = 2  # total attempts = 1 + _MAX_RETRIES\n_RETRY_BACKOFF_BASE = 2.0  # seconds\n\n\nclass AlibabaCloudProvider(ExternalProvider):\n    provider_id = \"alibabacloud\"\n\n    def is_configured(self) -> bool:\n        return bool(self._app_config.external_alibabacloud_api_key)\n\n    def generate(self, request: ExternalGenerationRequest) -> ExternalGenerationResult:\n        api_key = self._app_config.external_alibabacloud_api_key\n        if not api_key:\n            raise ExternalProviderRequestError(\"Alibaba Cloud DashScope API key is not configured\")\n\n        base_url = (self._app_config.external_alibabacloud_base_url or \"https://dashscope-intl.aliyuncs.com\").rstrip(\n            \"/\"\n        )\n        model_id = request.model.provider_model_id\n        headers = {\n            \"Content-Type\": \"application/json\",\n            \"Authorization\": f\"Bearer {api_key}\",\n        }\n        size = f\"{request.width}*{request.height}\"\n\n        if model_id in _SYNC_MODELS:\n            return self._generate_sync(request, base_url, headers, model_id, size)\n        if model_id in _ASYNC_MODELS:\n            return self._generate_async(request, base_url, headers, model_id, size)\n        raise ExternalProviderRequestError(\n            f\"Unknown DashScope model_id '{model_id}'. Add it to _SYNC_MODELS or _ASYNC_MODELS in alibabacloud.py.\"\n        )","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/external_generation/providers/alibabacloud.py#L33-L69","documentation":"The Alibaba Cloud DashScope provider checks the API key at request time; is_configured() reflects the same check. If external_alibabacloud_api_key is unset/empty in app config, generate() raises ExternalProviderRequestError instead of making an unauthenticated HTTP call. It indicates a configuration problem, not a transient API failure.","triggerScenarios":"Calling generate() (directly or via the external generation service routed to the alibabacloud provider) when self._app_config.external_alibabacloud_api_key is falsy — key never set, set to empty string, or config not reloaded after editing.","commonSituations":"Fresh InvokeAI install without provider keys configured; environment variable or config file entry for the DashScope key missing/typo'd; key removed during config migration; selecting the Alibaba provider while only other providers' keys are configured.","solutions":["Set the external_alibabacloud_api_key in InvokeAI config (or its env var) to a valid DashScope API key","Restart InvokeAI / reload config after adding the key so the new value is picked up","Verify the key in the Alibaba Cloud DashScope console and confirm the account/region is active","Call provider.is_configured() before generate() to fail early with a clearer message"],"exampleFix":"// before (app config)\n# external_alibabacloud_api_key: (unset)\n// after\nexternal_alibabacloud_api_key: sk-xxxxxxxxxxxxxxxx","handlingStrategy":"validation","validationCode":"provider = AlibabacloudProvider(app_config, ...)\nif not provider.is_configured():\n    raise RuntimeError(\"Set external_alibabacloud_api_key before using the Alibaba provider\")\nresult = provider.generate(request)","typeGuard":"def provider_configured(cfg) -> bool:\n    return bool(getattr(cfg, 'external_alibabacloud_api_key', None))","tryCatchPattern":"try:\n    result = provider.generate(request)\nexcept ExternalProviderRequestError as e:\n    if 'API key is not configured' in str(e):\n        raise ConfigError(\"Set external_alibabacloud_api_key in config/env\") from e\n    raise","preventionTips":["Set and verify provider API keys at startup (fail fast with is_configured())","Keep keys in env/config management, not hardcoded","Reload config after key rotation and smoke-test with a tiny request"],"tags":["configuration","api-key","missing-env-var","dashscope","alibabacloud"],"backgroundTag":"missing-env-var","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}