xtekky/gpt4free · error · MissingAuthError

{item}

Error message

{item}

What it means

In Pollinations' multi-image generation, when fewer than 2 images have finished and a task returns an Exception, the whole batch is cancelled and the exception is re-raised (as MissingAuthError if its text mentions the provider login_url, otherwise verbatim). The '{item}' message is the underlying failure text — often 'Unexpected content type: ...' from the fetcher or a 401/login-required error.

Source

Thrown at g4f/Provider/Pollinations.py:510

                    responses.add(
                        Exception(
                            f"Unexpected content type: {response.headers.get('content-type')}"
                        )
                    )

            tasks: list[asyncio.Task] = []
            for i in range(int(n)):
                tasks.append(asyncio.create_task(get_image(responses, i, seed)))
            while finished < n or len(responses) > 0:
                while len(responses) > 0:
                    item = responses.pop()
                    if isinstance(item, Exception):
                        if finished < 2:
                            yield Reasoning(status="")
                            for task in tasks:
                                task.cancel()
                            if cls.login_url in str(item):
                                raise MissingAuthError(item)
                            raise item
                        else:
                            finished += 1
                            yield Reasoning(
                                label=f"Image {finished}/{n} failed after {time.time() - start:.2f}s: {item}"
                            )
                    else:
                        finished += 1
                        yield Reasoning(
                            label=f"Image {finished}/{n} generated in {time.time() - start:.2f}s"
                        )
                        yield item
                await asyncio.sleep(1)
            yield Reasoning(status="")
            await asyncio.gather(*tasks)

    @classmethod
    async def _generate_text(

View on GitHub (pinned to 973504e177)

Solutions

  1. If the message contains a login/auth URL, obtain a Pollinations token/API key and configure auth instead of anonymous access.
  2. Switch to an openly available model (e.g. 'flux') and fewer images per request.
  3. Retry once — single-image transient failures often clear.
  4. Update g4f; Pollinations tier rules change frequently.

Example fix

# before
img = await Pollinations.create_async_generator(model='gptimage', prompt=p, n=4)

# after
img = await Pollinations.create_async_generator(model='flux', prompt=p)  # anonymous-friendly model, n=1
Defensive patterns

Strategy: try-catch

Validate before calling

# anonymous-safe request shape: open model, small n
from g4f.Provider.Pollinations import Pollinations

def pollinations_request_safe(model: str, n: int) -> bool:
    return model in Pollinations.get_models() and model == 'flux' and n <= 2

Type guard

def is_missing_auth(exc: Exception) -> bool:
    """True when the failure is auth, not a transient fetch error."""
    from g4f.errors import MissingAuthError
    return isinstance(exc, MissingAuthError)

Try / catch

from g4f.errors import MissingAuthError
try:
    imgs = [c async for c in Pollinations.create_async_generator(model, prompt, n=n)]
except MissingAuthError:
    imgs = [c async for c in Pollinations.create_async_generator('flux', prompt)]  # fallback model
except Exception:
    await asyncio.sleep(3)
    imgs = [c async for c in Pollinations.create_async_generator(model, prompt)]  # one retry

Prevention

When it happens

Trigger: Requesting n>=1 images where the first or second concurrent fetch fails (non-image content type returned, auth required for the model, or a fetch exception); because finished < 2, partial success is not tolerated and the error propagates.

Common situations: Using premium/queued Pollinations models that now require a token (item contains the login URL); upstream returning an error page (content-type text/html) instead of image bytes; requesting more images than the anonymous tier allows; transient seed-specific failures.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/653f9fdebe16f1cd. Report an issue: GitHub.