xtekky/gpt4free · error · ResponseError

result["error"].get("message", result["error"])

Error message

result["error"].get("message", result["error"])

What it means

Raised as ResponseError while consuming Puter's text/event-stream response: an SSE event arrived whose JSON payload contains an 'error' key. The provider surfaces the upstream error message (or the raw error object) and terminates the stream.

Source

Thrown at g4f/Provider/needs_auth/Puter.py:486

                        param: kwargs.get(param)
                        for param in extra_parameters
                        if param in kwargs
                    },
                },
            }
            async with session.post(
                cls.api_endpoint, headers=headers, json=json_data, proxy=proxy
            ) as response:
                await raise_for_status(response)
                mime_type = response.headers.get("content-type", "")
                if mime_type.startswith("text/plain"):
                    yield await response.text()
                    return
                elif mime_type.startswith("text/event-stream"):
                    reasoning = False
                    async for result in sse_stream(response.content):
                        if "error" in result:
                            raise ResponseError(
                                result["error"].get("message", result["error"])
                            )
                        choices = result.get("choices", [{}])
                        choice = choices.pop() if choices else {}
                        content = choice.get("delta", {}).get("content")
                        reasoning_content = choice.get("delta", {}).get(
                            "reasoning_content"
                        )
                        if reasoning_content:
                            reasoning = True
                            yield Reasoning(reasoning_content)
                        elif content:
                            if reasoning:
                                yield Reasoning(status="")
                                reasoning = False
                            yield content
                        if result.get("usage") is not None:
                            yield Usage(**result["usage"])

View on GitHub (pinned to 973504e177)

Solutions

  1. Catch ResponseError and inspect the message; fix the model name or request payload it complains about
  2. Check Puter account quota/usage if the message indicates rate or credit limits
  3. Retry with backoff for transient upstream errors; fall back to another provider if persistent

Example fix

# before
for chunk in client.chat.completions.create(..., stream=True):
    print(chunk.choices[0].delta.content)

# after
try:
    for chunk in client.chat.completions.create(..., stream=True):
        print(chunk.choices[0].delta.content)
except g4f.errors.ResponseError as e:
    logging.error('Puter stream error: %s', e)
    raise
Defensive patterns

Strategy: retry

Try / catch

from g4f.errors import ResponseError
try:
    stream = ...create(..., stream=True)
    for chunk in stream: process(chunk)
except ResponseError as e:
    if 'rate' in str(e).lower():
        backoff_and_retry()
    else:
        raise

Prevention

When it happens

Trigger: Streaming a completion from Puter when the upstream service returns an error event mid-stream: invalid model, quota exceeded, rate limit, or malformed request accepted late.

Common situations: Using a model name Puter no longer supports, hitting account rate limits partway through a long streaming session, transient upstream 5xx surfaced as SSE error events.

Related errors


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