xtekky/gpt4free · error · RuntimeError
\n".join([error.get("message") for error in json_line.get("e
Error message
\n".join([error.get("message") for error in json_line.get("errors")] What it means
While parsing MetaAI's newline-delimited GraphQL stream, a JSON line contained a top-level 'errors' array. g4f joins every error's 'message' field with newlines into a RuntimeError, forwarding the GraphQL error details (as written, the f-string is missing braces so the literal expression is shown — the effective message is the joined error text).
Source
Thrown at g4f/Provider/needs_auth/MetaAI.py:142
"__relay_internal__pv__WebPixelRatiorelayprovider": 1,
}
),
"server_timestamps": "true",
"doc_id": "7783822248314888",
}
async with self.session.post(url, headers=headers, data=payload) as response:
await raise_for_status(response, "Fetch response failed")
last_snippet_len = 0
fetch_id = None
async for line in response.content:
if b"<h1>Something Went Wrong</h1>" in line:
raise ResponseError("Response: Something Went Wrong")
try:
json_line = json.loads(line)
except json.JSONDecodeError:
continue
if json_line.get("errors"):
raise RuntimeError(
"\n".join(
[error.get("message") for error in json_line.get("errors")]
)
)
bot_response_message = (
json_line.get("data", {})
.get("node", {})
.get("bot_response_message", {})
)
streaming_state = bot_response_message.get("streaming_state")
fetch_id = bot_response_message.get("fetch_id") or fetch_id
if streaming_state in ("STREAMING", "OVERALL_DONE"):
imagine_card = bot_response_message.get("imagine_card")
if imagine_card is not None:
imagine_session = imagine_card.get("session")
if imagine_session is not None:
imagine_medias = (
imagine_session.get("media_sets", {})View on GitHub (pinned to 973504e177)
Solutions
- Read the joined message(s): they name the exact GraphQL failure (auth vs. schema vs. policy) and dictate the next step
- Refresh the session: recreate MetaAI / await update_cookies() to renew tokens and cookies
- Use a residential proxy or different IP if messages mention access/permission
- Update g4f so the current doc_id and payload are used
Example fix
// before
resp = await meta.prompt('...') # RuntimeError with GraphQL errors
// after
try:
resp = await meta.prompt('...')
except RuntimeError as e:
logging.warning('MetaAI graphql error: %s', e)
await meta.update_cookies() # refresh and retry once
resp = await meta.prompt('...') Defensive patterns
Strategy: try-catch
Try / catch
try:
resp = await meta.prompt(msg)
except RuntimeError as e:
msg_text = str(e)
if 'Something Went Wrong' in msg_text or 'errors' in msg_text.lower():
await meta.update_cookies()
resp = await meta.prompt(msg)
else:
raise Prevention
- Refresh LSD/DTSG tokens before heavy batches
- Read the GraphQL error messages — they distinguish auth vs. policy failures
- Keep g4f updated for doc_id changes
When it happens
Trigger: Any streamed line from the Meta AI completion endpoint with json_line['errors'] non-empty — e.g. invalid session tokens, expired access attempt, blocked prompt, or GraphQL schema/doc_id validation failures.
Common situations: Stale DTSG/LSD tokens after long-lived sessions; flagged accounts or bot-suspected IPs; prompts that trip Meta moderation; g4f version lagging a doc_id change making the query invalid.
Related errors
- Response: Something Went Wrong
- {r.status} {response body text}
- No audio chunks
- Install or update "curl_cffi" package | pip install -U curl_
- LMArena: {json.loads(line[3:])}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/d135de5f1dff67e7.
Report an issue: GitHub.