HKUDS/DeepTutor · error · GenerationProviderError

Image response had no `data` array.

Error message

Image response had no `data` array.

What it means

_extract_items parsed the response JSON but found no non-empty list under the top-level data key (either the body isn't a dict, or data is absent/empty/not a list). The OpenAI images API contract requires {"data": [ ... ]}.

Source

Thrown at deeptutor/services/imagegen/adapters/openai_compat.py:77

                resp = await client.post(url, headers=headers, json=payload)
                raise_for_provider(resp, "Image generation")
                images = [
                    await self._materialize(client, item) for item in self._extract_items(resp)
                ]
        except httpx.HTTPError as exc:
            raise GenerationProviderError(f"Image generation request error: {exc}") from exc
        if not images:
            raise GenerationProviderError("Image provider returned no images.")
        return images

    @staticmethod
    def _extract_items(resp: httpx.Response) -> list[dict[str, Any]]:
        data = resp.json()
        if isinstance(data, dict):
            items = data.get("data")
            if isinstance(items, list) and items:
                return [item for item in items if isinstance(item, dict)]
        raise GenerationProviderError("Image response had no `data` array.")

    async def _materialize(
        self, client: httpx.AsyncClient, item: dict[str, Any]
    ) -> tuple[bytes, str]:
        b64 = item.get("b64_json")
        if isinstance(b64, str) and b64:
            return base64.b64decode(b64), "image/png"
        src = item.get("url")
        if isinstance(src, str) and src:
            resp = await client.get(src)
            raise_for_provider(resp, "Image download")
            content_type = resp.headers.get("content-type") or "image/png"
            if not content_type.startswith("image/"):
                content_type = "image/png"
            return resp.content, content_type
        raise GenerationProviderError("Image item had neither `b64_json` nor `url`.")

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Log resp.json() to see the actual body — usually an inline error/quota message
  2. Address the underlying cause the body reports (billing, quota, model access)
  3. If the provider uses a different schema, point the config at a conforming endpoint or adapt the extraction
Defensive patterns

Strategy: validation

Validate before calling

body = resp.json()
assert isinstance(body, dict) and isinstance(body.get("data"), list) and body["data"], "missing data array"

Type guard

def is_openai_images_response(body) -> bool:
    return isinstance(body, dict) and isinstance(body.get("data"), list) and len(body["data"]) > 0

Try / catch

try:
    items = adapter._extract_items(resp)
except GenerationProviderError:
    logger.error("images/generations body lacked data: %s", resp.text)
    raise

Prevention

When it happens

Trigger: Provider returned an error-shaped 2xx body, a rate-limit/quota message without data, an empty data: [], or a completely different schema (e.g. wrapped in another key).

Common situations: OpenAI-compatible gateways that return errors with HTTP 200; exhausted quota returned as a message object; API version drift renaming the field.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/ab953842f3a1efda. Report an issue: GitHub.