# `Omni.Content.Attachment`
[🔗](https://github.com/aaronrussell/omni/blob/v2.0.0/lib/omni/content/attachment.ex#L1)

An attachment content block: an image, a PDF or other binary content.

A model takes only the media it supports (see `:input_modalities` on
`Omni.Model`); a request with an attachment it can't take is an error
before anything is sent.

```elixir
Omni.attachment({:base64, Base.encode64(File.read!("photo.png"))}, "image/png")
Omni.attachment({:url, "https://example.com/report.pdf"}, "application/pdf")
```

## Struct fields

- `:source` - where the content is: `{:base64, data}` for inline
  base64-encoded data, or `{:url, url}` for content hosted elsewhere
- `:media_type` - the MIME type, such as `"image/png"` or
  `"application/pdf"`
- `:meta` - a map for your application's own data, such as a filename or
  a label for a UI. Omni never reads it or sends it to a provider

# `source`

```elixir
@type source() :: {:base64, binary()} | {:url, String.t()}
```

An attachment source: inline base64 data or a remote URL.

# `t`

```elixir
@type t() :: %Omni.Content.Attachment{
  media_type: String.t(),
  meta: map(),
  source: source()
}
```

Binary content with a source, media type, and optional application metadata.

# `new`

```elixir
@spec new(Enumerable.t()) :: t()
```

Creates a new attachment content block from a keyword list or map.

```elixir
Attachment.new(source: {:url, "https://example.com/cat.png"}, media_type: "image/png", meta: %{name: "cat.png"})
```

# `new`

```elixir
@spec new(source(), String.t()) :: t()
```

Creates a new attachment content block from a source and media type.

```elixir
Attachment.new({:base64, Base.encode64(File.read!("photo.png"))}, "image/png")
Attachment.new({:url, "https://example.com/report.pdf"}, "application/pdf")
```

---

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