xtekky/gpt4free · error · RuntimeError
The .har file is not valid
Error message
The .har file is not valid
What it means
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.
Source
Thrown at g4f/Provider/openai/har_file.py:144
arkBody={
p["name"]: unquote(p["value"])
for p in entry["request"]["postData"]["params"]
if p["name"] not in ["rnd"]
},
arkCookies={c["name"]: c["value"] for c in entry["request"]["cookies"]},
userAgent="",
)
tmpArk.userAgent = tmpArk.arkHeader.get("user-agent", "")
bda = tmpArk.arkBody["bda"]
bw = tmpArk.arkHeader["x-ark-esync-value"]
tmpArk.arkBx = decrypt(bda, tmpArk.userAgent + bw)
return tmpArk
def genArkReq(chatArk: arkReq) -> arkReq:
tmpArk: arkReq = deepcopy(chatArk)
if tmpArk is None or not tmpArk.arkBody or not tmpArk.arkHeader:
raise RuntimeError("The .har file is not valid")
bda, bw = getBDA(tmpArk)
tmpArk.arkBody["bda"] = base64.b64encode(bda.encode()).decode()
tmpArk.arkBody["rnd"] = str(random.random())
tmpArk.arkHeader["x-ark-esync-value"] = bw
return tmpArk
async def sendRequest(tmpArk: arkReq, proxy: str = None) -> str:
async with StreamSession(
headers=tmpArk.arkHeader, cookies=tmpArk.arkCookies, proxies={"https": proxy}
) as session:
async with session.post(tmpArk.arkURL, data=tmpArk.arkBody) as response:
data = await response.json()
arkose = data.get("token")
if "sup=1|rid=" not in arkose:
return RuntimeError("No valid arkose token generated")
return arkoseView on GitHub (pinned to 973504e177)
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
Defensive patterns
Strategy: validation
Validate before calling
import json
def har_has_arkose(path: str) -> bool:
with open(path, 'rb') as f:
try:
har = json.load(f)
except json.JSONDecodeError:
return False
return any('x-ark-esync-value' in e.get('request', {}).get('headers', {})
for e in har.get('log', {}).get('entries', [])) Try / catch
try:
token = await sendRequest(genArkReq(ark_req), proxy)
except RuntimeError as e:
if 'not valid' in str(e):
recapture_har_with_chat_message()
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No proof_token found in .har files
- har_and_cookies dir is not readable
- No .har file found
- Response {response.status}: OpenAI Bot detected
- Response {response.status_code}: OpenAI Bot detected
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/64eab2faef905adb.
Report an issue: GitHub.