> ## Documentation Index
> Fetch the complete documentation index at: https://docs.routa.chat/llms.txt
> Use this file to discover all available pages before exploring further.

# Media

> How Routa stores images, audio, videos and documents, which types are accepted and how to get a temporary URL.

Media received in messages and files sent to the API stay in Routa's custody, in private storage. The API never exposes a permanent public URL: it hands out a **short-lived signed URL**.

## The media object

```json theme={null}
{
  "id": "med_01J8...",
  "content_type": "image/jpeg",
  "status": "ready",
  "url": "https://..."
}
```

| Field | Description |
| - | - |
| `id` | Media ID (`med_...`). It is the `media_id` in the content of a message. |
| `content_type` | MIME type of the file. |
| `status` | `pending`, `ready` or `unavailable`. |
| `url` | Signed URL, present only when `status` is `ready`. Otherwise `null`. |

| Status | Meaning |
| - | - |
| `pending` | Routa is still fetching or validating the file. |
| `ready` | The file is available and a URL can be issued. |
| `unavailable` | The file can no longer be served, for example because the fetch failed for good or retention expired. |

> [!NOTE]
>
> A message is never lost because its media failed. If the download of inbound media fails for good, the message still exists and the media becomes `unavailable`.

## Get the URL of a media file

`GET /v1/media/{id}` always returns a **fresh signed URL**, valid for **15 minutes**. Download right away and, if you need the file again, ask for another URL.

```bash theme={null}
curl https://api.routa.chat/v1/media/med_01J8... \
  -H "Authorization: Bearer $ROUTA_API_KEY"
```

If the media is still `pending`, retrieve it again after a moment.

## Upload or host media

`POST /v1/media` accepts the file in two ways, chosen by the `Content-Type`:

> [tab] Upload the bytes
>
> Send the file directly in the body, with the `Content-Type` of the file.
>
> ```bash theme={null}
> curl https://api.routa.chat/v1/media \
>   -H "Authorization: Bearer $ROUTA_API_KEY" \
>   -H "Content-Type: application/pdf" \
>   --data-binary @contract.pdf
> ```

> [tab] Host from a URL
>
> Send JSON with `source_url` and Routa fetches the file for you.
>
> ```bash theme={null}
> curl https://api.routa.chat/v1/media \
>   -H "Authorization: Bearer $ROUTA_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{ "source_url": "https://example.com/image.png" }'
> ```
>
> The URL must be public. Private or reserved addresses are blocked (`media_source_blocked`), and a URL that does not respond returns `media_source_unreachable`.

The response is `201 Created` with the media object.

## Accepted types and limits

Types and sizes follow the WhatsApp limits. A type outside the table returns `media_content_type_rejected`, and a file over the limit returns `media_size_limit_exceeded`.

| Type | Formats | Maximum size |
| - | - | - |
| Image | `image/jpeg`, `image/png` | 5 MiB |
| Image (sticker) | `image/webp` | 500 KB |
| Video | `video/mp4`, `video/3gpp` | 16 MiB |
| Audio | `audio/aac`, `audio/mp4`, `audio/mpeg`, `audio/amr`, `audio/ogg` | 16 MiB |
| Document | `application/pdf`, `text/plain`, `.doc`, `.docx`, `.xls`, `.xlsx`, `.ppt`, `.pptx` | 100 MiB |

## Retention

Media is kept for **90 days**. After that, the object becomes `unavailable`.

## Media in templates

A media header uses two files, uploaded through different endpoints:

| When | Endpoint | The `id` goes in |
| - | - | - |
| When you create the template: the sample WhatsApp reviews. | [`POST /v1/templates/media`](https://docs.routa.chat/en/api-reference/endpoint/templates/upload-media) (`tmedia_...`) | `components.header.media_id` |
| On every send: the file the recipient gets. | [`POST /v1/media`](https://docs.routa.chat/en/api-reference/endpoint/media/upload) (`med_...`) | `template.header_parameter.media_id` |

`POST /v1/templates/media` has its own types and limits. See [Templates](https://docs.routa.chat/en/concepts/templates.md#header). On a send, the file must be one you uploaded: a file received from a contact is refused. See [File in the header](https://docs.routa.chat/en/guides/send-template-message.md#file-in-the-header).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.