View Source Anthropic.Messages.Content.Image (anthropic_community v0.5.0)
Validates, processes, and converts images into Anthropic.Messages.Content.Image request
content blocks for use in a user message, per the vision
guide.
Features
- Supports multiple image formats: JPEG, PNG, GIF, and WEBP.
- Validates images against a set of predefined dimensions and aspect ratios.
- Converts images to a base64 encoded string for easy transmission and storage.
- Provides detailed error handling for various failure scenarios during image processing.
Usage
The primary entry point to the module is process_image/2, which takes an image input
and an input type and returns a %Anthropic.Messages.Content.Image{} struct ready to be
embedded directly in a message's content list:
{:ok, image_block} = Anthropic.Messages.Content.Image.process_image("/path/to/image.png", :path)
Anthropic.Messages.create(client,
model: "claude-opus-4-8",
max_tokens: 1024,
messages: [
%{role: "user", content: [image_block, %{type: "text", text: "What's in this image?"}]}
]
)Supported Input Types
:binary- Direct binary data of the image.:path- A file system path to the image.:base64- A base64 encoded string of the image.
Summary
Functions
Processes the given image input based on the specified input type and converts it into a
%Anthropic.Messages.Content.Image{} content block.
Types
@type input_type() :: :binary | :path | :base64
@type mime_type() :: String.t()
@type supported_size() :: {String.t(), dimensions()}
Functions
@spec process_image(image_input(), input_type()) :: process_output()
Processes the given image input based on the specified input type and converts it into a
%Anthropic.Messages.Content.Image{} content block.
Parameters
image_input: The image input, which can be binary data, a file path, or a base64 encoded string.input_type: A symbol indicating the type of theimage_input(:binary,:path,:base64).
Returns
An {:ok, %Anthropic.Messages.Content.Image{}} tuple on success, or {:error, reason} on failure.