{"record":{"id":"11e20d730fbcac43","repo":"invoke-ai/InvokeAI","slug":"dashscope-response-missing-choices-data","errorCode":null,"errorMessage":"DashScope response missing choices: {data}","messagePattern":"DashScope response missing choices: (.+?)","errorType":"exception","errorClass":"ExternalProviderRequestError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/external_generation/providers/alibabacloud.py","lineNumber":225,"sourceCode":"                raise ExternalProviderRequestError(f\"DashScope task {task_id} failed: {message}\")\n\n            self._logger.debug(\"DashScope task %s status: %s (%.0fs elapsed)\", task_id, status, elapsed)\n            time.sleep(_TASK_POLL_INTERVAL)\n\n    def _parse_sync_response(\n        self,\n        data: dict[str, object],\n        request: ExternalGenerationRequest,\n        request_id: str | None,\n    ) -> ExternalGenerationResult:\n        \"\"\"Parse the synchronous multimodal-generation response.\"\"\"\n        output = data.get(\"output\")\n        if not isinstance(output, dict):\n            raise ExternalProviderRequestError(f\"DashScope response missing output: {data}\")\n\n        choices = output.get(\"choices\")\n        if not isinstance(choices, list):\n            raise ExternalProviderRequestError(f\"DashScope response missing choices: {data}\")\n\n        images: list[ExternalGeneratedImage] = []\n        for choice in choices:\n            if not isinstance(choice, dict):\n                continue\n            message = choice.get(\"message\")\n            if not isinstance(message, dict):\n                continue\n            content = message.get(\"content\")\n            if not isinstance(content, list):\n                continue\n            for part in content:\n                if not isinstance(part, dict):\n                    continue\n                image_url = part.get(\"image\")\n                if isinstance(image_url, str) and image_url:\n                    pil_image = self._download_image(image_url)\n                    images.append(ExternalGeneratedImage(image=pil_image, seed=request.seed))","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/external_generation/providers/alibabacloud.py#L207-L243","documentation":"After locating the 'output' object, _parse_sync_response expects output.choices to be a list (OpenAI-style chat choices) from the multimodal-generation endpoint. If 'choices' is missing or not a list, the provider raises ExternalProviderRequestError with the raw data, since it cannot extract any generated image content.","triggerScenarios":"DashScope returns 200 with output present but no 'choices' array — e.g. an output containing only task/error fields, a moderation/rejection payload, or a response shape from the wrong endpoint (async image-generation returns output.results instead of output.choices).","commonSituations":"Routing a model that only supports the async image-generation endpoint into _SYNC_MODELS; content-policy rejection returning output without choices; custom base_url serving a different API revision whose output omits choices.","solutions":["Check the embedded response data for a rejection/error message from DashScope (content moderation often returns an output without choices)","Confirm the model_id belongs in _SYNC_MODELS; move it to _ASYNC_MODELS if it uses the flat-prompt image-generation endpoint","Verify the endpoint path /api/v1/services/aigc/multimodal-generation/generation matches your base_url and DashScope API version","Retry the request — transient moderation or backend issues can yield empty outputs","Check InvokeAI/DashScope docs for API schema changes"],"exampleFix":"# before\nif model_id in _SYNC_MODELS:\n    return self._generate_sync(...)\n# after\nif model_id in _SYNC_MODELS:\n    return self._generate_sync(...)\n# if you see 'missing choices', the model likely uses the async API:\n# move it from _SYNC_MODELS to _ASYNC_MODELS","handlingStrategy":"validation","validationCode":"if model.provider_model_id not in {\"qwen-image-2.0-pro\",\"qwen-image-2.0\",\"qwen-image-max\",\"wan2.6-t2i\",\"qwen-image-edit-max\"}:\n    raise ValueError(f\"{model.provider_model_id} is not a known sync DashScope model\")","typeGuard":"def has_choices(output: dict) -> bool:\n    return isinstance(output.get(\"choices\"), list) and len(output[\"choices\"]) > 0","tryCatchPattern":"try:\n    result = provider.generate(request)\nexcept ExternalProviderRequestError as e:\n    if \"missing choices\" in str(e):\n        log.error(\"DashScope output lacked choices (possible moderation or wrong endpoint): %s\", e)\n    raise","preventionTips":["Only route models verified to use the multimodal-generation endpoint into _SYNC_MODELS","Check embedded response text for content-policy messages and adjust prompts","Pin the DashScope API version/base_url","Validate model IDs before submitting generation jobs"],"tags":["dashscope","api-response","schema-mismatch","content-moderation"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}