Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Response Error Model

From Leeroopedia
Knowledge Sources
Domains API_Types, Responses_API
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete response type representing an error object when the model fails to generate a Response, provided by the openai-python SDK.

Description

ResponseError is a Pydantic model representing an error returned when the model fails to generate a Response. It contains a code field with a literal type covering all possible error codes (including "server_error", "rate_limit_exceeded", "invalid_prompt", "vector_store_timeout", and numerous image-related error codes), and a message field with a human-readable description. This type is auto-generated from the OpenAI OpenAPI specification by Stainless.

Usage

Import ResponseError when inspecting the error details on a failed Response object to determine the failure reason and display appropriate messages.

Code Reference

Source Location

Signature

class ResponseError(BaseModel):
    """An error object returned when the model fails to generate a Response."""

    code: Literal[
        "server_error",
        "rate_limit_exceeded",
        "invalid_prompt",
        "vector_store_timeout",
        "invalid_image",
        "invalid_image_format",
        "invalid_base64_image",
        "invalid_image_url",
        "image_too_large",
        "image_too_small",
        "image_parse_error",
        "image_content_policy_violation",
        "invalid_image_mode",
        "image_file_too_large",
        "unsupported_image_media_type",
        "empty_image_file",
        "failed_to_download_image",
        "image_file_not_found",
    ]
    message: str

Import

from openai.types.responses import ResponseError

I/O Contract

Fields

Name Type Required Description
code Literal[...] (see below) Yes The error code for the response. One of 18 possible literal values.
message str Yes A human-readable description of the error.

Error Codes

Code Category
server_error Server
rate_limit_exceeded Rate Limiting
invalid_prompt Input Validation
vector_store_timeout File Search
invalid_image Image
invalid_image_format Image
invalid_base64_image Image
invalid_image_url Image
image_too_large Image
image_too_small Image
image_parse_error Image
image_content_policy_violation Image
invalid_image_mode Image
image_file_too_large Image
unsupported_image_media_type Image
empty_image_file Image
failed_to_download_image Image
image_file_not_found Image

Usage Examples

from openai.types.responses import ResponseError

# Check for errors on a response
response = client.responses.create(
    model="gpt-4o",
    input="Analyze this image",
)

if response.status == "failed" and response.error:
    error: ResponseError = response.error
    print(f"Error code: {error.code}")
    print(f"Error message: {error.message}")

    if error.code == "rate_limit_exceeded":
        print("Retrying after delay...")
    elif error.code.startswith("image"):
        print("Image-related error occurred")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment