public final class ImagePart

  1. Object
  2. MessagePart
  3. ImagePart
Image content within a multimodal ChatMessage. An image is either inline encoded bytes with a MIME type or a provider-accessible URL. Inline bytes are copied on construction and access so later caller mutations cannot change a request that already contains this part.

Constructors

public ImagePart(byte[] data, String mimeType)Creates an inline image part.
public ImagePart(String url)Remote image by URL.

Methods

public byte[] getData()
public String getMimeType()
public String getUrl()
public boolean isUrl()

Inherited methods

Constructor details

ImagePart

public ImagePart(byte[] data, String mimeType)
Creates an inline image part. The media type must describe the encoded bytes, for example image/png or image/jpeg; providers reject inline images without a type.

Parameters

data byte[]
encoded image bytes, defensively copied
mimeType String
media type such as image/png

ImagePart

public ImagePart(String url)
Remote image by URL. Only HTTPS is portable across providers. Creates a remotely addressed image part.

Parameters

url String
provider-accessible HTTPS or data URL

Method details

getData

public byte[] getData()

Returns

a defensive copy of inline bytes, or null for a URL image

getMimeType

public String getMimeType()

Returns

MIME type of inline bytes, or null for a URL image

getUrl

public String getUrl()

Returns

provider-accessible URL, or null for an inline image

isUrl

public boolean isUrl()

Returns

true when this part references a URL instead of bytes