{"record":{"id":"e88f87162d5c91c6","repo":"xtekky/gpt4free","slug":"unexpected-response-response-text","errorCode":null,"errorMessage":"Unexpected response: {response.text}","messagePattern":"Unexpected response: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"g4f/Provider/template/OpenaiTemplate.py","lineNumber":279,"sourceCode":"                                and isinstance(data, str)\n                                and data.startswith(\"http://\")\n                                or data.startswith(\"https://\")\n                            ]\n                        ),\n                        None,\n                    )\n                async with session.post(\n                    f\"{base_url.rstrip('/')}/images/generations\", json=data, ssl=cls.ssl\n                ) as response:\n                    content_type = response.headers.get(\"content-type\", \"\")\n                    if content_type.startswith(\"application/json\"):\n                        data = await response.json()\n                        cls.raise_error(data, response.status)\n                        model = data.get(\"model\")\n                        if model:\n                            yield ProviderInfo(**cls.get_dict(), model=model)\n                    elif content_type.startswith(\"text/plain\"):\n                        raise Exception(\"Unexpected response: \" + await response.text())\n                    else:\n                        raise Exception(\"Unexpected content type: \" + content_type)\n                    await raise_for_status(response)\n                    yield ImageResponse(\n                        [\n                            f\"data:image/png;base64,{image['b64_json']}\"\n                            if image.get(\"url\") is None\n                            else image[\"url\"]\n                            for image in data[\"data\"]\n                        ],\n                        prompt,\n                    )\n                return\n\n            if stream or stream is None:\n                kwargs.setdefault(\"stream_options\", {\"include_usage\": True})\n            extra_parameters = {\n                key: kwargs[key] for key in extra_parameters if key in kwargs","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/template/OpenaiTemplate.py#L261-L297","documentation":"Error \"Unexpected response: {response.text}\" thrown in xtekky/gpt4free.","triggerScenarios":"Thrown at g4f/Provider/template/OpenaiTemplate.py:279 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the response body for an error message from the upstream API.","Verify base_url, api_key, and model are correct for this endpoint."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}