Python class
OutputImageContent
OutputImageContentβ
class max.pipelines.request.OutputImageContent(*, type='output_image', image_url=None, image_data=None, format=None, detail=None)
Bases: BaseModel
Image content generated by the model in output messages.
-
Parameters:
-
- type (Literal['output_image'])
- image_url (str | None)
- image_data (str | None)
- format (str | None)
- detail (ImageDetail | None)
detailβ
detail: ImageDetail | None
formatβ
from_numpy()β
classmethod from_numpy(array, format='png', detail=None)
Create an OutputImageContent from a numpy array.
Converts a numpy array containing image data to base64-encoded format suitable for the OpenResponses API.
-
Parameters:
-
- array (ndarray[tuple[Any, ...], dtype[uint8]]) β A uint8 numpy array with values in [0, 255]. Expected shapes:
- [H, W, C] for color images (C=3 for RGB, C=4 for RGBA)
- [H, W] for grayscale images
- format (str) β The image format to use for encoding (e.g., βpngβ, βjpegβ, βwebpβ). Defaults to βpngβ.
- detail (ImageDetail | None) β Optional detail level for the generated image.
- array (ndarray[tuple[Any, ...], dtype[uint8]]) β A uint8 numpy array with values in [0, 255]. Expected shapes:
-
Returns:
-
An OutputImageContent instance with base64-encoded image data.
-
Raises:
-
- ImportError β If PIL/Pillow is not available.
- ValueError β If the array shape or dtype is invalid.
-
Return type:
Example:
>>> import numpy as np
>>> from max.pipelines.request.open_responses import OutputImageContent
>>> # Create a simple red image
>>> img_array = np.zeros((100, 100, 3), dtype=np.uint8)
>>> img_array[:, :, 0] = 255 # Set red channel to max
>>> output = OutputImageContent.from_numpy(img_array, format="png")image_dataβ
image_urlβ
model_configβ
model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
typeβ
type: Literal['output_image']
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!