{"record":{"id":"5865244db3e526ee","repo":"assafelovic/gpt-researcher","slug":"modelslab-api-error","errorCode":null,"errorMessage":"ModelsLab API error","messagePattern":"ModelsLab API error","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/llm_provider/image/modelslab_image_generator.py","lineNumber":223,"sourceCode":"        try:\n            import aiohttp\n\n            async with aiohttp.ClientSession() as session:\n                async with session.post(\n                    TEXT2IMG_URL,\n                    json=payload,\n                    timeout=aiohttp.ClientTimeout(total=30),\n                ) as resp:\n                    body = await resp.json()\n        except ImportError:\n            import requests\n\n            body = await asyncio.to_thread(\n                lambda: requests.post(TEXT2IMG_URL, json=payload, timeout=30).json()\n            )\n\n        if body.get(\"status\") == \"error\":\n            raise RuntimeError(body.get(\"messege\", \"ModelsLab API error\"))\n\n        if body.get(\"status\") == \"processing\" and body.get(\"id\"):\n            return await self._poll_for_result(body[\"id\"])\n\n        return body.get(\"output\", [])\n\n    def is_available(self) -> bool:\n        \"\"\"Return True if the API key is configured.\"\"\"\n        return bool(self.api_key)\n\n    @classmethod\n    def from_config(cls, config) -> Optional[\"ModelsLabImageGeneratorProvider\"]:\n        \"\"\"Create a ModelsLabImageGeneratorProvider from a Config object.\"\"\"\n        enabled = getattr(config, \"IMAGE_GENERATION_ENABLED\", False)\n        provider = getattr(config, \"IMAGE_GENERATION_PROVIDER\", \"google\")\n        if not enabled or provider != \"modelslab\":\n            return None\n        model = getattr(config, \"IMAGE_GENERATION_MODEL\", None)","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/llm_provider/image/modelslab_image_generator.py#L205-L241","documentation":"RuntimeError raised right after the initial ModelsLab text2img POST: the API immediately responded with status \"error\" instead of \"processing\" or \"success\". The message is taken from the API's \"messege\" field (misspelled by ModelsLab), defaulting to \"ModelsLab API error\".","triggerScenarios":"generate_image() → _request_images() posts payload to TEXT2IMG_URL; response JSON has body[\"status\"] == \"error\" on the first call, before any polling starts.","commonSituations":"Invalid or exhausted API key, malformed payload (bad model_id, missing prompt), or content-policy rejection at request validation time.","solutions":["Inspect the exception message — it carries the API's stated reason.","Verify the ModelsLab API key and remaining credits.","Check that the payload keys/model name match the current ModelsLab text2img API docs.","If the key was rotated, update the MODELslab credentials in config/env."],"exampleFix":"// before\nout = await generator._request_images(payload)\n\n// after\ntry:\n    out = await generator._request_images(payload)\nexcept RuntimeError as e:\n    raise ImageProviderError(f\"ModelsLab rejected request: {e}\") from e","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    out = await generator._request_images(payload)\nexcept RuntimeError as e:\n    raise ImageProviderError(str(e)) from e","preventionTips":["Verify API key/credits before batch runs.","Validate payload keys against the current ModelsLab text2img schema.","Fail fast on the first request so polling never starts for doomed jobs."],"tags":["modelslab","api-error","image-generation","http-post"],"backgroundTag":"image-generation-api-error","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}