Normandy.Components.ContentBlock.Image (normandy v0.6.0)

View Source

Represents an image content block inside a multimodal message.

Supports two source types:

  • :base64 — inline base64-encoded image data with a media type.
  • :url — hosted image referenced by URL.

Use alongside Normandy.Components.ContentBlock.Text in a list assigned to a message's :content field to send an image to a Claude model.

Cache control

An optional cache_control field carries an Anthropic prompt-cache breakpoint annotation that the adapter ships verbatim on the wire. Use with_cache/1 for the default ephemeral type, or with_cache/2 for a custom map (e.g. %{"type" => "ephemeral", "ttl" => "1h"}). Atom keys are accepted and stringified at serialization time.

Summary

Functions

Builds a base64-sourced image block. media_type (e.g. "image/png", "image/jpeg") is required and positional — matching the Anthropic API, where the server cannot infer the format from the raw bytes.

Builds a URL-sourced image block.

Converts the block into the Anthropic/Claudio content-block map shape (string keys). Includes cache_control only when set.

Annotates this block with an ephemeral cache breakpoint.

Annotates this block with a caller-supplied cache_control map.

Types

source()

@type source() :: :base64 | :url

t()

@type t() :: %Normandy.Components.ContentBlock.Image{
  __meta__: term(),
  cache_control: map() | nil,
  data: String.t() | nil,
  media_type: String.t() | nil,
  source: source(),
  url: String.t() | nil
}

Functions

new_base64(data, media_type)

@spec new_base64(String.t(), String.t()) :: t()

Builds a base64-sourced image block. media_type (e.g. "image/png", "image/jpeg") is required and positional — matching the Anthropic API, where the server cannot infer the format from the raw bytes.

new_url(url)

@spec new_url(String.t()) :: t()

Builds a URL-sourced image block.

to_claudio(block)

@spec to_claudio(t()) :: %{required(String.t()) => term()}

Converts the block into the Anthropic/Claudio content-block map shape (string keys). Includes cache_control only when set.

Raises ArgumentError when the struct is in an incomplete state (e.g. source: :base64 with nil data, or source: :url with nil url). The constructors (new_base64/2, new_url/1) enforce valid state, so this only fires when a caller bypasses them.

with_cache(block)

@spec with_cache(t()) :: t()

Annotates this block with an ephemeral cache breakpoint.

with_cache(block, cache_control)

@spec with_cache(t(), map()) :: t()

Annotates this block with a caller-supplied cache_control map.

Atom keys are accepted; they are stringified when serialized.