{"record":{"id":"1890d28a35af4a92","repo":"assafelovic/gpt-researcher","slug":"modelslab-generation-error","errorCode":null,"errorMessage":"ModelsLab generation error","messagePattern":"ModelsLab generation error","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/llm_provider/image/modelslab_image_generator.py","lineNumber":101,"sourceCode":"\n    async def _poll_for_result(self, request_id: str) -> List[str]:\n        \"\"\"Poll the fetch endpoint until generation completes.\"\"\"\n        try:\n            import aiohttp\n\n            for _ in range(MAX_POLL_ATTEMPTS):\n                await asyncio.sleep(POLL_INTERVAL_SECONDS)\n                async with aiohttp.ClientSession() as session:\n                    async with session.post(\n                        f\"{FETCH_BASE_URL}/{request_id}\",\n                        json={\"key\": self.api_key},\n                        timeout=aiohttp.ClientTimeout(total=15),\n                    ) as resp:\n                        body = await 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(\n                                body.get(\"messege\", \"ModelsLab generation error\")\n                            )\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\"))","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/llm_provider/image/modelslab_image_generator.py#L83-L119","documentation":"Raised while polling a ModelsLab text-to-image job (aiohttp path) when the polling endpoint returns a JSON body with status == \"error\". The RuntimeError message is the API's own error text, falling back to \"ModelsLab generation error\" when the body omits it (note the API misspells the field as \"messege\"). It means the generation job itself failed server-side after the initial request was accepted.","triggerScenarios":"Calling generate_image() which posts to the ModelsLab text2img endpoint, receives a processing/id status, then _poll_for_result() loops until the fetched body has status \"error\". Any ModelsLab-side failure (content policy, invalid model, credit exhaustion) triggers it.","commonSituations":"Prompt flagged by ModelsLab content filters, invalid model_id, expired/insufficient subscription credits, or transient API errors surfacing only during the async polling phase.","solutions":["Check the raised message text — it comes from the API's messege field and usually names the real cause (content filter, credits, bad model).","Verify your ModelsLab API key and subscription status in the dashboard.","Retry with a simpler/safer prompt to rule out content-policy rejection.","Confirm the model_id/payload params are valid for ModelsLab's text2img API."],"exampleFix":"// before\nimages = await generator.generate_image(prompt)\n\n// after\ntry:\n    images = await generator.generate_image(prompt)\nexcept RuntimeError as e:\n    logger.error(f\"ModelsLab rejected the job: {e}\")\n    images = []","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    images = await generator.generate_image(prompt)\nexcept RuntimeError as e:\n    logger.error(f\"ModelsLab job failed: {e}\"); images = []","preventionTips":["Log the API's messege text to identify content/credit issues.","Pre-validate prompt length and parameters against ModelsLab docs.","Keep image provider fallbacks configured (e.g. switch to another provider on failure)."],"tags":["modelslab","image-generation","api-error","polling"],"backgroundTag":"image-generation-api-error","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}