> ## 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.

# Upload or host media

> Stores a media file in Routa's custody. There are two ways, chosen by the `Content-Type`:

- **Bytes:** send the file in the body, with the `Content-Type` of the file.
- **URL:** send `application/json` with `{ "source_url": "https://..." }` and Routa downloads the file. The URL must be public.

Accepted types and sizes follow the WhatsApp limits. See [Media](/en/concepts/media).

The returned `id` is what you pass in `template.header_parameter.media_id` to send a template with a media header.



## OpenAPI

````yaml en/openapi.json POST /v1/media
openapi: 3.0.3
info:
  title: Routa API
  description: >-
    REST API to send and receive WhatsApp messages, track delivery and receive
    normalized events through webhooks.
  version: '1'
servers:
  - url: https://api.routa.chat
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Messages
    description: Send, retrieve and list messages.
  - name: Events
    description: Query the log of normalized events.
  - name: Webhooks
    description: Manage webhook endpoints, secrets and deliveries.
  - name: Templates
    description: Create and retrieve WhatsApp templates.
  - name: Media
    description: Upload and download media files.
  - name: Usage
    description: Query the metered usage of the project.
  - name: Identity
    description: Identify the API key in use.
  - name: Partners
    description: >-
      Create one project per customer, issue the key of each project, follow the
      channels and receive the events of every customer on a single webhook.
      These routes use a partner key (`rt_partner_...`). See [Partner
      API](/en/partners/overview).
paths:
  /v1/media:
    post:
      tags:
        - Media
      summary: Upload or host media
      description: >-
        Stores a media file in Routa's custody. There are two ways, chosen by
        the `Content-Type`:


        - **Bytes:** send the file in the body, with the `Content-Type` of the
        file.

        - **URL:** send `application/json` with `{ "source_url": "https://..."
        }` and Routa downloads the file. The URL must be public.


        Accepted types and sizes follow the WhatsApp limits. See
        [Media](/en/concepts/media).


        The returned `id` is what you pass in
        `template.header_parameter.media_id` to send a template with a media
        header.
      operationId: uploadMedia
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - source_url
              properties:
                source_url:
                  type: string
                  format: uri
                  description: Public URL of the file Routa should download.
                  example: https://example.com/image.png
          application/octet-stream:
            schema:
              type: string
              format: binary
              description: >-
                The file bytes. Use the real `Content-Type` of the file, for
                example `image/jpeg`.
      responses:
        '201':
          description: Resource created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Media'
        '401':
          description: >-
            The API key is missing, invalid, revoked or expired
            (`api_key_invalid`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: The key lacks the required scope (`insufficient_scope`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit exceeded. See the `Retry-After` header
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth:
            - media:write
components:
  schemas:
    Media:
      type: object
      properties:
        id:
          type: string
          description: Media ID.
          example: med_01J8ZK9M3Q7XABCDEFGHJKMNPQ
        content_type:
          type: string
          description: MIME type of the file.
          example: image/jpeg
        status:
          type: string
          enum:
            - pending
            - ready
            - unavailable
          description: 'State: `pending`, `ready` or `unavailable`.'
        url:
          type: string
          nullable: true
          description: >-
            Signed URL, valid for 15 minutes. Present only when `status` is
            `ready`.
      required:
        - id
        - content_type
        - status
        - url
    Error:
      type: object
      properties:
        error:
          type: object
          required:
            - type
            - code
            - message
            - request_id
          properties:
            type:
              type: string
              description: >-
                Error category: `invalid_request_error`, `authentication_error`,
                `permission_error`, `not_found_error`, `conflict_error`,
                `rate_limit_error`, `billing_error` or `api_error`.
              example: invalid_request_error
            code:
              type: string
              description: >-
                Stable, machine-readable code. See [Error
                codes](/en/errors/error-codes).
              example: channel_inactive
            message:
              type: string
              description: >-
                Human-readable text, in English. It can change, so do not parse
                it.
              example: Channel chan_01J8... is not active and cannot send messages.
            param:
              type: string
              description: >-
                The request field at fault, when it applies. It is filled in on
                `request_invalid` (the field outside the schema, such as
                `template.button_parameters.0.index`) and on template errors:
                `name` in `template_name_invalid`; `body_text`,
                `components.header`, `components.footer` or `components.buttons`
                in `template_components_invalid`; and `variable_examples`,
                `variable_examples.<position>`, `components.header.example` or
                `components.buttons.<position>.example` when
                `template_variables_invalid` refuses an example.
              example: components.buttons.0.example
            doc_url:
              type: string
              description: Link to the documentation of the code, when available.
            details:
              type: object
              additionalProperties:
                oneOf:
                  - type: string
                  - type: number
              description: >-
                Actionable values, such as `limit`, `used` and `resets_at` in
                `message_quota_exceeded`, or `reason`, which tells apart the
                causes behind one code, in errors such as `invalid_recipient`
                and `template_variables_invalid`. See [Actionable
                details](/en/errors/overview#actionable-details).
            request_id:
              type: string
              description: Request ID. Quote it when you contact support.
              example: req_01J8ZK9M3Q7XABCDEFGHJKMNPQ
          description: Error details.
      required:
        - error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Project API key, in the format `rt_live_...` or `rt_test_...`, sent as
        `Authorization: Bearer <key>`.

````

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