{"record":{"id":"d135de5f1dff67e7","repo":"xtekky/gpt4free","slug":"n-join-error-get-message-for-error-in-json-l","errorCode":null,"errorMessage":"\\n\".join([error.get(\"message\") for error in json_line.get(\"errors\")]","messagePattern":"\\\\n\"\\.join\\(\\[error\\.get\\(\"message\"\\) for error in json_line\\.get\\(\"errors\"\\)\\]","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/MetaAI.py","lineNumber":142,"sourceCode":"                    \"__relay_internal__pv__WebPixelRatiorelayprovider\": 1,\n                }\n            ),\n            \"server_timestamps\": \"true\",\n            \"doc_id\": \"7783822248314888\",\n        }\n        async with self.session.post(url, headers=headers, data=payload) as response:\n            await raise_for_status(response, \"Fetch response failed\")\n            last_snippet_len = 0\n            fetch_id = None\n            async for line in response.content:\n                if b\"<h1>Something Went Wrong</h1>\" in line:\n                    raise ResponseError(\"Response: Something Went Wrong\")\n                try:\n                    json_line = json.loads(line)\n                except json.JSONDecodeError:\n                    continue\n                if json_line.get(\"errors\"):\n                    raise RuntimeError(\n                        \"\\n\".join(\n                            [error.get(\"message\") for error in json_line.get(\"errors\")]\n                        )\n                    )\n                bot_response_message = (\n                    json_line.get(\"data\", {})\n                    .get(\"node\", {})\n                    .get(\"bot_response_message\", {})\n                )\n                streaming_state = bot_response_message.get(\"streaming_state\")\n                fetch_id = bot_response_message.get(\"fetch_id\") or fetch_id\n                if streaming_state in (\"STREAMING\", \"OVERALL_DONE\"):\n                    imagine_card = bot_response_message.get(\"imagine_card\")\n                    if imagine_card is not None:\n                        imagine_session = imagine_card.get(\"session\")\n                        if imagine_session is not None:\n                            imagine_medias = (\n                                imagine_session.get(\"media_sets\", {})","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/MetaAI.py#L124-L160","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nresp = await meta.prompt('...')  # RuntimeError with GraphQL errors\n\n// after\ntry:\n    resp = await meta.prompt('...')\nexcept RuntimeError as e:\n    logging.warning('MetaAI graphql error: %s', e)\n    await meta.update_cookies()  # refresh and retry once\n    resp = await meta.prompt('...')","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await meta.prompt(msg)\nexcept RuntimeError as e:\n    msg_text = str(e)\n    if 'Something Went Wrong' in msg_text or 'errors' in msg_text.lower():\n        await meta.update_cookies()\n        resp = await meta.prompt(msg)\n    else:\n        raise","preventionTips":["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"],"tags":["metaai","graphql","session-expiry","runtime"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}