xtekky/gpt4free · error · ResponseError

result

Error message

result

What it means

Raised as ResponseError when Puter returns a non-streaming JSON body (content-type application/json) that has neither a 'choices' key nor a 'result' key. The provider cannot locate a completion payload, so it raises with the whole JSON body as the message — which typically reveals the real upstream error (auth failure, quota, bad model).

Source

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

                                yield Reasoning(status="")
                                reasoning = False
                            yield content
                        if result.get("usage") is not None:
                            yield Usage(**result["usage"])
                        tool_calls = choice.get("delta", {}).get("tool_calls")
                        if tool_calls:
                            yield ToolCalls(choice["delta"]["tool_calls"])
                        finish_reason = choice.get("finish_reason")
                        if finish_reason:
                            yield FinishReason(finish_reason)
                elif mime_type.startswith("application/json"):
                    result = await response.json()
                    if "choices" in result:
                        choice = result["choices"][0]
                    elif "result" in result:
                        choice = result.get("result", {})
                    else:
                        raise ResponseError(result)
                    message = choice.get("message", {})
                    reasoning = message.get("reasoning")
                    if reasoning:
                        yield Reasoning(reasoning)
                    content = message.get("content", "")
                    if isinstance(content, list):
                        for item in content:
                            if item.get("type") == "text":
                                yield item.get("text", "")
                    elif content:
                        yield content
                    if "tool_calls" in message:
                        yield ToolCalls(message["tool_calls"])
                    if result.get("usage") is not None:
                        yield Usage(**result["usage"])
                    finish_reason = choice.get("finish_reason")
                    if finish_reason:
                        yield FinishReason(finish_reason)

View on GitHub (pinned to 973504e177)

Solutions

  1. Read the raised message: it is the raw JSON body and states the actual upstream problem
  2. If it is an auth error, refresh the api_key passed to the provider
  3. If the schema looks changed, update g4f to the latest version where the Puter parser was adjusted

Example fix

# before
result = client.chat.completions.create(model=..., messages=msgs, stream=False)

# after
try:
    result = client.chat.completions.create(model=..., messages=msgs, stream=False)
except g4f.errors.ResponseError as e:
    logging.error('Puter returned unexpected body: %s', e)
    raise
Defensive patterns

Strategy: try-catch

Try / catch

from g4f.errors import ResponseError
try:
    result = ...create(..., stream=False)
except ResponseError as e:
    body = str(e)
    if 'auth' in body.lower():
        rotate_api_key()
    else:
        raise

Prevention

When it happens

Trigger: Non-streaming (stream=False) call to Puter where the API responds with an error document instead of a completion, e.g. {"error": ...} or an unexpected schema.

Common situations: Expired or invalid api_key producing an error JSON, upstream API schema change after a Puter deployment, requesting a model that returns a structured error.

Related errors


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