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

# Import media from a URL

> Send a public HTTPS file by importing it into a Relay Attachment.

Put the URL in a media part's `url` field instead of `attachment_id`, through either [send path](/messages/send). Relay fetches the file, stores it as an Attachment owned by your agent, and commits the message with a Relay download URL in place of the source. Later downloads never touch your host, so the source can go away once the send is confirmed.

The import limit is 10 MiB (10,485,760 bytes). For a larger file, or one that needs private access to fetch, [upload it](/messages/attachments) instead. Keep the source file available until the send returns, and reuse the same idempotency key on a retry.

## Send the URL

Send exactly one of `url` or `attachment_id` in each media part:

```json theme={null}
{
  "message": {
    "parts": [{"type":"media","url":"https://cdn.yourdomain.com/report.pdf"}]
  }
}
```

Relay returns `202` after the import and commit. The media part in the response carries the new Attachment `id` and a Relay download URL; keep the `id` for [URL refreshes](/messages/receiving-media#refresh-eligibility). A message may carry up to 40 URL media parts.

## Apply the URL safety checks

Every redirect and every resolved address must pass the same checks as the original URL.

| Check                  | Requirement                                                                                                                          |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| Scheme and credentials | HTTPS, with no username or password in the URL                                                                                       |
| Network                | Every resolved address is public; loopback, private, link-local, reserved, and internal destinations are blocked                     |
| Hostname               | `localhost` and names ending in `.localhost`, `.local`, `.internal`, `.home`, `.lan`, `.test`, `.invalid`, or `.example` are refused |
| Redirects              | At most five; each destination is checked again                                                                                      |
| Response               | The final response must succeed                                                                                                      |
| Size                   | The body is 1 byte to 10 MiB; a declared `Content-Length`, when present, must be valid and within the ceiling                        |
| Content type           | Any valid declared MIME type; a missing or unusable declaration becomes `application/octet-stream`                                   |

An imported Attachment is served with the same [download headers and type rules](/messages/attachment-types) as an uploaded one.

## When it fails

| Status | Code                               | Cause                                                                           | Next action                             |
| ------ | ---------------------------------- | ------------------------------------------------------------------------------- | --------------------------------------- |
| `400`  | [1005](/api-reference/errors#1005) | The media part names both inputs or neither, or the message has too many parts. | Correct the part.                       |
| `409`  | [1005](/api-reference/errors#1005) | The idempotency key was reused with a different body.                           | Use a new key for a new message.        |
| `413`  | [2006](/api-reference/errors#2006) | The file is empty or over 10 MiB.                                               | Upload it instead.                      |
| `422`  | [2006](/api-reference/errors#2006) | The URL, a redirect, the address, or the response failed a check.               | Fix the URL or host the file elsewhere. |

## Next steps

* [Upload attachments](/messages/attachments)
* [Read the types and limits](/messages/attachment-types)
* [Download attachments](/messages/receiving-media)
