xtekky/gpt4free · error · Exception

Unexpected content type: {content_type}

Error message

Unexpected content type: {content_type}

What it means

Error "Unexpected content type: {content_type}" thrown in xtekky/gpt4free.

Source

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

                                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
            }
            if extra_body is None:

View on GitHub (pinned to 973504e177)

Solutions

  1. Confirm base_url points to an API endpoint that returns JSON, not an HTML page.
  2. Verify the request path and headers (Accept: application/json).

When it happens

Trigger: Thrown at g4f/Provider/template/OpenaiTemplate.py:281 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/1287e5ce8c189441. Report an issue: GitHub.