# `SystemOneClient.Images`
[🔗](https://github.com/schainks/system_one_client/blob/v0.5.0/lib/system_one_client/images.ex#L1)

Validation for the `images:` option.

Images are base64 data URLs (`data:image/png;base64,...`); build one from bytes with
`SystemOneClient.image_data_url/2`. Only providers whose APIs accept images can take
them, and they are checked before any request is sent:

| Provider | Accepted | Limits checked locally |
| --- | --- | --- |
| `:openai` | any `image/*` data URL | none documented |
| `:cloudflare` | PNG, JPEG, WebP | at most 4 images, 4 MiB each and 8 MiB in total, decoded |
| `:gemini` | PNG, JPEG, WebP, HEIC, HEIF, GIF, BMP, TIFF | 100 MiB in total, decoded |
| `:flide` | any `image/*` data URL | none; they depend on the model served |
| others | no | returns `{:error, {:unsupported_option, :images, provider}}` |

Remote `http(s)` image URLs are rejected for every provider. OpenAI, Clef and Flide do
not accept them; Gemini does, but this option does not pass them through yet.

# `error`

```elixir
@type error() ::
  :images_not_a_list
  | {:unsupported_option, :images, atom()}
  | {:invalid_image, non_neg_integer(),
     :not_a_data_url
     | :invalid_base64
     | :too_large
     | {:unsupported_type, String.t()}}
  | {:too_many_images, pos_integer(), pos_integer()}
  | {:images_too_large, non_neg_integer(), pos_integer()}
```

# `validate`

```elixir
@spec validate(term(), atom()) :: :ok | {:error, error()}
```

Checks `images` for `provider`.

    iex> SystemOneClient.Images.validate(["data:image/png;base64,YWJj"], :openai)
    :ok

    iex> SystemOneClient.Images.validate(["https://example.com/a.png"], :openai)
    {:error, {:invalid_image, 0, :not_a_data_url}}

---

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