Tinkex.Types.ImageChunk (Tinkex v0.3.4)
View SourceImage chunk with base64 encoded data.
Mirrors Python tinker.types.ImageChunk.
Fields
data- Base64-encoded image dataformat- Image format (:pngor:jpeg)expected_tokens- Advisory expected token count (optional, required for.length/1)type- Always "image"
Expected Tokens
The expected_tokens field is advisory. The Tinker backend computes the actual
token count from the image. If expected_tokens is provided and doesn't match,
the request will fail quickly rather than processing the full request.
Calling length/1 will raise if expected_tokens is nil; this mirrors the
Python SDK guardrails to avoid silently miscounting tokens.
Wire Format
{
"data": "base64-encoded-data",
"format": "png",
"expected_tokens": 256,
"type": "image"
}CRITICAL: Field names are data and format, NOT image_data and image_format.
Summary
Functions
Get the length (number of tokens) consumed by this image.
Create a new ImageChunk from binary image data.
Types
@type format() :: :png | :jpeg
@type t() :: %Tinkex.Types.ImageChunk{ data: String.t(), expected_tokens: non_neg_integer() | nil, format: format(), type: String.t() }
Functions
@spec length(t()) :: non_neg_integer()
Get the length (number of tokens) consumed by this image.
Create a new ImageChunk from binary image data.
Automatically encodes the binary data as base64.
Parameters
image_binary- Raw image bytesformat- Image format (:pngor:jpeg)opts- Optional keyword list::expected_tokens- Advisory expected token count
Examples
iex> chunk = ImageChunk.new(<<1, 2, 3>>, :png, expected_tokens: 256)
iex> chunk.expected_tokens
256