assafelovic/gpt-researcher · error · TimeoutError
ModelsLab image generation timed out after polling.
Error message
ModelsLab image generation timed out after polling.
What it means
TimeoutError raised after _poll_for_result exhausts MAX_POLL_ATTEMPTS without the ModelsLab job reaching status "success" with output. The job stays in "processing" (or returns transient statuses) for the entire polling window, so the code gives up.
Solutions
- Retry the generation — transient ModelsLab congestion is the most common cause.
- Reduce image count / steps / resolution in the payload to shorten generation time.
- Raise MAX_POLL_ATTEMPTS or the per-request timeout if you control the module.
- Check ModelsLab status page / your job id in their dashboard to see if the job eventually finished.
Example fix
// before
images = await generator.generate_image(prompt)
// after
for attempt in range(3):
try:
images = await generator.generate_image(prompt)
break
except TimeoutError:
images = []
await asyncio.sleep(5) Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
null
Try / catch
for attempt in range(3):
try:
images = await generator.generate_image(prompt); break
except TimeoutError:
await asyncio.sleep(5)
else:
images = [] Prevention
- Reduce image count/steps to shorten generation time.
- Retry with backoff — congestion is often transient.
- Raise polling limits if your workload routinely generates large batches.
When it happens
Trigger: Initial text2img POST returns status "processing" with an id; every subsequent poll for MAX_POLL_ATTEMPTS iterations fails to return success/output; the loop exits and raises TimeoutError.
Common situations: Heavy prompt/large batch queueing long generation times, slow ModelsLab service, network latency stretching poll round-trips, or an id from a job that died silently server-side.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
AI-assisted analysis of assafelovic/gpt-researcher@6f998577d5 (2026-08-28).
Data as JSON: /api/errors/d16b01d4306f5e27.
Report an issue: GitHub.
Appendix: source
Thrown at gpt_researcher/llm_provider/image/modelslab_image_generator.py:121
)
except ImportError:
import requests
for _ in range(MAX_POLL_ATTEMPTS):
await asyncio.sleep(POLL_INTERVAL_SECONDS)
resp = await asyncio.to_thread(
requests.post,
f"{FETCH_BASE_URL}/{request_id}",
json={"key": self.api_key},
timeout=15,
)
body = resp.json()
if body.get("status") == "success" and body.get("output"):
return body["output"]
if body.get("status") == "error":
raise RuntimeError(body.get("messege", "ModelsLab generation error"))
raise TimeoutError("ModelsLab image generation timed out after polling.")
async def generate_image(
self,
prompt: str,
context: str = "",
research_id: str = "",
aspect_ratio: str = "1:1",
num_images: int = 1,
style: str = "dark",
) -> List[Dict[str, Any]]:
"""Generate images using ModelsLab's text-to-image API.
Args:
prompt: The image generation prompt.
context: Additional context (appended to prompt).
research_id: Research ID for organizing output directories.
aspect_ratio: Ignored (ModelsLab uses width/height).
num_images: Number of images to generate (1–4).View on GitHub (pinned to 6f998577d5)