xtekky/gpt4free · error · Exception

Unexpected response: {response.text}

Error message

Unexpected response: {response.text}

What it means

Error "Unexpected response: {response.text}" thrown in xtekky/gpt4free.

Source

Thrown at g4f/Provider/template/OpenaiTemplate.py:279

                                and isinstance(data, str)
                                and data.startswith("http://")
                                or data.startswith("https://")
                            ]
                        ),
                        None,
                    )
                async with session.post(
                    f"{base_url.rstrip('/')}/images/generations", json=data, ssl=cls.ssl
                ) as response:
                    content_type = response.headers.get("content-type", "")
                    if content_type.startswith("application/json"):
                        data = await response.json()
                        cls.raise_error(data, response.status)
                        model = data.get("model")
                        if model:
                            yield ProviderInfo(**cls.get_dict(), model=model)
                    elif content_type.startswith("text/plain"):
                        raise Exception("Unexpected response: " + await response.text())
                    else:
                        raise Exception("Unexpected content type: " + content_type)
                    await raise_for_status(response)
                    yield ImageResponse(
                        [
                            f"data:image/png;base64,{image['b64_json']}"
                            if image.get("url") is None
                            else image["url"]
                            for image in data["data"]
                        ],
                        prompt,
                    )
                return

            if stream or stream is None:
                kwargs.setdefault("stream_options", {"include_usage": True})
            extra_parameters = {
                key: kwargs[key] for key in extra_parameters if key in kwargs

View on GitHub (pinned to 973504e177)

Solutions

  1. Check the response body for an error message from the upstream API.
  2. Verify base_url, api_key, and model are correct for this endpoint.

When it happens

Trigger: Thrown at g4f/Provider/template/OpenaiTemplate.py:279 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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