{"record":{"id":"654eb85b5a6c60d8","repo":"BerriAI/litellm","slug":"error-response-status-code-response-text-654eb8","errorCode":null,"errorMessage":"Error: {response.status_code} {response.text}","messagePattern":"Error: (.+?) (.+?)","errorType":"http","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/image_generation/image_generation_handler.py","lineNumber":163,"sourceCode":"\n        logging_obj.pre_call(\n            input=prompt,\n            api_key=\"\",\n            additional_args={\n                \"complete_input_dict\": optional_params,\n                \"api_base\": api_base,\n                \"headers\": headers,\n            },\n        )\n\n        response: Final = sync_handler.post(\n            url=api_base,\n            headers=headers,\n            data=json.dumps(request_data),\n        )\n\n        if response.status_code != 200:\n            raise Exception(f\"Error: {response.status_code} {response.text}\")\n\n        json_response: Final = response.json()\n        return self.process_image_generation_response(json_response, model_response, model)\n\n    async def aimage_generation(\n        self,\n        prompt: str,\n        api_base: str | None,\n        vertex_project: str | None,\n        vertex_location: str | None,\n        vertex_credentials: VERTEX_CREDENTIALS_TYPES | None,\n        model_response: ImageResponse,\n        logging_obj: Any,\n        model: str = \"imagegeneration\",  # vertex ai uses imagegeneration as the default model\n        client: AsyncHTTPHandler | None = None,\n        optional_params: dict | None = None,\n        timeout: int | None = None,\n        extra_headers: dict | None = None,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/image_generation/image_generation_handler.py#L145-L181","documentation":"The synchronous Vertex AI image-generation handler POSTs to the model's predict endpoint and, when the HTTP status is not 200, raises a bare Exception embedding the status code and full response body ('Error: {status} {body}'). It is not a typed litellm exception class, so callers must parse the message (or the underlying status) rather than catch a specific exception type. The body usually contains Vertex AI's error JSON explaining the real cause.","triggerScenarios":"litellm.image_generation(model='vertex_ai/imagegeneration', prompt='a cat') returning 404 (model not available/enabled in the region), 403 (service account lacks aiplatform.endpoints.predict / Vertex AI User role), 400 (invalid parameters like a bad sampleCount or aspect ratio), or 429 (quota exhausted).","commonSituations":"Image Generation API not enabled in the GCP project; using a region where the model is not served; IAM roles granted on the wrong project; exceeding the image quota on a new account; typos in optional_params keys after camelCase transformation.","solutions":["Read the status and body from the message text — it contains Vertex AI's exact error JSON","404: enable the model/API in the target region (e.g. us-central1) in the Model Garden / Vertex AI console","403: grant the service account roles/aiplatform.user (or runai.user) on the project","400: verify optional_params (sampleCount, aspectRatio) against the model's docs","429: check quotas in the console and back off or request an increase"],"exampleFix":"# before\nresp = litellm.image_generation(model='vertex_ai/imagegeneration', prompt='a cat')\n\n# after — surface the embedded status/body\ntry:\n    resp = litellm.image_generation(\n        model='vertex_ai/imagegeneration',\n        prompt='a cat',\n        vertex_ai_project='my-project',\n        vertex_ai_location='us-central1',\n    )\nexcept Exception as e:\n    print(str(e))  # 'Error: 404 {\"error\": {\"message\": \"Model not found...\"}}'\n    raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.image_generation(model='vertex_ai/imagegeneration', prompt=p,\n                                    vertex_ai_project=PROJECT, vertex_ai_location=REGION)\nexcept Exception as e:\n    msg = str(e)\n    if 'Error: 429' in msg or 'Error: 503' in msg:\n        backoff_and_retry()  # transient\n    elif 'Error: 403' in msg:\n        raise RuntimeError('service account lacks Vertex AI predict permission') from e\n    else:\n        raise  # body text contains Vertex AI's error JSON","preventionTips":["Enable the image model in the target region before deploying","Grant roles/aiplatform.user to the calling service account","Wrap calls with status-aware handling that parses 'Error: {code}' from the message","Watch quotas when raising sampleCount or concurrency"],"tags":["vertex-ai","image-generation","http-error","gcp","iam","quota"],"backgroundTag":"http-error-response","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}