assafelovic/gpt-researcher · error · RuntimeError

ModelsLab generation error

Error message

ModelsLab generation error

What it means

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.

Source

Thrown at gpt_researcher/llm_provider/image/modelslab_image_generator.py:101

    async def _poll_for_result(self, request_id: str) -> List[str]:
        """Poll the fetch endpoint until generation completes."""
        try:
            import aiohttp

            for _ in range(MAX_POLL_ATTEMPTS):
                await asyncio.sleep(POLL_INTERVAL_SECONDS)
                async with aiohttp.ClientSession() as session:
                    async with session.post(
                        f"{FETCH_BASE_URL}/{request_id}",
                        json={"key": self.api_key},
                        timeout=aiohttp.ClientTimeout(total=15),
                    ) as resp:
                        body = await 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")
                            )
        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"))

View on GitHub (pinned to 6f998577d5)

Solutions

  1. Check the raised message text — it comes from the API's messege field and usually names the real cause (content filter, credits, bad model).
  2. Verify your ModelsLab API key and subscription status in the dashboard.
  3. Retry with a simpler/safer prompt to rule out content-policy rejection.
  4. Confirm the model_id/payload params are valid for ModelsLab's text2img API.

Example fix

// before
images = await generator.generate_image(prompt)

// after
try:
    images = await generator.generate_image(prompt)
except RuntimeError as e:
    logger.error(f"ModelsLab rejected the job: {e}")
    images = []
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

try:
    images = await generator.generate_image(prompt)
except RuntimeError as e:
    logger.error(f"ModelsLab job failed: {e}"); images = []

Prevention

When it happens

Trigger: 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.

Common situations: Prompt flagged by ModelsLab content filters, invalid model_id, expired/insufficient subscription credits, or transient API errors surfacing only during the async polling phase.

Related errors


AI-assisted analysis of assafelovic/gpt-researcher@6f998577d5 (2026-08-28). Data as JSON: /api/errors/1890d28a35af4a92. Report an issue: GitHub.