invoke-ai/InvokeAI · error · ExternalProviderRequestError

Alibaba Cloud DashScope API key is not configured

Error message

Alibaba Cloud DashScope API key is not configured

What it means

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.

Source

Thrown at invokeai/app/services/external_generation/providers/alibabacloud.py:51

_TASK_POLL_INTERVAL = 5  # seconds
_TASK_POLL_TIMEOUT = 300  # seconds
_DOWNLOAD_TIMEOUT = 60  # seconds
_DOWNLOAD_MAX_BYTES = 32 * 1024 * 1024  # 32 MiB safety cap on image downloads
_RETRY_STATUS_CODES = {429, 500, 502, 503, 504}
_MAX_RETRIES = 2  # total attempts = 1 + _MAX_RETRIES
_RETRY_BACKOFF_BASE = 2.0  # seconds


class AlibabaCloudProvider(ExternalProvider):
    provider_id = "alibabacloud"

    def is_configured(self) -> bool:
        return bool(self._app_config.external_alibabacloud_api_key)

    def generate(self, request: ExternalGenerationRequest) -> ExternalGenerationResult:
        api_key = self._app_config.external_alibabacloud_api_key
        if not api_key:
            raise ExternalProviderRequestError("Alibaba Cloud DashScope API key is not configured")

        base_url = (self._app_config.external_alibabacloud_base_url or "https://dashscope-intl.aliyuncs.com").rstrip(
            "/"
        )
        model_id = request.model.provider_model_id
        headers = {
            "Content-Type": "application/json",
            "Authorization": f"Bearer {api_key}",
        }
        size = f"{request.width}*{request.height}"

        if model_id in _SYNC_MODELS:
            return self._generate_sync(request, base_url, headers, model_id, size)
        if model_id in _ASYNC_MODELS:
            return self._generate_async(request, base_url, headers, model_id, size)
        raise ExternalProviderRequestError(
            f"Unknown DashScope model_id '{model_id}'. Add it to _SYNC_MODELS or _ASYNC_MODELS in alibabacloud.py."
        )

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Set the external_alibabacloud_api_key in InvokeAI config (or its env var) to a valid DashScope API key
  2. Restart InvokeAI / reload config after adding the key so the new value is picked up
  3. Verify the key in the Alibaba Cloud DashScope console and confirm the account/region is active
  4. Call provider.is_configured() before generate() to fail early with a clearer message

Example fix

// before (app config)
# external_alibabacloud_api_key: (unset)
// after
external_alibabacloud_api_key: sk-xxxxxxxxxxxxxxxx
Defensive patterns

Strategy: validation

Validate before calling

provider = AlibabacloudProvider(app_config, ...)
if not provider.is_configured():
    raise RuntimeError("Set external_alibabacloud_api_key before using the Alibaba provider")
result = provider.generate(request)

Type guard

def provider_configured(cfg) -> bool:
    return bool(getattr(cfg, 'external_alibabacloud_api_key', None))

Try / catch

try:
    result = provider.generate(request)
except ExternalProviderRequestError as e:
    if 'API key is not configured' in str(e):
        raise ConfigError("Set external_alibabacloud_api_key in config/env") from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/2c2832cdb6c7af96. Report an issue: GitHub.