{"record":{"id":"ba983758a082c0e1","repo":"xtekky/gpt4free","slug":"result","errorCode":null,"errorMessage":"result","messagePattern":"result","errorType":"exception","errorClass":"ResponseError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/Puter.py","lineNumber":518,"sourceCode":"                                yield Reasoning(status=\"\")\n                                reasoning = False\n                            yield content\n                        if result.get(\"usage\") is not None:\n                            yield Usage(**result[\"usage\"])\n                        tool_calls = choice.get(\"delta\", {}).get(\"tool_calls\")\n                        if tool_calls:\n                            yield ToolCalls(choice[\"delta\"][\"tool_calls\"])\n                        finish_reason = choice.get(\"finish_reason\")\n                        if finish_reason:\n                            yield FinishReason(finish_reason)\n                elif mime_type.startswith(\"application/json\"):\n                    result = await response.json()\n                    if \"choices\" in result:\n                        choice = result[\"choices\"][0]\n                    elif \"result\" in result:\n                        choice = result.get(\"result\", {})\n                    else:\n                        raise ResponseError(result)\n                    message = choice.get(\"message\", {})\n                    reasoning = message.get(\"reasoning\")\n                    if reasoning:\n                        yield Reasoning(reasoning)\n                    content = message.get(\"content\", \"\")\n                    if isinstance(content, list):\n                        for item in content:\n                            if item.get(\"type\") == \"text\":\n                                yield item.get(\"text\", \"\")\n                    elif content:\n                        yield content\n                    if \"tool_calls\" in message:\n                        yield ToolCalls(message[\"tool_calls\"])\n                    if result.get(\"usage\") is not None:\n                        yield Usage(**result[\"usage\"])\n                    finish_reason = choice.get(\"finish_reason\")\n                    if finish_reason:\n                        yield FinishReason(finish_reason)","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/Puter.py#L500-L536","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the raised message: it is the raw JSON body and states the actual upstream problem","If it is an auth error, refresh the api_key passed to the provider","If the schema looks changed, update g4f to the latest version where the Puter parser was adjusted"],"exampleFix":"# before\nresult = client.chat.completions.create(model=..., messages=msgs, stream=False)\n\n# after\ntry:\n    result = client.chat.completions.create(model=..., messages=msgs, stream=False)\nexcept g4f.errors.ResponseError as e:\n    logging.error('Puter returned unexpected body: %s', e)\n    raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from g4f.errors import ResponseError\ntry:\n    result = ...create(..., stream=False)\nexcept ResponseError as e:\n    body = str(e)\n    if 'auth' in body.lower():\n        rotate_api_key()\n    else:\n        raise","preventionTips":["Keep the api_key current; expired keys are the most common cause of error JSON bodies","Pin g4f versions in production and test after upgrading (upstream schema changes surface here)"],"tags":["json","upstream-error","response-parsing","puter","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}