{"record":{"id":"32aeb3bcb6bb12ac","repo":"HKUDS/DeepTutor","slug":"image-item-had-neither-b64-json-nor-url","errorCode":null,"errorMessage":"Image item had neither `b64_json` nor `url`.","messagePattern":"Image item had neither `b64_json` nor `url`\\.","errorType":"error_code","errorClass":"GenerationProviderError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/imagegen/adapters/openai_compat.py","lineNumber":93,"sourceCode":"            if isinstance(items, list) and items:\n                return [item for item in items if isinstance(item, dict)]\n        raise GenerationProviderError(\"Image response had no `data` array.\")\n\n    async def _materialize(\n        self, client: httpx.AsyncClient, item: dict[str, Any]\n    ) -> tuple[bytes, str]:\n        b64 = item.get(\"b64_json\")\n        if isinstance(b64, str) and b64:\n            return base64.b64decode(b64), \"image/png\"\n        src = item.get(\"url\")\n        if isinstance(src, str) and src:\n            resp = await client.get(src)\n            raise_for_provider(resp, \"Image download\")\n            content_type = resp.headers.get(\"content-type\") or \"image/png\"\n            if not content_type.startswith(\"image/\"):\n                content_type = \"image/png\"\n            return resp.content, content_type\n        raise GenerationProviderError(\"Image item had neither `b64_json` nor `url`.\")\n\n\n__all__ = [\"OpenAICompatImagegenAdapter\"]\n","sourceCodeStart":75,"sourceCodeEnd":97,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/imagegen/adapters/openai_compat.py#L75-L97","documentation":"_materialize inspected a data item dict and found neither a non-empty b64_json string nor a usable url field to fetch, so there is no way to obtain image bytes from that item.","triggerScenarios":"A data item containing only extra fields (e.g. revised_prompt alone), a null/empty b64_json and no url, or response_format set to url while the provider omits url.","commonSituations":"Provider response_format mismatch (asking b64_json but getting url-only or vice versa), partial fields on error, schema drift in third-party gateways.","solutions":["Inspect the item dict to see which fields it actually carries","Set response_format in the request payload to the value your provider honors (url or b64_json)","If the provider simply doesn't populate either field, switch endpoint or provider"],"exampleFix":"// before\npayload = {\"model\": m, \"prompt\": p}  # provider defaults omit url/b64\n// after\npayload = {\"model\": m, \"prompt\": p, \"response_format\": \"b64_json\"}","handlingStrategy":"validation","validationCode":"def item_has_image(item: dict) -> bool:\n    return (isinstance(item.get(\"b64_json\"), str) and item[\"b64_json\"]) or isinstance(item.get(\"url\"), str)","typeGuard":"def is_materializable(item) -> bool:\n    return isinstance(item, dict) and (bool(item.get(\"b64_json\")) or bool(item.get(\"url\")))","tryCatchPattern":"try:\n    img = await adapter._materialize(client, item)\nexcept GenerationProviderError as exc:\n    if \"neither\" in str(exc):\n        continue  # skip unusable item","preventionTips":["Explicitly set response_format in the request payload","Inspect data items during provider onboarding to confirm b64_json/url presence"],"tags":["imagegen","openai-compat","response-parsing"],"backgroundTag":"unexpected-response-schema","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}