{"record":{"id":"d16b01d4306f5e27","repo":"assafelovic/gpt-researcher","slug":"modelslab-image-generation-timed-out-after-polling","errorCode":null,"errorMessage":"ModelsLab image generation timed out after polling.","messagePattern":"ModelsLab image generation timed out after polling\\.","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/llm_provider/image/modelslab_image_generator.py","lineNumber":121,"sourceCode":"                            )\n        except ImportError:\n            import requests\n\n            for _ in range(MAX_POLL_ATTEMPTS):\n                await asyncio.sleep(POLL_INTERVAL_SECONDS)\n                resp = await asyncio.to_thread(\n                    requests.post,\n                    f\"{FETCH_BASE_URL}/{request_id}\",\n                    json={\"key\": self.api_key},\n                    timeout=15,\n                )\n                body = resp.json()\n                if body.get(\"status\") == \"success\" and body.get(\"output\"):\n                    return body[\"output\"]\n                if body.get(\"status\") == \"error\":\n                    raise RuntimeError(body.get(\"messege\", \"ModelsLab generation error\"))\n\n        raise TimeoutError(\"ModelsLab image generation timed out after polling.\")\n\n    async def generate_image(\n        self,\n        prompt: str,\n        context: str = \"\",\n        research_id: str = \"\",\n        aspect_ratio: str = \"1:1\",\n        num_images: int = 1,\n        style: str = \"dark\",\n    ) -> List[Dict[str, Any]]:\n        \"\"\"Generate images using ModelsLab's text-to-image API.\n\n        Args:\n            prompt: The image generation prompt.\n            context: Additional context (appended to prompt).\n            research_id: Research ID for organizing output directories.\n            aspect_ratio: Ignored (ModelsLab uses width/height).\n            num_images: Number of images to generate (1–4).","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/llm_provider/image/modelslab_image_generator.py#L103-L139","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nimages = await generator.generate_image(prompt)\n\n// after\nfor attempt in range(3):\n    try:\n        images = await generator.generate_image(prompt)\n        break\n    except TimeoutError:\n        images = []\n        await asyncio.sleep(5)","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"for attempt in range(3):\n    try:\n        images = await generator.generate_image(prompt); break\n    except TimeoutError:\n        await asyncio.sleep(5)\nelse:\n    images = []","preventionTips":["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."],"tags":["modelslab","timeout","polling","image-generation"],"backgroundTag":"api-polling-timeout","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}