{"record":{"id":"e1c4b07437930855","repo":"abi/screenshot-to-code","slug":"invalid-prediction-creation-response","errorCode":null,"errorMessage":"Invalid prediction creation response.","messagePattern":"Invalid prediction creation response\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/image_generation/replicate.py","lineNumber":87,"sourceCode":"            raise ValueError(f\"Inference errored out: {error_message}\")\n        if status == \"failed\":\n            raise ValueError(\"Inference failed\")\n\n    raise TimeoutError(\"Inference timed out\")\n\n\nasync def _run_prediction(\n    endpoint_url: str, payload: dict[str, Any], api_token: str\n) -> Any:\n    headers = _build_headers(api_token)\n\n    async with httpx.AsyncClient() as client:\n        try:\n            response = await client.post(endpoint_url, headers=headers, json=payload)\n            response.raise_for_status()\n            response_json = response.json()\n            if not isinstance(response_json, dict):\n                raise ValueError(\"Invalid prediction creation response.\")\n\n            prediction_id = _extract_prediction_id(response_json)\n            final_response = await _poll_prediction(client, prediction_id, headers)\n            return final_response.get(\"output\")\n        except httpx.HTTPStatusError as exc:\n            raise ValueError(f\"HTTP error occurred: {exc}\") from exc\n        except httpx.RequestError as exc:\n            raise ValueError(f\"An error occurred while requesting: {exc}\") from exc\n        except asyncio.TimeoutError as exc:\n            raise TimeoutError(\"Request timed out\") from exc\n        except (TimeoutError, ValueError):\n            raise\n        except Exception as exc:\n            raise ValueError(f\"An unexpected error occurred: {exc}\") from exc\n\n\ndef _extract_output_url(result: Any, context: str) -> str:\n    if isinstance(result, str):","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/image_generation/replicate.py#L69-L105","documentation":"Raised in _run_prediction when the POST that creates a prediction returns 2xx but its JSON body is not an object — the first shape check before _extract_prediction_id even runs. It means the HTTP layer was fine but the payload isn't a prediction dict at all (a JSON array, scalar, or \"null\").","triggerScenarios":"POST {base}/models/{model_path}/predictions responding 200 with a JSON list or scalar body; a gateway returning a bare JSON literal; severe API contract drift on Replicate's side.","commonSituations":"Rare in practice — usually proxy interference or hitting a non-Replicate endpoint configured via REPLICATE_API_BASE_URL; response shape changes during Replicate migrations.","solutions":["Log response.text at the failure point to see the actual body.","Confirm REPLICATE_API_BASE_URL is https://api.replicate.com and reachable directly.","Reproduce the POST with curl using the same token and model_path.","Update the check if the API legitimately wraps predictions in an envelope now."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from typing import Any, Mapping\n\ndef is_prediction_envelope(response_json: Any) -> bool:\n    return isinstance(response_json, Mapping)","tryCatchPattern":"try:\n    output = await call_replicate_model(model, input, token)\nexcept ValueError as e:\n    if \"Invalid prediction creation response\" in str(e):\n        log.error(\"Non-dict creation body from Replicate for %s\", model)\n    raise","preventionTips":["Confirm no proxy rewrites creation responses","Reproduce the POST with curl when this fires","Keep an integration test pinned to the current creation-response shape"],"tags":["replicate","api","response-validation","image-generation"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}