xtekky/gpt4free · error · ResponseStatusError

Response {response.status}: {message}

Error message

Response {response.status}: {message}

What it means

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}'.

Source

Thrown at g4f/Provider/hf_space/raise_for_status.py:29

    response: Union[StreamResponse, ClientResponse], message: str = None
):
    if response.ok:
        return
    content_type = response.headers.get("content-type", "")
    if content_type.startswith("application/json"):
        try:
            data = await response.json()
            message = data.get("error", data.get("message", message))
            message = message.split(" <a ")[0]
        except Exception:
            pass
    if not message:
        text = await response.text()
        is_html = response.headers.get("content-type", "").startswith(
            "text/html"
        ) or text.startswith("<!DOCTYPE")
        message = "HTML content" if is_html else text
    raise ResponseStatusError(f"Response {response.status}: {message}")

View on GitHub (pinned to 973504e177)

Solutions

  1. 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.
  2. Open the provider's cls.url in a browser to verify the Space is running and not showing a login/build page.
  3. Pass fresh cookies= or api_key= (zerogpu token) to the provider call.
  4. Upgrade g4f — Space URL/protocol fixes for renamed Spaces land upstream quickly.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    ...
except ResponseStatusError as e:
    status = int(str(e).split(':')[0].split()[-1])
    if status == 429 or status >= 500:
        await asyncio.sleep(backoff)  # retryable
    elif status in (401, 403):
        refresh_credentials()  # auth problem
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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'.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/471a4f24d54824f5. Report an issue: GitHub.