ATH-MaaS/Pixelle-Video · error · RuntimeError

Image edit failed: {response.code}, {response.message}, stat

Error message

Image edit failed: {response.code}, {response.message}, status={response.status_code}

What it means

edit_image calls the DashScope image edit API and raises RuntimeError when the response does not contain the expected image result (no 'results' key / empty results). The response.code, response.message, and response.status_code are embedded in the message so the developer can see exactly what the API rejected (auth, quota, bad params, content policy).

Source

Thrown at pixelle_video/services/api_services/image_dashscope.py:186

            if response.status_code == 200:
                results = self._extract_image_urls(getattr(response, "output", None))
                if not results:
                    raise RuntimeError(f"DashScope image edit returned no image URLs. output={getattr(response, 'output', None)}")

                # Check if we should download
                if save_dir:
                    os.makedirs(save_dir, exist_ok=True)
                    local_files = []
                    for i, url in enumerate(results):
                        file_name = f"ds_{session_id if session_id else 'nosess'}_{int(time.time())}_{i}_{uuid.uuid4().hex[:6]}.png"
                        file_path = os.path.join(save_dir, file_name)
                        if self.image_processor.download_image(url, file_path):
                            local_files.append(file_path)
                    return local_files

                return results
            else:
                raise RuntimeError(f"Image edit failed: {response.code}, {response.message}, status={response.status_code}")
        except Exception as e:
            logging.error(f"Error in edit_image: {e}")
            raise


if __name__ == "__main__":
    import sys
    sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    from config import Config

    print("=== DashScope 图片生成可用性测试 ===")
    MODELS=["wan2.6-t2i", "wan2.7-image", "wan2.7-image-pro"]
    save_dir = "code/result/image/test_avail"
    api_key = Config.DASHSCOPE_API_KEY
    base_url = Config.DASHSCOPE_BASE_URL
    if not api_key:
        print("✗ DASHSCOPE_API_KEY 未设置,跳过")
        sys.exit(1)

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Read response.code/response.message in the error text and fix the indicated cause (invalid key, quota, invalid parameter).
  2. Verify DASHSCOPE_API_KEY is set, valid, and has image-edit quota enabled.
  3. Check that the input image and prompt comply with the model's requirements (format, size, content policy).
  4. Retry with backoff if the code indicates throttling (e.g. 'Throttling' / 429).

Example fix

// before
result = client.edit_image(image_path, prompt)

// after
try:
    result = client.edit_image(image_path, prompt)
except RuntimeError as e:
    logging.error(f"DashScope edit rejected: {e}")
    if 'Throttling' in str(e):
        time.sleep(30)
        result = client.edit_image(image_path, prompt)
    else:
        raise
Defensive patterns

Strategy: try-catch

Validate before calling

import os
assert os.environ.get("DASHSCOPE_API_KEY"), "DASHSCOPE_API_KEY not set"
assert os.path.exists(image_path), "input image missing"

Type guard

def has_edit_result(resp) -> bool:
    return bool(resp) and bool(getattr(resp, "results", None))

Try / catch

try:
    out = client.edit_image(image_path, prompt)
except RuntimeError as e:
    if 'Throttling' in str(e) or '429' in str(e):
        # backoff and retry
        time.sleep(30)
        out = client.edit_image(image_path, prompt)
    else:
        logging.error(f"Image edit rejected: {e}")
        raise

Prevention

When it happens

Trigger: Calling edit_image when the DashScope image-edit HTTP response is not successful in the expected shape: response.code is an error code (e.g. 'InvalidApiKey', 'Throttling', 'InvalidParameter'), or results is missing/empty despite an HTTP 200.

Common situations: Expired or wrong DASHSCOPE_API_KEY, exceeded image-edit quota/rate limits, unsupported prompt or image violating content policy, wrong model name or malformed image input, DashScope service-side errors returned inside a 200 envelope.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/d282abb6f9142c22. Report an issue: GitHub.