Image
Image values to BAML functions can be created in client libraries. This document explains how to use these functions both at compile time and runtime to handle image data. For more details, refer to image types.
Usage Examples
Static Methods
Creates an Image object from a URL. Optionally specify the media type, otherwise it will be inferred from the URL.
Creates an Image object using Base64 encoded data along with the given MIME type.
Instance Methods
Check if the image is stored as a URL.
Get the URL of the image if it’s stored as a URL. Throws an Error if the image is not stored as a URL.
Get the base64 data and media type if the image is stored as base64. Returns [base64Data, mediaType]. Throws an Error if the image is not stored as base64.
Convert the image to a JSON representation. Returns either a URL object or a base64 object with media type.
URL Handling
When you create an Image using from_url, BAML processes the URL according to your client’s media_url_handler configuration:
- OpenAI: By default keeps URLs as-is (
send_url). Set tosend_base64to convert to base64. - Anthropic: By default keeps URLs as-is (
send_url). The provider accepts both formats. - Google AI: By default uses
send_base64_unless_google_urlto preserve gs:// URLs while converting others. - Vertex AI: By default uses
send_url_add_mime_typeto include MIME type information. - AWS Bedrock: By default converts to base64 (
send_base64).
You can override these defaults in your client configuration. See the provider-specific documentation linked above for details.