xtekky/gpt4free · warning · RuntimeError

Response: {text}

Error message

Response: {text}

What it means

In fetch_sources(), parsing of the sources response failed with KeyError, TypeError, or json.JSONDecodeError while walking response_json['data']['message']['searchResults']['references'] (as written, the f-string lacks braces so the literal expression is the message — the effective text is 'Response: <raw body>'). It means the endpoint answered non-error HTML but the body did not match the expected GraphQL shape.

Source

Thrown at g4f/Provider/needs_auth/MetaAI.py:248

            "x-fb-friendly-name": "AbraSearchPluginDialogQuery",
            **headers,
        }
        async with self.session.post(
            url, headers=headers, cookies=self.cookies, data=payload
        ) as response:
            await raise_for_status(response, "Fetch sources failed")
            text = await response.text()
            if "<h1>Something Went Wrong</h1>" in text:
                raise ResponseError("Response: Something Went Wrong")
            try:
                response_json = json.loads(text)
                message = response_json["data"]["message"]
                if message is not None:
                    searchResults = message["searchResults"]
                    if searchResults is not None:
                        return Sources(searchResults["references"])
            except (KeyError, TypeError, json.JSONDecodeError):
                raise RuntimeError(f"Response: {text}")

    @staticmethod
    def extract_value(text: str, key: str = None, start_str=None, end_str='",') -> str:
        if start_str is None:
            start_str = f'{key}":{{"value":"'
        start = text.find(start_str)
        if start >= 0:
            start += len(start_str)
            end = text.find(end_str, start)
            if end >= 0:
                return text[start:end]


def generate_offline_threading_id() -> str:
    """
    Generates an offline threading ID.

    Returns:

View on GitHub (pinned to 973504e177)

Solutions

  1. Log the raw text included in the message to see the actual body returned
  2. Refresh cookies/tokens via update_cookies() and retry once
  3. Treat sources as optional and consume the completion without them when parsing fails
  4. Update g4f to pick up any schema changes in fetch_sources

Example fix

// before
# error escapes and kills the whole prompt
resp = await meta.prompt(query)

// after
# accept that sources may be unavailable
try:
    resp = await meta.prompt(query)
except RuntimeError:
    resp = await meta.prompt(query, stream=False)  # or skip source-augmented mode
Defensive patterns

Strategy: fallback

Try / catch

try:
    resp = await meta.prompt(query)
except RuntimeError:
    # sources parsing failed; completion may still be usable without sources
    resp = await meta.prompt(query) if retry_enabled else degrade_to_no_sources()

Prevention

When it happens

Trigger: POSTing AbraSearchPluginDialogQuery returns a 200 body that is not valid JSON, or JSON lacking data/message/searchResults keys — e.g. empty search results shape changes, auth-token drift, or an interstitial page without the error h1 marker.

Common situations: Meta changing the search plugin response schema; responses where message is null (no sources found); partial HTML bodies from proxies that break JSON parsing.

Related errors


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