ATH-MaaS/Pixelle-Video · error · RuntimeError
OpenAI API 返回数据为空
Error message
OpenAI API 返回数据为空
What it means
generate_image calls the OpenAI Images API (via client.images.generate with extra_body support) and raises RuntimeError when the SDK returns None or an empty data list. This means the relay/proxy or OpenAI returned a success-shaped response with no image payloads.
Source
Thrown at pixelle_video/services/api_services/image_gpt.py:101
if image_urls and isinstance(image_urls, list) and len(image_urls) > 0:
# 中转站通常支持通过 extra_body 传递 image_url 或 ref_image
# 这里我们将第一张图作为参考图
ref_images = [self._encode_image_to_base64(image_urls[i]) for i in range(min(len(image_urls), 6))]
extra_body = {"image_url": ref_images}
while attempts < self.max_attempts:
try:
response = self.client.images.generate(
model=model,
prompt=prompt,
size=size,
quality=quality,
n=1,
extra_body=extra_body
)
if not response or not response.data:
raise RuntimeError("OpenAI API 返回数据为空")
img_data = response.data[0]
file_path = None
# 1. 处理 Base64 格式 (中转站常用)
if hasattr(img_data, 'b64_json') and img_data.b64_json:
if save_dir:
os.makedirs(save_dir, exist_ok=True)
file_name = f"gpt_{int(time.time())}_{uuid.uuid4().hex[:6]}.png"
file_path = os.path.join(save_dir, file_name)
with open(file_path, "wb") as f:
f.write(base64.b64decode(img_data.b64_json))
return file_path
return img_data.b64_json
# 2. 处理 URL 格式
elif hasattr(img_data, 'url') and img_data.url:
url = img_data.urlView on GitHub (pinned to 848b054e4f)
Solutions
- Retry the request — this library already retries per model; transient relay failures usually resolve on retry.
- Verify base_url points to a working endpoint and the API key is valid for that endpoint.
- Try a different supported model (e.g. 'gpt-image-1' vs 'dall-e-3') via the model argument.
- Check the relay provider's status/logs; switch to the official API to rule out relay issues.
Example fix
// before
url = client.generate_image(prompt, model="dall-e-3")
// after
from tenacity import retry, stop_after_attempt
@retry(stop=stop_after_attempt(3), wait=wait_fixed(10))
def gen():
return client.generate_image(prompt, model="gpt-image-1") Defensive patterns
Strategy: retry
Validate before calling
assert api_key and api_key.startswith(("sk-",)), "OpenAI/relay key missing"
assert base_url, "base_url for OpenAI-compatible endpoint not configured" Type guard
def has_image_data(resp) -> bool:
return resp is not None and bool(getattr(resp, "data", None)) Try / catch
try:
out = client.generate_image(prompt)
except RuntimeError as e:
if "返回数据为空" in str(e):
time.sleep(10)
out = client.generate_image(prompt) # transient relay failure
else:
raise Prevention
- Prefer response_format='b64_json' when using relays
- Retry empty responses — they are usually transient relay issues
- Monitor relay provider status; fall back to the official API when needed
- Pin a model name known to work with your endpoint
When it happens
Trigger: client.images.generate(...) returns None, or response.data is an empty list — typically from a third-party relay/中转站 returning 200 with an empty body, or the model returning no images.
Common situations: Using an unofficial OpenAI-compatible relay that silently fails, base_url pointing to a proxy with intermittent empty responses, model name not supported by the endpoint, content policy rejection returning empty data instead of an error.
Related errors
- API image generation returned no result: provider={provider}
- DashScope image generation returned no image URLs. output={g
- 未在响应中找到 url 或 b64_json
- Max attempts reached, failed to generate image. Last error:
- str(e)
AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30).
Data as JSON: /api/errors/9b127093f42ba013.
Report an issue: GitHub.