xtekky/gpt4free · error · MissingAuthError

Response {response.status_code}: OpenAI Bot detected

Error message

Response {response.status_code}: OpenAI Bot detected

What it means

Sync variant: 403 where response.text matches is_openai ('Unable to load site' / 'challenge-error-text') raises MissingAuthError('OpenAI Bot detected'). The provider's anti-bot gate treated the sync request as an unauthorized bot. Note the sync path does not check the lmarena recaptcha marker — only the async path does.

Source

Thrown at g4f/requests/raise_for_status.py:112

    if response.ok:
        return
    is_html = False
    if message is None:
        is_html = response.headers.get("content-type", "").startswith(
            "text/html"
        ) or response.text.startswith("<!DOCTYPE")
        message = response.text
    if message is None or is_html:
        if response.status_code == 520:
            message = "Unknown error (Cloudflare)"
    if response.status_code in (429, 402):
        raise RateLimitError(f"Response {response.status_code}: {message}")
    if response.status_code == 401:
        raise MissingAuthError(f"Response {response.status_code}: {message}")
    if response.status_code == 403 and is_cloudflare(response.text):
        raise CloudflareError(f"Response {response.status_code}: Cloudflare detected")
    elif response.status_code == 403 and is_openai(response.text):
        raise MissingAuthError(f"Response {response.status_code}: OpenAI Bot detected")
    elif response.status_code == 502:
        raise ResponseStatusError(f"Response {response.status_code}: Bad Gateway")
    elif response.status_code == 504:
        raise RateLimitError(f"Response {response.status_code}: Gateway Timeout ")
    elif response.status_code == 400 and "API key not valid" in message:
        raise MissingAuthError(f"Response {response.status_code}: Invalid API key")
    else:
        raise ResponseStatusError(
            f"Response {response.status_code}: {'HTML content' if is_html else message}"
        )

View on GitHub (pinned to 973504e177)

Solutions

  1. Switch to a different provider.
  2. Update g4f — gate handling changes with provider updates.
  3. Use API-key-based providers instead of scraped web UIs.
  4. Retry from another network.
Defensive patterns

Strategy: fallback

Type guard

from g4f.errors import MissingAuthError
def is_bot_gate(err: BaseException) -> bool:
    return isinstance(err, MissingAuthError) and 'Bot detected' in str(err)

Try / catch

from g4f.errors import MissingAuthError
try:
    resp = g4f.ChatCompletion.create(model, messages)
except MissingAuthError as e:
    if 'Bot detected' in str(e):
        resp = g4f.ChatCompletion.create(fallback_model, messages)
    else:
        raise

Prevention

When it happens

Trigger: Synchronous g4f calls to providers wrapping OpenAI's web chat or similar gated UIs that return their bot-block page with 403.

Common situations: OpenAI web bot detection flags the client; provider session cookies expired; datacenter IP reputation.

Related errors


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