{"record":{"id":"471a4f24d54824f5","repo":"xtekky/gpt4free","slug":"response-response-status-message","errorCode":null,"errorMessage":"Response {response.status}: {message}","messagePattern":"Response (.+?): (.+?)","errorType":"exception","errorClass":"ResponseStatusError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/hf_space/raise_for_status.py","lineNumber":29,"sourceCode":"    response: Union[StreamResponse, ClientResponse], message: str = None\n):\n    if response.ok:\n        return\n    content_type = response.headers.get(\"content-type\", \"\")\n    if content_type.startswith(\"application/json\"):\n        try:\n            data = await response.json()\n            message = data.get(\"error\", data.get(\"message\", message))\n            message = message.split(\" <a \")[0]\n        except Exception:\n            pass\n    if not message:\n        text = await response.text()\n        is_html = response.headers.get(\"content-type\", \"\").startswith(\n            \"text/html\"\n        ) or text.startswith(\"<!DOCTYPE\")\n        message = \"HTML content\" if is_html else text\n    raise ResponseStatusError(f\"Response {response.status}: {message}\")\n","sourceCodeStart":11,"sourceCodeEnd":30,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/hf_space/raise_for_status.py#L11-L30","documentation":"ResponseStatusError raised by the shared raise_for_status helper used by all HF Space providers: the HTTP response status was not ok (<200 or >=300). The helper extracts the best message it can — JSON 'error'/'message' field (with HF's ' <a ...>' suffix stripped), else the body text, collapsed to 'HTML content' when the body is HTML — and raises 'Response {status}: {message}'.","triggerScenarios":"HF Space returning 404 (Space paused/deleted/renamed), 401/403 (auth required, invalid/expired zerogpu token or cookies, Cloudflare block of the impersonated client), 429 (rate limited), 500/503 (Space crashed or starting up), or HTML login/redirect pages served instead of the API.","commonSituations":"Using a Space that was paused or rebuilt at a different URL; ZeroGPU tokens expiring between join and data calls; anonymous access blocked after an HF policy change; Cloudflare challenges hitting the StreamSession despite impersonate='chrome'.","solutions":["Map the status: 404 → Space moved/paused (check the space URL manually); 401/403 → provide valid HF cookies / refresh the zerogpu token; 429 → back off and retry; 5xx → Space down, retry later.","Open the provider's cls.url in a browser to verify the Space is running and not showing a login/build page.","Pass fresh cookies= or api_key= (zerogpu token) to the provider call.","Upgrade g4f — Space URL/protocol fixes for renamed Spaces land upstream quickly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ...\nexcept ResponseStatusError as e:\n    status = int(str(e).split(':')[0].split()[-1])\n    if status == 429 or status >= 500:\n        await asyncio.sleep(backoff)  # retryable\n    elif status in (401, 403):\n        refresh_credentials()  # auth problem\n    else:\n        raise","preventionTips":["Check the Space URL responds 200 in a browser before wiring it into production.","Refresh HF cookies / zerogpu tokens proactively on a schedule.","Map status codes to retry vs fail-fast behavior instead of blanket retries."],"tags":["http","hf-space","status-code","auth"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}