# The machine-readable contract for the customer-facing Send API —
# api.mailway.net (live) / api.mailway.dev (sandbox).
#
# Hand-authored, code-verified: tests/Core/OpenApiContractTest.php makes
# real requests against the routes and validates the responses against
# these schemas on every suite run, so code and spec cannot drift
# silently. When either side changes, change both in the same commit.
#
# Published at https://mailway.net/openapi.yaml — mailway-landing serves
# a vendored copy (public/openapi.yaml); update it in the same wave.
#
# Scope: the bearer-token send surface only. The console API
# (api.console.mailway.net) and the SMTP ingest are internal contracts
# and deliberately not described here; the anonymous landing-form
# endpoints (/v1/consent, /v1/contact, /v1/waitlist) are not part of
# the customer contract either.
openapi: 3.1.0

info:
  title: Mailway Send API
  version: 1.0.0
  summary: One endpoint in front of the email providers you already own.
  description: |
    Mailway is a provider-neutral email gateway: you bring your own
    provider accounts (Amazon SES, SendGrid, Mailgun, Postmark, Brevo,
    Mandrill, Gmail, or any SMTP server), and Mailway routes, fails
    over, archives, and evidences every message.

    A `202` from this API means Mailway **accepted and durably stored**
    the message — it says nothing about delivery. Provider handoffs and
    recipient-server delivery events arrive asynchronously via
    [webhooks](https://mailway.net/docs/webhooks) and the console;
    provider-accepted and delivered are different claims and are never
    blurred.

    The human-readable reference lives at
    [mailway.net/docs/api/send](https://mailway.net/docs/api/send); the
    error-code catalog at
    [mailway.net/docs/api/errors](https://mailway.net/docs/api/errors).
  contact:
    name: Mailway
    url: https://mailway.net/contact

externalDocs:
  description: Send API reference
  url: https://mailway.net/docs/api/send

servers:
  - url: https://api.mailway.net
    description: Production — accepts `mw_live_…` keys only.
  - url: https://api.mailway.dev
    description: >-
      Sandbox — accepts `mw_test_…` keys only. Messages are validated,
      stored, and visible in the console with a sandbox badge, but never
      forwarded automatically (`status: captured`).

security:
  - bearerApiKey: []

paths:
  /v1/send:
    post:
      operationId: sendMessage
      summary: Send a message
      description: |
        Validates, durably stores, and queues one message for sending
        through the project's providers. The key *is* the project
        selection — there is no project field in the body.

        Pass an `Idempotency-Key` header to make retries safe: a
        repeated key returns the `202` of the mail it first created
        instead of sending again (first body wins; keys are unique per
        project).
      externalDocs:
        url: https://mailway.net/docs/api/send
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Message'
      responses:
        '202':
          description: >-
            Accepted and durably stored. Not a delivery claim — track
            provider handoff and delivery via webhooks or the console.
          headers:
            RateLimit-Policy:
              $ref: '#/components/headers/RateLimit-Policy'
            RateLimit:
              $ref: '#/components/headers/RateLimit'
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendAccepted'
        '400':
          $ref: '#/components/responses/ContentEncodingError'
        '401':
          $ref: '#/components/responses/AuthenticationError'
        '402':
          $ref: '#/components/responses/QuotaError'
        '413':
          $ref: '#/components/responses/PayloadTooLargeError'
        '422':
          $ref: '#/components/responses/UnprocessableError'
        '429':
          $ref: '#/components/responses/RateLimitError'
        '500':
          $ref: '#/components/responses/ServerError'

  /v1/send/batch:
    post:
      operationId: sendBatch
      summary: Send up to 100 messages in one request
      description: |
        Each element of `messages` is validated against the exact
        `/v1/send` message schema and is an **independent** send: one
        failing element never sinks the rest, which is why the response
        is `207 Multi-Status`. `data` is an array in request order —
        each slot is either `{id, status}` or the surface's standard
        error envelope for that element. Check per element; don't
        assume all-or-nothing.

        `Idempotency-Key` is not honored on batch. Each accepted
        element counts against plan quotas.
      externalDocs:
        url: https://mailway.net/docs/api/send#batch
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - messages
              properties:
                messages:
                  type: array
                  minItems: 1
                  maxItems: 100
                  description: >-
                    A JSON array; an object here is refused
                    (`messages:invalid`).
                  items:
                    $ref: '#/components/schemas/Message'
      responses:
        '207':
          description: Per-element results, in request order.
          headers:
            RateLimit-Policy:
              $ref: '#/components/headers/RateLimit-Policy'
            RateLimit:
              $ref: '#/components/headers/RateLimit'
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchResponse'
        '400':
          $ref: '#/components/responses/ContentEncodingError'
        '401':
          $ref: '#/components/responses/AuthenticationError'
        '402':
          $ref: '#/components/responses/QuotaError'
        '413':
          $ref: '#/components/responses/PayloadTooLargeError'
        '422':
          $ref: '#/components/responses/UnprocessableError'
        '429':
          $ref: '#/components/responses/RateLimitError'
        '500':
          $ref: '#/components/responses/ServerError'

  /v1/send/mime:
    post:
      operationId: sendMime
      summary: Send a raw message
      description: |
        Takes a message your app built (RFC 5322, as a mail library
        writes it) and relays it the way Mailway's SMTP relay does:
        byte-for-byte, apart from the automatic exceptions listed at
        [mailway.net/docs/smtp](https://mailway.net/docs/smtp#what-happens-to-your-message).
        On receipt, a missing `Message-ID` is added, made from the mail
        ID (`<m.…@mailway.net>`, `@mailway.dev` on the sandbox), a
        missing `Date` is added as the time Mailway received the
        message, and `Bcc` and `Resent-Bcc` fields are removed. Bare line
        feeds and bare carriage returns become CRLF.

        `meta.recipients` is the envelope, as SMTP's `RCPT TO`: everyone
        who gets the mail, Bcc recipients included. The message's own
        `To` and `Cc` fields only control what recipients see, so an
        address that isn't in `meta.recipients` doesn't get the mail.

        A message with no `From` field, a NUL byte, a bare carriage
        return in the header block, or a header line that starts with a
        dot is refused (`message:*`). `scheduled_at`, `routing`, and
        `provider_options` can't be set on this endpoint yet
        (`<field>:unsupported`). Use `/v1/send` for them.

        The project needs at least one attached provider account that
        can carry a raw message: one that sends over SMTP, an Amazon SES
        or Mailgun account, or an account an admin enabled re-encoding
        on for the project. Otherwise the request is refused with
        `no_raw_mime_provider`.
      externalDocs:
        url: https://mailway.net/docs/api/send#send-a-raw-message
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - message
                - meta
              properties:
                message:
                  type: string
                  format: binary
                  description: >-
                    The raw message, as a file part. A text field is
                    refused (`message:not_a_file`). At most 25 MB
                    (`body:too_large`, 413).
                meta:
                  $ref: '#/components/schemas/MimeMeta'
            encoding:
              meta:
                contentType: application/json
      responses:
        '202':
          description: >-
            Mailway received and stored the mail. This is not a delivery
            claim: follow the mail in the console or through webhooks
            (`mail.sent` when a provider accepts it, `mail.delivered` when a
            delivery event confirms it).
          headers:
            RateLimit-Policy:
              $ref: '#/components/headers/RateLimit-Policy'
            RateLimit:
              $ref: '#/components/headers/RateLimit'
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendAccepted'
        '400':
          $ref: '#/components/responses/UnreadableRequestError'
        '401':
          $ref: '#/components/responses/AuthenticationError'
        '402':
          $ref: '#/components/responses/QuotaError'
        '413':
          $ref: '#/components/responses/PayloadTooLargeError'
        '422':
          $ref: '#/components/responses/UnprocessableError'
        '429':
          $ref: '#/components/responses/RateLimitError'
        '500':
          $ref: '#/components/responses/ServerError'

# Outbound lifecycle webhooks — the requests Mailway makes TO your
# endpoint. Endpoints and their signing secrets (`whsec_…`) are managed
# in the console; full guide at https://mailway.net/docs/webhooks.
webhooks:
  mailEvent:
    post:
      operationId: mailEvent
      summary: A mail lifecycle event delivered to your endpoint
      description: |
        One envelope for every event type. Events are normalized across
        providers — a `mail.bounced` looks the same whether Amazon SES
        or Mailtrap reported the underlying bounce.

        **Verify before trusting**: every delivery is signed with your
        endpoint's secret. Recompute `HMAC-SHA256("{t}.{raw_body}",
        secret)` over the raw request body bytes, compare it in constant
        time against each `v1` value in the header (accept the delivery
        if any one matches), and reject stale timestamps (5 minutes is a
        good tolerance).

        Delivery is **at-least-once**: deduplicate on `data.event_id`.
        Failed deliveries retry on a backoff ladder (up to six attempts,
        over about 8.6 hours when your endpoint answers in under
        5 seconds); an endpoint that keeps failing for 24 hours is
        disabled automatically.

        This is version 1 of the payload (`X-Mailway-Webhook-Version:
        1`). Mailway adds fields and event types within version 1, so
        ignore any field or event type you don't know.
      parameters:
        - name: X-Mailway-Signature
          in: header
          required: true
          description: >-
            `t=<unix timestamp>,v1=<hex HMAC-SHA256 of "{t}.{raw_body}">`.
            Mailway sends one `v1` today. Treat the delivery as authentic
            if any `v1` in the header matches, so your code keeps working
            if a later version sends two (`t=…,v1=…,v1=…`, for example
            while a secret rotates).
          schema:
            type: string
        - name: X-Mailway-Webhook-Version
          in: header
          required: true
          description: >-
            The payload's version, `1`. Fields and event types added
            later keep it at `1`.
          schema:
            type: string
            enum: ['1']
        - name: X-Mailway-Event
          in: header
          required: true
          description: The event type, mirroring `type` in the body.
          schema:
            type: string
        - name: X-Mailway-Delivery
          in: header
          required: true
          description: The delivery id (`we.…`), stable across retries of one delivery.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WebhookDelivery'
      responses:
        '200':
          description: >-
            Any 2xx within 10 seconds counts as delivered; redirects are
            not followed. Acknowledge fast and process async.

components:
  securitySchemes:
    bearerApiKey:
      type: http
      scheme: bearer
      description: |
        Per-project API key, shown once at creation and stored hashed:
        `mw_live_…` (production) or `mw_test_…` (sandbox), 40
        alphanumeric characters after the prefix. Live keys work only on
        `api.mailway.net`, test keys only on `api.mailway.dev` — the
        host binding is deliberate (`mode_mismatch` otherwise), so a
        misconfigured environment variable can't send real mail from a
        test suite.

  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        12–40 characters of `[A-Za-z0-9_-]` (UUIDs, ULIDs, and base64url
        tokens all pass). Unique per project, and a key never expires: it
        is used once, for the life of the project. A repeated key returns
        the 202 of the mail it first created instead of sending again
        (first body wins), with `status` and `paused` as they are now. The
        body is validated before the key is looked up, so a retry whose
        body fails validation gets that 422, not the original 202 (never a
        409). Not honored on `/v1/send/batch`.
      schema:
        type: string
        minLength: 12
        maxLength: 40
        pattern: '^[A-Za-z0-9_-]+$'

  headers:
    RateLimit-Policy:
      description: >-
        The rate-limit policy for this endpoint, as an IETF
        RateLimit-Policy field (draft-ietf-httpapi-ratelimit-headers):
        `"api-send";q=600;w=60` is 600 requests per 60-second window.
        `X-RateLimit-Limit` carries the same quota.
      schema:
        type: string
        example: '"api-send";q=600;w=60'
    RateLimit:
      description: >-
        What's left of the quota: use at most `r` more requests in the
        next `t` seconds. `t` is never shorter than the time to the
        window's reset, and is stretched so `r`/`t` never exceeds the
        policy's `q`/`w`. On a 429, `r` is 0 and `t` equals
        `Retry-After`. `X-RateLimit-Remaining` carries the same `r`.
      schema:
        type: string
        example: '"api-send";r=599;t=60'
    X-RateLimit-Limit:
      description: Requests allowed per window.
      schema:
        type: integer
    X-RateLimit-Remaining:
      description: Requests left in the current window.
      schema:
        type: integer

  responses:
    ContentEncodingError:
      description: >-
        The body declares `Content-Encoding: gzip` or `br` but doesn't
        decode as that encoding (`content_encoding:invalid`). Compress
        the body with the declared encoding, or send plain JSON without
        the header. Also a request Mailway can't read at all
        (`request:invalid`, as described under UnreadableRequestError).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnreadableRequestError:
      description: >-
        Mailway couldn't read the request at all (`request:invalid`), so
        it never checked the fields one by one. The message is the same
        whatever the cause. Check the request's headers and fields against
        this specification. Retrying it unchanged won't help.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    PayloadTooLargeError:
      description: >-
        The request body is over the 25 MB limit, measured after
        decompression for a gzip or `br` body (`body:too_large`). On
        `/v1/send/mime` it is the `message` file. Send smaller
        attachments, or split a batch into smaller requests.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ServerError:
      description: >-
        Mailway failed on its side (`api_error` / `server_error`). The
        body never carries the failure's details. Retry with backoff,
        with the same `Idempotency-Key` on `/v1/send` and
        `/v1/send/mime` so a retry can't send the mail twice.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    AuthenticationError:
      description: >-
        Missing or invalid API key (`missing_api_key`,
        `invalid_api_key`, `key_expired`), or a key used on the wrong
        host (`mode_mismatch`).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    QuotaError:
      description: >-
        A plan limit was reached (`monthly_quota_exceeded`,
        `throughput_quota_exceeded`), the plan doesn't include the
        feature asked for (`scheduling_unavailable`: `scheduled_at` below
        Pro), or the team is a second Free team of the person who created
        it (`free_team_limit`: only one Free team per person sends, and a
        second one sends once it is on a paid plan). This is a billing
        state, not a bug: retrying won't help until the month rolls over
        or the plan changes.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnprocessableError:
      description: >-
        The request can't succeed as sent: field validation
        (`error.details` lists each failing field), a project with no
        providers (`no_providers_configured`), a project with no provider
        that can carry a raw message (`no_raw_mime_provider`), a message
        `/v1/send/mime` refuses (`message:*`, `sender:required`), a pin to
        an unattached
        provider (`routing_provider_not_configured`), a suppressed
        recipient (`suppressed_recipient`), or a cap
        (`sender_domain:limit_reached`, `category:limit_reached`,
        `tags:limit_reached`). Fix the payload or the project; don't
        retry blindly.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimitError:
      description: >-
        Too many requests (`rate_limited` — honor `Retry-After`), or the
        Free plan's daily limit (`daily_send_cap_exceeded` — resets at
        00:00 UTC). Budgets are per key: 600 requests/min on `/v1/send`
        and `/v1/send/mime` together, 6/min on `/v1/send/batch` (the same 600-message budget either
        way). Requests without a valid key fall back to a much tighter
        per-IP bucket.
      headers:
        Retry-After:
          description: Seconds to wait before retrying (on `rate_limited`).
          schema:
            type: integer
        RateLimit-Policy:
          $ref: '#/components/headers/RateLimit-Policy'
        RateLimit:
          $ref: '#/components/headers/RateLimit'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'

  schemas:
    Address:
      description: >-
        An email address in any of three forms: `"a@b.com"`,
        or `{"email": "a@b.com", "name": "Name"}` (the `"Name <a@b.com>"` string form is not accepted yet).
      oneOf:
        - type: string
          description: 'A bare address, `a@b.com`'
          maxLength: 254
        - type: object
          required:
            - email
          properties:
            email:
              type: string
              format: email
              maxLength: 254
            name:
              type: string
              maxLength: 254
          additionalProperties: false

    Recipients:
      description: A single address or an array of addresses.
      oneOf:
        - $ref: '#/components/schemas/Address'
        - type: array
          items:
            $ref: '#/components/schemas/Address'

    Attachment:
      type: object
      required:
        - filename
        - content
      properties:
        filename:
          type: string
          maxLength: 255
        content:
          type: string
          contentEncoding: base64
          description: >-
            Base64-encoded bytes. The limits are on **decoded** size: 10 MB
            per attachment (`attachments:too_large`) and 18.75 MB for all
            of a message's attachments together
            (`attachments:total_too_large`). Base64 makes attachments a
            third larger, so a 25 MB request body holds at most 18.75 MB
            of them. A request with more is over the body limit, which
            answers first (`body:too_large`, 413). An MB here is
            1,048,576 bytes.
        content_type:
          type:
            - string
            - 'null'
          maxLength: 255
          description: >-
            A media type, `type/subtype` (e.g. `application/pdf`),
            optionally with `; name=value` parameters of plain tokens
            (`text/csv; charset=utf-8`). A value without a subtype, a
            quoted parameter, or a `multipart/*` type is refused
            (`attachments.content_type:invalid`). Defaults to
            `application/octet-stream`.
        content_id:
          type:
            - string
            - 'null'
          maxLength: 255
          description: >-
            For inline images — reference it from the HTML as
            `cid:<content_id>` and set `disposition: inline`. Printable
            ASCII that makes a valid message ID: `logo` (sent as
            `logo@mailway`) or `logo@example.com`, without angle
            brackets, spaces, or a doubled dot
            (`attachments.content_id:invalid`).
        disposition:
          type:
            - string
            - 'null'
          enum:
            - attachment
            - inline
            - null
      additionalProperties: false

    Routing:
      type: object
      description: >-
        Per-message routing overrides. Unknown keys are rejected
        (`routing:unknown_key`). A pin is never silently rerouted — a
        pinned provider that isn't attached to the project is a 422
        (`routing_provider_not_configured`), not a fallback.
      properties:
        provider:
          description: >-
            Pin the send to one provider family, or an ordered preference
            list (duplicates rejected). The pin names the provider account
            (e.g. `mailtrap`); Mailway picks SMTP or API per send from what
            that account can use. An account of that family must be
            attached to the project.
          oneOf:
            - $ref: '#/components/schemas/ProviderFamily'
            - type: array
              items:
                $ref: '#/components/schemas/ProviderFamily'
        strategy:
          type:
            - string
            - 'null'
          enum:
            - fallback
            - round-robin
            - random
            - free-first
            - null
          description: Override the project's provider-selection strategy for this send.
      additionalProperties: false

    ProviderFamily:
      type: string
      description: >-
        A provider account's family. One account can send over SMTP and
        over the provider's API; which one a message used is reported
        per send as `transport`.
      enum:
        - amazon-ses
        - sendgrid
        - mailgun
        - mandrill
        - postmark
        - brevo
        - gmail
        - mailtrap
        - smtp
        - resend
        - mailjet
        - mailersend
        - nuntly
        - smtp2go

    Transport:
      type: string
      description: How a send left the provider account.
      enum:
        - smtp
        - api

    ProviderOptions:
      type: object
      description: >-
        Provider-specific extras keyed by provider family,
        allowlist-validated: unknown families
        (`provider_options:unknown_provider`) and unknown option keys
        (`provider_options:unknown_option`) are rejected, never silently
        dropped. Only header-mappable options are accepted — an option
        Mailway can't actually apply would be a 202 that lies. They apply
        whichever transport the send uses.
      properties:
        amazon-ses:
          type: object
          properties:
            configuration_set:
              type: string
              maxLength: 255
          additionalProperties: false
        postmark:
          type: object
          properties:
            message_stream:
              type: string
              maxLength: 255
          additionalProperties: false
      additionalProperties: false

    Message:
      type: object
      description: >-
        One message. Unknown top-level keys are rejected
        (`body:unknown_key`) — a typo like `pasued` fails loudly at the
        boundary instead of silently no-opping. At least one of `html`
        or `text` is required (`body:required`); at most 50 recipients
        combined across `to`/`cc`/`bcc` (`recipients:too_many`). Every
        string, at any depth, is trimmed of leading and trailing
        whitespace, and an empty string is treated as absent: a
        `metadata` value of `""` is `metadata:value_invalid`, a header
        value of `""` is `headers:invalid`, a whitespace-only `html` with
        no `text` is `body:required`, and a blank `scheduled_at` sends
        now.
      required:
        - from
        - to
        - subject
      anyOf:
        - required:
            - html
        - required:
            - text
      properties:
        from:
          $ref: '#/components/schemas/Address'
        to:
          $ref: '#/components/schemas/Recipients'
        cc:
          $ref: '#/components/schemas/Recipients'
        bcc:
          $ref: '#/components/schemas/Recipients'
        reply_to:
          $ref: '#/components/schemas/Recipients'
        subject:
          type: string
          maxLength: 989
          description: >-
            Required. ≤ 989 characters, so the `Subject:` line fits RFC
            5322's 998-character line even when the subject has no space
            to fold at. It goes out whole. The console, share links,
            webhook events, exports, and certificates show its first 255
            characters.
        html:
          type:
            - string
            - 'null'
          maxLength: 2097152
          description: ≤ 2 MB. Send both `html` and `text` when you can.
        text:
          type:
            - string
            - 'null'
          maxLength: 2097152
          description: ≤ 2 MB.
        headers:
          type:
            - object
            - 'null'
          description: >-
            Custom headers (e.g. `List-Unsubscribe`). Header names Mailway
            sets or builds from other fields are reserved and rejected
            (`headers:reserved`): From, Sender, To, Cc, Bcc, Reply-To,
            Subject, Date, Message-ID, Return-Path, Received,
            DKIM-Signature, Content-Type, Content-Transfer-Encoding,
            MIME-Version, and the `X-Mailway-*` prefix. Each header can be
            set once: naming one twice in different case (`X-Tag` and
            `x-tag`) is rejected (`headers:invalid`). A project rule's
            `add_header` replaces a header of the same name, whatever its
            case.
          additionalProperties:
            type: string
            maxLength: 8192
        attachments:
          type:
            - array
            - 'null'
          maxItems: 20
          description: >-
            A JSON array; an object here is refused
            (`attachments:invalid`).
          items:
            $ref: '#/components/schemas/Attachment'
        tags:
          type:
            - array
            - 'null'
          maxItems: 10
          description: >-
            Labels for groups of mails (e.g. `password-reset`). They
            become the project's tags (console filters, `tag_present`
            rules) and come back on every webhook event as
            `data.mail.tags`. Case doesn't matter within a project; events
            show the spelling used first. Once the project has 1,000
            distinct tags, a new name is rejected (`tags:limit_reached`);
            reusing a tag always works. A JSON array; an object here is
            refused (`tags:invalid`).
          items:
            type: string
            maxLength: 64
            pattern: '^[A-Za-z0-9_-]+$'
        metadata:
          type:
            - object
            - 'null'
          maxProperties: 10
          description: >-
            Your own values for this one mail (order IDs, user IDs),
            sent back on every webhook event as `data.mail.metadata`.
            Deleted with the mail's content when its retention period
            ends; webhook deliveries already built keep their copy for 30
            days. Keys ≤ 40 chars, string values ≤ 500 chars. Key order
            isn't kept.
          propertyNames:
            maxLength: 40
          additionalProperties:
            type: string
            maxLength: 500
        category:
          type:
            - string
            - 'null'
          minLength: 1
          maxLength: 64
          description: >-
            One per mail — the reporting bucket per-category stats
            group by (e.g. "Password reset"). Letters/digits first
            character; letters, digits, space, `_-./:` after.
            Case-sensitive and verbatim. A project holds at most 100
            distinct categories — reusing one is free, a new name past
            the cap is rejected (`category:limit_reached`). Use
            `category` for reporting, `tags` for groups of mails, and
            `metadata` to match events to your own records.
        scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            An RFC 3339 date-time with an offset or `Z` (e.g.
            `2026-08-04T09:00:00Z` or `2026-08-04T11:00:00+02:00`;
            fractional seconds allowed). Anything else, a relative value
            like `+1 hour` or `tomorrow` included, is refused
            (`scheduled_at:invalid`). Must be in the future and at most 72
            hours out (`scheduled_at:too_soon` / `scheduled_at:too_late`).
            Mailway stores and echoes it as the UTC instant it names.
        paused:
          type:
            - boolean
            - 'null'
          description: >-
            Accept + store the message but hold it until released in the
            console.
        routing:
          oneOf:
            - $ref: '#/components/schemas/Routing'
            - type: 'null'
        provider_options:
          oneOf:
            - $ref: '#/components/schemas/ProviderOptions'
            - type: 'null'
      additionalProperties: false

    MimeMeta:
      type: object
      description: >-
        The envelope and options of a `/v1/send/mime` request: a JSON
        object in the `meta` part, sent as a text field or a small JSON
        file part. Unknown keys are refused (`meta:unknown_key`). As on
        `/v1/send`, every string is trimmed and an empty one is treated
        as absent.
      required:
        - recipients
      properties:
        recipients:
          type: array
          minItems: 1
          maxItems: 1000
          description: >-
            The envelope recipients: everyone who gets the mail, Bcc
            recipients included. An address listed twice gets the mail
            once. A JSON array; an object here is refused
            (`recipients:invalid`).
          items:
            type: string
            format: email
            maxLength: 254
        sender:
          type: string
          format: email
          maxLength: 254
          description: >-
            The envelope sender (SMTP's `MAIL FROM`). Defaults to the
            address in the `From` field.
        category:
          $ref: '#/components/schemas/Message/properties/category'
        tags:
          $ref: '#/components/schemas/Message/properties/tags'
        metadata:
          $ref: '#/components/schemas/Message/properties/metadata'
        paused:
          $ref: '#/components/schemas/Message/properties/paused'
      additionalProperties: false

    SendAccepted:
      type: object
      required:
        - id
        - status
        - scheduled_at
        - paused
        - category
        - project_id
        - routing
      properties:
        id:
          type: string
          pattern: '^m\.'
          description: >-
            The message's permanent identifier — it threads through the
            console, webhook events, and the public viewer.
        status:
          type: string
          enum:
            - queued
            - scheduled
            - paused
            - captured
            - rejected
          description: >-
            `queued` — received, to be sent now; `scheduled` —
            `scheduled_at` is set; `paused` — held (the `paused` flag, or
            the project is paused); `captured` — a sandbox send, stored
            but never auto-forwarded; `rejected` — Mailway won't send this
            mail. On the first answer that means a rule refused it on
            arrival (its `mail.failed` webhook event names the rule). A
            retry with the same `Idempotency-Key` reports the mail's hold
            or rejection state when it arrives, so there `rejected` can
            also mean a person rejected it in the console, a recipient was
            on the suppression list when it was due, a provider
            permanently refused its only recipient, or its project was
            deleted before it was due. Its webhook event says which:
            `mail.failed` with a reason, or `mail.suppressed` for the
            suppression list. The answer never says what a provider did:
            a mail a provider accepted, and a mail whose every attempt
            failed, both come back as `queued` (or `scheduled`). Follow
            delivery through webhooks or the console.
        scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            The request's `scheduled_at` as the UTC instant it names, e.g.
            `2026-08-04T09:00:00Z` for `2026-08-04T11:00:00+02:00`.
            Milliseconds (`.250Z`) appear only when the request had a
            fraction of a second; finer digits are dropped.
        paused:
          type: boolean
          description: >-
            The mail's actual held state — also `true` when the project
            itself is paused, not just when the request asked for it.
        category:
          type:
            - string
            - 'null'
          description: Echo of the request field.
        project_id:
          type: string
          pattern: '^p\.'
        routing:
          type: object
          required:
            - provider
            - strategy
          properties:
            provider:
              description: Echo of the request field.
              oneOf:
                - type: string
                - type: array
                  items:
                    type: string
                - type: 'null'
            strategy:
              type:
                - string
                - 'null'
              description: Echo of the request field.
          additionalProperties: false
      additionalProperties: false

    BatchAccepted:
      type: object
      required:
        - id
        - status
      properties:
        id:
          type: string
          pattern: '^m\.'
        status:
          type: string
          enum:
            - queued
            - scheduled
            - paused
            - captured
            - rejected
      additionalProperties: false

    BatchResponse:
      type: object
      required:
        - data
      properties:
        data:
          type: array
          description: >-
            One slot per input message, in request order — correlate by
            position (`data[i]` ↔ `messages[i]`). Each slot is either an
            accepted send or the surface's standard error envelope
            (persistence failures surface as `api_error` /
            `server_error`: retry just that element).
          items:
            oneOf:
              - $ref: '#/components/schemas/BatchAccepted'
              - $ref: '#/components/schemas/Error'
      additionalProperties: false

    Error:
      type: object
      description: >-
        The surface's one error envelope. Branch on `error.code` — it's
        stable; `error.message` is for humans and may change. Field
        validation carries `error.details` listing every failing field
        (`error.code` mirrors the first).
      required:
        - error
      properties:
        error:
          type: object
          required:
            - type
            - code
            - message
          properties:
            type:
              type: string
              enum:
                - authentication_error
                - quota_error
                - permission_error
                - validation_error
                - rate_limit_error
                - api_error
            code:
              type: string
              description: >-
                Stable, branchable code — e.g. `invalid_api_key`,
                `monthly_quota_exceeded`, `suppressed_recipient`,
                `from:required`, `idempotency_key:invalid`. A path the
                API doesn't serve answers 404 `route_not_found`, and a
                wrong method 405 `method_not_allowed`, in this same
                envelope. The full catalog: https://mailway.net/docs/api/errors
            message:
              type: string
            details:
              type: array
              description: Present on field-validation failures.
              items:
                type: object
                required:
                  - field
                  - code
                properties:
                  field:
                    type: string
                    description: >-
                      The failing field's dotted path, e.g. `subject`,
                      `to.1`, `attachments.0.filename`.
                  code:
                    type: string
                    description: >-
                      `<field>:<reason>`, with the field named without
                      its index, so the set of codes is fixed: `to.1`
                      fails as `to:invalid`, `attachments.0.filename` as
                      `attachments.filename:required`.
                additionalProperties: false
          additionalProperties: false
      additionalProperties: false

    WebhookDelivery:
      type: object
      description: >-
        One envelope for every event type (version 1). `data.event_id`
        and `data.occurred_at` are on every event; `data.mail` is on
        every event except `webhook.test`; the other `data` fields
        appear on the event types named in their descriptions. The
        `tags` and `metadata` of a mail sent through the HTTP API come
        back on every event. The envelope is open: Mailway adds fields
        within version 1, so ignore any field you don't know.
      required:
        - id
        - type
        - created_at
        - data
      properties:
        id:
          type: string
          pattern: '^we\.'
          description: >-
            The delivery id. Stable across retries and redeliveries of
            this delivery. The same event can be delivered again under a
            new id, so deduplicate on `data.event_id`, not on this.
        type:
          description: >-
            `mail.accepted`: Mailway received the mail. `mail.sent`: a
            provider accepted it. `mail.delivered`: the provider's
            delivery event confirmed delivery to the recipient's mail
            server. `mail.bounced` / `mail.complained`: the provider
            reported a bounce or a spam complaint. `mail.delayed`: the
            provider reported a delay and is still trying.
            `mail.failed`: rejected, or every attempt failed
            (`data.reason` says which). `mail.suppressed`: the project's
            suppression list blocked it. `webhook.test`: the console's
            Send test button. Mailway can add event types within
            version 1; ignore one you don't know.
          anyOf:
            - type: string
              enum:
                - mail.accepted
                - mail.sent
                - mail.delivered
                - mail.bounced
                - mail.delayed
                - mail.complained
                - mail.failed
                - mail.suppressed
                - webhook.test
            - type: string
        created_at:
          type: string
          format: date-time
          description: When Mailway built this delivery.
        data:
          type: object
          required:
            - event_id
            - occurred_at
          properties:
            event_id:
              type: string
              pattern: '^ev\.[0-7][0-9a-hjkmnp-tv-z]{25}$'
              description: >-
                The event's id: the same on every delivery of this event
                (retries, redeliveries, a delivery Mailway sends again
                under a new `id`, and every endpoint that receives the
                event), and different for every other event. Deduplicate
                on it. Each provider delivery event is its own event with
                its own `event_id`, so one mail can get several
                `mail.bounced`, one for each bounce the provider reports.
            occurred_at:
              type: string
              format: date-time
              description: >-
                When the event happened, in UTC: the provider's time for
                `mail.delivered`, `mail.bounced`, `mail.delayed`, and
                `mail.complained` (when Mailway received the provider's
                event if it gave no time), and Mailway's own time for the
                others. Not `created_at`, which is when this delivery was
                built.
            reason:
              description: >-
                On `mail.failed` only: what ended the mail. See
                https://mailway.net/docs/webhooks#why-a-mail-failed.
                Mailway can add values; treat one you don't know as a
                failure.
              anyOf:
                - type: string
                  enum: [rule, person, smtp_credential_revoked, project_deleted, team_deletion, provider_refused, exhausted]
                - type: string
            error_type:
              description: >-
                On `mail.failed` with `reason` `provider_refused`
                (always `hard_bounce`) or `exhausted`: why the last
                attempt failed, as a stable code to branch on.
                `no_provider`: no provider could be tried. `internal`:
                the failure was inside Mailway, not a provider's answer.
                The others are the provider's answer, classified.
                Mailway can add values.
              anyOf:
                - type: string
                  enum: [auth, provider_quota, hard_bounce, soft_bounce, rate_limit, timeout, connection, unknown, no_provider, internal]
                - type: string
            error:
              type: string
              description: >-
                On `mail.failed` with `reason` `exhausted`: one sentence
                for people about `error_type`. Its wording can change;
                branch on `error_type`.
            bounce:
              type: string
              enum: [permanent, transient]
              description: >-
                On `mail.bounced` only: `permanent` (the recipient's
                server refused it for good; the address goes on the
                project's suppression list) or `transient` (refused for
                now, for example a full mailbox).
            recipients:
              type: array
              items:
                type: string
              description: >-
                On `mail.delivered`, `mail.bounced`, `mail.delayed`, and
                `mail.complained`: the recipients this provider event is
                about. A mail gets one event per provider event, so a
                mail to several recipients can get several events of one
                type. A provider can name several recipients in one
                event.
            diagnostic:
              type:
                - object
                - 'null'
              description: >-
                On `mail.delivered` (always null), `mail.bounced`,
                `mail.delayed`, and `mail.complained`: what the provider
                reported, normalized. `kind` is `bounce`, `delay`, or
                `complaint`; `recipients` lists each address with the
                receiving server's `status` and `diagnostic_code` where
                the provider gives them.
              additionalProperties: true
            suppressed:
              type: array
              items:
                type: string
              description: '`mail.suppressed` only: the recipients on the suppression list.'
            rule:
              type: object
              description: >-
                On `mail.failed` with `reason` `rule` only: the rule that
                rejected the mail.
              properties:
                uid:
                  type: string
                  pattern: '^r\.'
                name:
                  type: string
                  description: The name the rule had when it fired.
                reason:
                  type:
                    - string
                    - 'null'
                  description: The reason written on its reject action, or null if it has none.
              additionalProperties: true
            message:
              type: string
              description: '`webhook.test` only: a fixed line saying this is a test.'
            endpoint:
              type: string
              pattern: '^w\.'
              description: '`webhook.test` only: the id of the endpoint that was tested.'
            mail:
              type: object
              description: On every event except `webhook.test`.
              properties:
                uid:
                  type: string
                  pattern: '^m\.'
                subject:
                  type:
                    - string
                    - 'null'
                  description: Null when the mail has no subject.
                from:
                  type: string
                to:
                  type: array
                  items:
                    type: string
                project:
                  type:
                    - object
                    - 'null'
                  description: Null once the mail's project is deleted.
                  properties:
                    uid:
                      type: string
                      pattern: '^p\.'
                    name:
                      type: string
                tags:
                  type: array
                  description: >-
                    The send request's `tags`, plus any your rules added
                    (the `tag` action) and minus any they removed
                    (`untag`).
                  items:
                    type: string
                metadata:
                  type:
                    - object
                    - 'null'
                  description: >-
                    The send request's `metadata`, or null when it had
                    none or the mail's retention window has ended.
                  additionalProperties:
                    type: string
              additionalProperties: true
            provider:
              description: >-
                The provider account's family — on `mail.sent` the account
                that accepted the handoff; on delivery events the account
                that reported it, or null when that account was deleted
                before the event arrived. On `mail.failed` with `reason`
                `provider_refused`, the account that refused it. Mailway
                can add families.
              anyOf:
                - $ref: '#/components/schemas/ProviderFamily'
                - type: string
                - type: 'null'
            transport:
              description: '`mail.sent` only: how the handoff left that account.'
              $ref: '#/components/schemas/Transport'
          additionalProperties: true
      additionalProperties: true
