ATH-MaaS/Pixelle-Video · error · RuntimeError
未在响应中找到 url 或 b64_json
Error message
未在响应中找到 url 或 b64_json
What it means
generate_image raises RuntimeError when the API response contains image data whose items expose neither a usable url nor b64_json. The code handles b64_json and url cases; anything else (e.g. revised_prompt only, or unexpected relay formats) falls through to this error.
Source
Thrown at pixelle_video/services/api_services/image_gpt.py:128
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.url
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)
if self.image_processor.download_image(url, file_path):
return file_path
return url
raise RuntimeError("未在响应中找到 url 或 b64_json")
except Exception as e:
last_error = e
msg = str(e)
# Other errors: wait before retry
print(f"Image generation error: {e}. Retrying in 10 seconds.")
time.sleep(10)
break # Break inner loop to retry all models
attempts += 1
raise Exception(f"Max attempts reached, failed to generate image. Last error: {last_error}")
def generate_images(self, prompt, count=4, size="1024x1024", quality="standard", model=None):
"""Generate multiple image URLs by calling Images API 'count' times."""
urls = []
for _ in range(count):
url = self.generate_image(prompt=prompt, size=size, quality=quality, model=model)
urls.append(url)
return urls
View on GitHub (pinned to 848b054e4f)
Solutions
- Log response.data[0] to see what fields the provider actually returns and adapt parsing.
- Set response_format explicitly ('b64_json' is safest with relays) or update the client SDK so attributes match.
- Switch to a relay/endpoint that returns standard OpenAI response shapes.
- Rely on the built-in retry loop (it retries across models) but fix the endpoint for a permanent solution.
Example fix
// before
resp = client.images.generate(model="dall-e-3", prompt=prompt, n=1)
// after
resp = client.images.generate(model="dall-e-3", prompt=prompt, n=1,
response_format="b64_json") Defensive patterns
Strategy: type-guard
Validate before calling
# After the API call, before consuming the image:
img = response.data[0]
if not (getattr(img, 'url', None) or getattr(img, 'b64_json', None)):
print('unexpected response item:', img) Type guard
def extract_image_payload(item):
b64 = getattr(item, "b64_json", None)
if b64:
return ("b64", b64)
url = getattr(item, "url", None)
if url:
return ("url", url)
return None Try / catch
try:
out = client.generate_image(prompt)
except RuntimeError as e:
if "未在响应中找到 url 或 b64_json" in str(e):
out = client.generate_image(prompt, model="dall-e-3") # try another model
else:
raise Prevention
- Set response_format explicitly and match parsing to it
- Log the raw response item when the shape is unexpected
- Keep the OpenAI SDK updated so attribute names match the API
- Test new relay endpoints with a single small request first
When it happens
Trigger: The Images API response data[0] lacks both b64_json and url attributes/values — e.g. a relay returning a non-standard response object, or response_format mismatch (url requested but provider returns only b64, with b64 empty).
Common situations: Third-party OpenAI-compatible relays with non-standard response shapes, requesting response_format='url' from a model that only returns base64, SDK version changes altering response attribute names.
Related errors
- OpenAI API 返回数据为空
- Max attempts reached, failed to generate image. Last error:
- str(e)
- API image generation returned no result: provider={provider}
- DashScope generation failed: {e}
AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30).
Data as JSON: /api/errors/fc9c43cb2b549308.
Report an issue: GitHub.