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

# Upload an attachment

> Upload binary attachment bytes and receive a temporary attachment_id for use in attachments[]. Requires `email.send` permission.



## OpenAPI

````yaml https://smtp.sendmux.ai/api/v1/openapi.json post /emails/attachments
openapi: 3.1.0
info:
  title: Sendmux Sending API
  version: 1.0.0
  description: >-
    Send emails programmatically via the Sendmux email infrastructure. Every
    response carries an `X-Request-Id` header; errors include a `retryable`
    flag. 429 and 503 responses include `Retry-After`. Mutating endpoints accept
    an `Idempotency-Key` header for safe retries.
servers:
  - url: https://smtp.sendmux.ai/api/v1
    description: Production
security:
  - BearerAuth: []
paths:
  /emails/attachments:
    post:
      tags:
        - Attachments
      summary: Upload an attachment
      description: >-
        Upload binary attachment bytes and receive a temporary attachment_id for
        use in attachments[]. Requires `email.send` permission.
      operationId: sendingUploadAttachment
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            type: string
            maxLength: 255
          description: >-
            Optional client-generated key to make the request idempotent for 24
            hours. Replays under the same key return the cached response; a
            reused key with a different body returns 409 idempotency_conflict.
          example: order-12345-2026-04-24
        - name: Content-Length
          in: header
          required: true
          schema:
            type: integer
            format: int64
            minimum: 1
          description: Exact number of bytes in the binary request body.
          example: 20480
        - name: filename
          in: query
          required: true
          schema:
            type: string
            minLength: 1
            maxLength: 255
          description: Filename to associate with the uploaded attachment.
          example: analysis.pdf
        - name: content_type
          in: query
          required: false
          schema:
            type: string
            maxLength: 255
          description: MIME type override for the uploaded attachment.
          example: application/pdf
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
      responses:
        '201':
          description: Attachment uploaded successfully
          headers:
            Location:
              description: Canonical URL for the temporary uploaded attachment metadata.
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AttachmentUploadResponse'
        '400':
          description: Missing or invalid upload metadata
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Insufficient permissions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: Idempotency conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '413':
          description: Attachment exceeds the upload size cap
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Attachment validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Attachment storage temporarily unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    AttachmentUploadResponse:
      allOf:
        - $ref: '#/components/schemas/SuccessEnvelope'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/AttachmentUploadData'
          required:
            - data
      unevaluatedProperties: false
    ErrorResponse:
      type: object
      properties:
        ok:
          type: boolean
          enum:
            - false
        error:
          $ref: '#/components/schemas/ErrorDetail'
        meta:
          $ref: '#/components/schemas/Meta'
      required:
        - ok
        - error
        - meta
      additionalProperties: false
    SuccessEnvelope:
      type: object
      properties:
        ok:
          type: boolean
          enum:
            - true
        meta:
          $ref: '#/components/schemas/Meta'
      required:
        - ok
        - meta
    AttachmentUploadData:
      type: object
      properties:
        attachment_id:
          type: string
          pattern: ^att_[a-z0-9]{24}$
          description: Temporary attachment ID to use in email attachments[].
          example: att_tz4a98xxat96iws9zmbrgj3a
        filename:
          type: string
          description: Stored attachment filename
          example: analysis.pdf
        content_type:
          type: string
          description: Stored attachment MIME type
          example: application/pdf
        size_bytes:
          type: integer
          description: Stored attachment byte size
          example: 20480
        expires_at:
          type: string
          format: date-time
          description: ISO timestamp when this temporary attachment reference expires.
          example: '2026-07-07T08:15:00.000Z'
      required:
        - attachment_id
        - filename
        - content_type
        - size_bytes
        - expires_at
      additionalProperties: false
    ErrorDetail:
      type: object
      properties:
        code:
          type: string
          description: Machine-readable error code
          example: validation_error
        message:
          type: string
          description: Human-readable error description
        param:
          type: string
          description: Parameter that caused the error
        doc_url:
          type: string
          format: uri
          description: Link to error documentation
        retryable:
          type: boolean
          description: >-
            True when the client may safely retry the same request. 429 and 5xx
            default true; 4xx default false.
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ErrorIssue'
          description: Accumulated per-field issues (validation errors)
      required:
        - code
        - message
        - retryable
      additionalProperties: false
    Meta:
      type: object
      properties:
        request_id:
          type: string
          description: Unique request identifier
          example: req_clxxxxxxxxxxxxxxxxxxxxxxxxx
      required:
        - request_id
      additionalProperties: false
    ErrorIssue:
      type: object
      properties:
        field:
          type: string
          description: Dot-path to the failing field
          example: to.email
        code:
          type: string
          description: Issue code from the validator
          example: invalid_string
        message:
          type: string
          description: Human-readable issue message
      required:
        - field
        - code
        - message
      additionalProperties: false
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Sendmux API key (smx_...)

````