# `Tinkex.Types.ImageChunk`
[🔗](https://github.com/North-Shore-AI/tinkex/blob/v0.4.0/lib/tinkex/types/image_chunk.ex#L1)

Image chunk with base64 encoded data.

Mirrors Python `tinker.types.ImageChunk`.

## Fields

- `data` - Base64-encoded image data
- `format` - Image format (`:png` or `: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

```json
{
  "data": "base64-encoded-data",
  "format": "png",
  "expected_tokens": 256,
  "type": "image"
}
```

CRITICAL: Field names are `data` and `format`, NOT `image_data` and `image_format`.

# `format`

```elixir
@type format() :: :png | :jpeg
```

# `t`

```elixir
@type t() :: %Tinkex.Types.ImageChunk{
  data: String.t(),
  expected_tokens: non_neg_integer() | nil,
  format: format(),
  type: String.t()
}
```

# `length`

```elixir
@spec length(t()) :: non_neg_integer()
```

Get the length (number of tokens) consumed by this image.

# `new`

```elixir
@spec new(binary(), format(), keyword()) :: t()
```

Create a new ImageChunk from binary image data.

Automatically encodes the binary data as base64.

## Parameters

- `image_binary` - Raw image bytes
- `format` - Image format (`:png` or `: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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
