{"record":{"id":"64eab2faef905adb","repo":"xtekky/gpt4free","slug":"the-har-file-is-not-valid","errorCode":null,"errorMessage":"The .har file is not valid","messagePattern":"The \\.har file is not valid","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/openai/har_file.py","lineNumber":144,"sourceCode":"        arkBody={\n            p[\"name\"]: unquote(p[\"value\"])\n            for p in entry[\"request\"][\"postData\"][\"params\"]\n            if p[\"name\"] not in [\"rnd\"]\n        },\n        arkCookies={c[\"name\"]: c[\"value\"] for c in entry[\"request\"][\"cookies\"]},\n        userAgent=\"\",\n    )\n    tmpArk.userAgent = tmpArk.arkHeader.get(\"user-agent\", \"\")\n    bda = tmpArk.arkBody[\"bda\"]\n    bw = tmpArk.arkHeader[\"x-ark-esync-value\"]\n    tmpArk.arkBx = decrypt(bda, tmpArk.userAgent + bw)\n    return tmpArk\n\n\ndef genArkReq(chatArk: arkReq) -> arkReq:\n    tmpArk: arkReq = deepcopy(chatArk)\n    if tmpArk is None or not tmpArk.arkBody or not tmpArk.arkHeader:\n        raise RuntimeError(\"The .har file is not valid\")\n    bda, bw = getBDA(tmpArk)\n\n    tmpArk.arkBody[\"bda\"] = base64.b64encode(bda.encode()).decode()\n    tmpArk.arkBody[\"rnd\"] = str(random.random())\n    tmpArk.arkHeader[\"x-ark-esync-value\"] = bw\n    return tmpArk\n\n\nasync def sendRequest(tmpArk: arkReq, proxy: str = None) -> str:\n    async with StreamSession(\n        headers=tmpArk.arkHeader, cookies=tmpArk.arkCookies, proxies={\"https\": proxy}\n    ) as session:\n        async with session.post(tmpArk.arkURL, data=tmpArk.arkBody) as response:\n            data = await response.json()\n            arkose = data.get(\"token\")\n    if \"sup=1|rid=\" not in arkose:\n        return RuntimeError(\"No valid arkose token generated\")\n    return arkose","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/openai/har_file.py#L126-L162","documentation":"Raised by genArkReq() when the stored Arkose request (chatArk copied from the HAR capture) is None or lacks its arkBody/arkHeader payloads. The HAR entries are searched for the outbound request to the Arkose (x-ark-esync) endpoint; if that request was never captured, the reconstructed object is empty and regenerating the bda token is impossible, so RuntimeError('The .har file is not valid') fires.","triggerScenarios":"The chosen .har file parses as JSON and contains ChatGPT requests, but the Arkose-token request with x-ark-esync-value headers/body is missing, leaving arkose_request incomplete.","commonSituations":"HAR captured before any message was sent (Arkose request only fires on chat requests); HAR captured with DevTools filtering that excluded the ark request; OpenAI frontend changed which endpoint carries the bda payload; HAR from a session where Arkose was not challenged.","solutions":["Re-capture the HAR while actually sending a chat message so the Arkose request is included","Disable network filters in DevTools during capture so all requests are recorded","Try the other .har files present — get_har_files() sorts by mtime and readHAR iterates them","Update g4f — Arkose request detection patterns are adjusted as OpenAI changes them"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import json\n\ndef har_has_arkose(path: str) -> bool:\n    with open(path, 'rb') as f:\n        try:\n            har = json.load(f)\n        except json.JSONDecodeError:\n            return False\n    return any('x-ark-esync-value' in e.get('request', {}).get('headers', {})\n               for e in har.get('log', {}).get('entries', []))","typeGuard":null,"tryCatchPattern":"try:\n    token = await sendRequest(genArkReq(ark_req), proxy)\nexcept RuntimeError as e:\n    if 'not valid' in str(e):\n        recapture_har_with_chat_message()\n        raise","preventionTips":["Always capture the HAR while sending an actual chat message so Arkose requests are recorded","Disable network filters during capture","Keep several recent HARs — readHAR scans all of them by mtime"],"tags":["openai","har-file","arkose","auth","bot-detection"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}