{"record":{"id":"4b8605ee87a4570b","repo":"xtekky/gpt4free","slug":"response-response-status-code-openai-bot-detect","errorCode":null,"errorMessage":"Response {response.status_code}: OpenAI Bot detected","messagePattern":"Response (.+?): OpenAI Bot detected","errorType":"exception","errorClass":"MissingAuthError","httpStatus":403,"severity":"error","filePath":"g4f/requests/raise_for_status.py","lineNumber":112,"sourceCode":"    if response.ok:\n        return\n    is_html = False\n    if message is None:\n        is_html = response.headers.get(\"content-type\", \"\").startswith(\n            \"text/html\"\n        ) or response.text.startswith(\"<!DOCTYPE\")\n        message = response.text\n    if message is None or is_html:\n        if response.status_code == 520:\n            message = \"Unknown error (Cloudflare)\"\n    if response.status_code in (429, 402):\n        raise RateLimitError(f\"Response {response.status_code}: {message}\")\n    if response.status_code == 401:\n        raise MissingAuthError(f\"Response {response.status_code}: {message}\")\n    if response.status_code == 403 and is_cloudflare(response.text):\n        raise CloudflareError(f\"Response {response.status_code}: Cloudflare detected\")\n    elif response.status_code == 403 and is_openai(response.text):\n        raise MissingAuthError(f\"Response {response.status_code}: OpenAI Bot detected\")\n    elif response.status_code == 502:\n        raise ResponseStatusError(f\"Response {response.status_code}: Bad Gateway\")\n    elif response.status_code == 504:\n        raise RateLimitError(f\"Response {response.status_code}: Gateway Timeout \")\n    elif response.status_code == 400 and \"API key not valid\" in message:\n        raise MissingAuthError(f\"Response {response.status_code}: Invalid API key\")\n    else:\n        raise ResponseStatusError(\n            f\"Response {response.status_code}: {'HTML content' if is_html else message}\"\n        )\n","sourceCodeStart":94,"sourceCodeEnd":123,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/requests/raise_for_status.py#L94-L123","documentation":"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.","triggerScenarios":"Synchronous g4f calls to providers wrapping OpenAI's web chat or similar gated UIs that return their bot-block page with 403.","commonSituations":"OpenAI web bot detection flags the client; provider session cookies expired; datacenter IP reputation.","solutions":["Switch to a different provider.","Update g4f — gate handling changes with provider updates.","Use API-key-based providers instead of scraped web UIs.","Retry from another network."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":"from g4f.errors import MissingAuthError\ndef is_bot_gate(err: BaseException) -> bool:\n    return isinstance(err, MissingAuthError) and 'Bot detected' in str(err)","tryCatchPattern":"from g4f.errors import MissingAuthError\ntry:\n    resp = g4f.ChatCompletion.create(model, messages)\nexcept MissingAuthError as e:\n    if 'Bot detected' in str(e):\n        resp = g4f.ChatCompletion.create(fallback_model, messages)\n    else:\n        raise","preventionTips":["Recognize 'Bot detected' as provider-side gating, not your key","Maintain a fallback provider chain","Use official API-key providers for stability","Update g4f regularly"],"tags":["http-403","bot-detection","openai","sync"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}