ATH-MaaS/Pixelle-Video · error · Exception
Max attempts reached, failed to generate image. Last error:
Error message
Max attempts reached, failed to generate image. Last error: {last_error} What it means
generate_image loops through attempts (and models); when every attempt fails, it raises a generic Exception reporting the number of attempts and the last underlying error. This is the terminal wrapper around failures like [51]/[52], network errors, or auth errors.
Source
Thrown at pixelle_video/services/api_services/image_gpt.py:137
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
if __name__ == "__main__":
import sys
import tempfile
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from config import Config
MODELS = ["gpt-image-2"]
save_dir = "code/result/image/test_avail"View on GitHub (pinned to 848b054e4f)
Solutions
- Inspect 'Last error: ...' in the message — fix that root cause first (key, quota, model, connectivity).
- Increase retry attempts or backoff interval if failures are rate-limit related.
- Verify API key validity and remaining quota on the provider dashboard.
- Add a fallback provider/model, or circuit-break and schedule the job for later during outages.
Example fix
// before
url = client.generate_image(prompt) # raises after retries
// after
try:
url = client.generate_image(prompt)
except Exception as e:
logging.error(f"Image generation exhausted retries: {e}")
url = fallback_provider.generate_image(prompt) Defensive patterns
Strategy: fallback
Validate before calling
import os
assert os.environ.get("OPENAI_API_KEY") or os.environ.get("RELAY_API_KEY"), "no image API key configured" Type guard
def can_attempt(client) -> bool:
return bool(getattr(client, "api_key", None)) and bool(getattr(client, "base_url", None)) Try / catch
try:
out = client.generate_image(prompt)
except Exception as e:
logging.error(f"All generation attempts failed: {e}")
out = None # degrade gracefully or use fallback provider
if out is None:
raise Prevention
- Read the wrapped 'Last error' to fix the root cause, not just the symptom
- Configure a fallback model or provider for critical workflows
- Track quota/rate limits and back off before retries are exhausted
- Alert on repeated retry exhaustion — it usually signals an outage or expired key
When it happens
Trigger: All retry attempts of generate_image exhausted: every call to client.images.generate either returned empty data, had no url/b64_json, raised a network/timeout error, or returned a rate-limit error.
Common situations: Sustained provider outage or relay downtime, exhausted rate limits/quota across all retries, invalid API key failing every attempt, network connectivity issues from the host.
Related errors
- OpenAI API 返回数据为空
- 未在响应中找到 url 或 b64_json
- 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/e0860e1cb9567538.
Report an issue: GitHub.