xtekky/gpt4free · error · MissingAuthError
Response status: {response.status}
Error message
Response status: {response.status} What it means
OpenaiChat fetches /backend-api/sentinel/chat-requirements before chatting; if that probe returns HTTP 401 or 403, MissingAuthError with the status is raised instead of proceeding. The chat-requirements endpoint acts as an early auth/Cloudflare gate, so 401/403 means the session credentials were rejected before the conversation even started.
Source
Thrown at g4f/Provider/needs_auth/OpenaiChat.py:591
prepare_url, json=data, headers=cls._headers
) as response:
await raise_for_status(response)
conduit_token = (await response.json())["conduit_token"]
async with session.post(
f"{cls.url}/backend-anon/sentinel/chat-requirements"
if cls._api_key is None
else f"{cls.url}/backend-api/sentinel/chat-requirements",
json={
"p": None
if not getattr(auth_result, "proof_token", None)
else get_requirements_token(
getattr(auth_result, "proof_token", None)
)
},
headers=cls._headers,
) as response:
if response.status in (401, 403):
raise MissingAuthError(f"Response status: {response.status}")
else:
cls._update_request_args(auth_result, session)
await raise_for_status(response)
chat_requirements = await response.json()
need_turnstile = chat_requirements.get("turnstile", {}).get(
"required", False
)
need_arkose = chat_requirements.get("arkose", {}).get(
"required", False
)
chat_token = chat_requirements.get("token")
# if need_arkose and cls.request_config.arkose_token is None:
# await get_request_config(proxy)
# cls._create_request_args(auth_result.cookies, auth_result.headers)
# cls._set_api_key(auth_result.access_token)
# if auth_result.arkose_token is None:
# raise MissingAuthError("No arkose token found in .har file")View on GitHub (pinned to 973504e177)
Solutions
- Refresh credentials: re-login via nodriver or re-export a HAR file so tokens/cookies are current
- Use a different IP or residential proxy if 403 (Cloudflare) persists
- Update g4f for the current sentinel/chat-requirements handshake (proof token format changes)
- If using an API key path, verify the key is valid and correctly passed
Example fix
// before resp = await client.chat.completions.create(model=..., messages=msgs) # MissingAuthError: Response status: 403 // after await OpenaiChat.nodriver_auth(proxy=proxy) # or replace HAR file resp = await client.chat.completions.create(model=..., messages=msgs)
Defensive patterns
Strategy: retry
Try / catch
from g4f.errors import MissingAuthError
try:
resp = await client.chat.completions.create(model=..., messages=msgs)
except MissingAuthError as e:
if '401' in str(e):
await OpenaiChat.nodriver_auth() # token invalid -> re-login
elif '403' in str(e):
rotate_proxy() # Cloudflare block -> change IP
resp = await client.chat.completions.create(model=..., messages=msgs) Prevention
- Distinguish 401 (re-auth) from 403 (IP/Cloudflare) in handling
- Use residential proxies for automated access
- Keep g4f current for sentinel handshake changes
When it happens
Trigger: POSTing {'p': ...} to the sentinel chat-requirements endpoint with cls._headers; the reverse proxy answers 401 (bad/expired access token or API key) or 403 (Cloudflare/WAF block, banned session).
Common situations: Expired access token or API key; cookies cleared by Cloudflare; IP banned or flagged (datacenter IPs); proof-token/turnstile requirements unmet after a backend change; outdated g4f sentinel payload.
Related errors
- Invalid secrets
- Failed to obtain Turnstile token for DeepInfra request.
- Access token is not valid
- Missing access token
- Response {response.status}: Cloudflare detected
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/dda7e343c3faed7d.
Report an issue: GitHub.