{
  "openapi": "3.1.0",
  "info": {
    "title": "SendHQ API",
    "version": "0.1.0",
    "description": "Transactional email control plane. Relative paths use the current MailForge deployment. API keys belong to one account and deployment environment."
  },
  "servers": [
    {
      "url": "/",
      "description": "Current MailForge deployment"
    }
  ],
  "tags": [
    {
      "name": "Service",
      "description": "Liveness and provider integration."
    },
    {
      "name": "Reference",
      "description": "Machine-readable reference and developer quickstarts."
    },
    {
      "name": "Emails",
      "description": "Transactional sends and their event histories."
    },
    {
      "name": "Domains",
      "description": "Sending-domain enrollment and DNS records."
    },
    {
      "name": "Webhooks",
      "description": "Signed outbound notifications."
    },
    {
      "name": "Metrics",
      "description": "Volume and delivery outcomes."
    },
    {
      "name": "Keys",
      "description": "Account- and environment-scoped credentials."
    },
    {
      "name": "Billing",
      "description": "Trial allowances, subscriptions and signed billing notifications."
    },
    {
      "name": "Authentication",
      "description": "Browser sessions and email sign-in."
    }
  ],
  "security": [
    {
      "BearerKey": []
    }
  ],
  "paths": {
    "/openapi.json": {
      "get": {
        "operationId": "getOpenApi",
        "summary": "Read the OpenAPI document",
        "tags": [
          "Reference"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 reference.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Check service liveness",
        "tags": [
          "Service"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "API process is running.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/emails": {
      "post": {
        "operationId": "sendEmail",
        "summary": "Queue one transactional email",
        "tags": [
          "Emails"
        ],
        "description": "Requires the send scope. Maximum request body is 1 MiB. Include html or text, or both.",
        "x-required-scope": "send",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "One visible ASCII value without spaces or commas. For 24 hours, retrying the same normalized email with this value replays its acknowledgement.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "pattern": "^[\\x21-\\x2B\\x2D-\\x7E]+$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendEmailRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Committed for dispatch or replayed from the idempotency cache.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AcceptedEmail"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "402": {
            "description": "upgrade_required for expired or inactive accounts, quota_exceeded when the current plan allowance is exhausted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "key_missing_scope or domain_not_verified.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "idempotency_conflict — The key was used for a different email.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMedia"
          },
          "422": {
            "description": "recipient_suppressed — The address is suppressed for this account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "get": {
        "operationId": "listEmails",
        "summary": "List email logs",
        "tags": [
          "Emails"
        ],
        "description": "Requires the read scope. ",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "Current email status.",
            "schema": {
              "$ref": "#/components/schemas/EmailStatus"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Exact recipient, case-insensitive.",
            "schema": {
              "type": "string",
              "format": "email",
              "maxLength": 254,
              "description": "One ASCII mailbox."
            }
          },
          {
            "name": "domain_id",
            "in": "query",
            "required": false,
            "description": "Filter by sending-domain UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "before",
            "in": "query",
            "required": false,
            "description": "Exclusive timestamp with timezone (up to six fractional digits), or the previous X-Next-Cursor.",
            "schema": {
              "type": "string",
              "maxLength": 70
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page size.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Newest emails first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/EmailSummary"
                  }
                }
              }
            },
            "headers": {
              "X-Next-Cursor": {
                "description": "Present only when more records exist. Send as before with the same filters.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/emails/{id}": {
      "get": {
        "operationId": "getEmail",
        "summary": "Read an email and its event history",
        "tags": [
          "Emails"
        ],
        "description": "Requires the read scope. ",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Resource UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Email and append-only events.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailDetail"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "404": {
            "description": "email_not_found — No visible email with this UUID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/domains": {
      "post": {
        "operationId": "createDomain",
        "summary": "Register a sending domain",
        "tags": [
          "Domains"
        ],
        "description": "Requires the send scope. Registration of the same account and normalized hostname returns its existing enrollment.",
        "x-required-scope": "send",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateDomainRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing enrollment.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Domain"
                }
              }
            }
          },
          "201": {
            "description": "Pending enrollment with DNS records.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Domain"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMedia"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      },
      "get": {
        "operationId": "listDomains",
        "summary": "List sending domains",
        "tags": [
          "Domains"
        ],
        "description": "Requires the read scope. ",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "before",
            "in": "query",
            "required": false,
            "description": "Exclusive timestamp with timezone (up to six fractional digits), or the previous X-Next-Cursor.",
            "schema": {
              "type": "string",
              "maxLength": 70
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page size.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Newest domains first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Domain"
                  }
                }
              }
            },
            "headers": {
              "X-Next-Cursor": {
                "description": "Present only when more records exist. Send as before with the same filters.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/domains/{id}": {
      "get": {
        "operationId": "getDomain",
        "summary": "Read sending-domain verification records",
        "tags": [
          "Domains"
        ],
        "description": "Requires the read scope. ",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Resource UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Domain and DNS verification records.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Domain"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "404": {
            "description": "domain_not_found — No visible domain with this UUID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/webhooks": {
      "post": {
        "operationId": "createWebhook",
        "summary": "Register a webhook receiver",
        "tags": [
          "Webhooks"
        ],
        "description": "Requires the webhooks:manage scope. ",
        "x-required-scope": "webhooks:manage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Endpoint and one-time signing secret.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedWebhook"
                }
              }
            }
          },
          "400": {
            "description": "invalid_webhook_url for an invalid registration or destination, or invalid_request for malformed JSON.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "409": {
            "description": "webhook_exists — The URL is already registered.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMedia"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      },
      "get": {
        "operationId": "listWebhooks",
        "summary": "List outbound webhook endpoints",
        "tags": [
          "Webhooks"
        ],
        "description": "Requires the read scope. ",
        "x-required-scope": "read",
        "responses": {
          "200": {
            "description": "Endpoint origins and current state, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WebhookSummary"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/webhooks/{id}": {
      "delete": {
        "operationId": "deleteWebhook",
        "summary": "Remove a webhook receiver",
        "tags": [
          "Webhooks"
        ],
        "description": "Requires the webhooks:manage scope. ",
        "x-required-scope": "webhooks:manage",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Resource UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Endpoint and pending deliveries removed."
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "404": {
            "description": "webhook_not_found — No visible webhook with this UUID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/keys": {
      "post": {
        "operationId": "createKey",
        "summary": "Issue an API key",
        "tags": [
          "Keys"
        ],
        "description": "Requires the keys:manage scope. The key inherits the caller's account and deployment environment. Grants must be a subset of the caller's scopes.",
        "x-required-scope": "keys:manage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateKeyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "New key including its one-time credential.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedKey"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMedia"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      },
      "get": {
        "operationId": "listKeys",
        "summary": "List API key metadata",
        "tags": [
          "Keys"
        ],
        "description": "Requires the keys:manage scope. ",
        "x-required-scope": "keys:manage",
        "parameters": [
          {
            "name": "before",
            "in": "query",
            "required": false,
            "description": "Exclusive timestamp with timezone (up to six fractional digits), or the previous X-Next-Cursor.",
            "schema": {
              "type": "string",
              "maxLength": 70
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page size.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current-environment keys, including revoked keys, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ApiKey"
                  }
                }
              }
            },
            "headers": {
              "X-Next-Cursor": {
                "description": "Present only when more records exist. Send as before with the same filters.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/keys/{id}": {
      "delete": {
        "operationId": "revokeKey",
        "summary": "Revoke an API key",
        "tags": [
          "Keys"
        ],
        "description": "Requires the keys:manage scope. ",
        "x-required-scope": "keys:manage",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Resource UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Access revoked, including when the visible key was already revoked."
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "404": {
            "description": "key_not_found — No manageable key with this UUID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/metrics": {
      "get": {
        "operationId": "getMetrics",
        "summary": "Read 14 days of email delivery metrics",
        "tags": [
          "Metrics"
        ],
        "description": "Requires the read scope. Rates use distinct accepted emails, inferred from sent, delivery, permanent bounce or complaint events. Outcomes may overlap. Dates without accepted emails have null rates; subsequent feedback may update earlier cohorts.",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "domain_id",
            "in": "query",
            "required": false,
            "description": "Filter by sending-domain UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Daily creation cohorts and totals. Unknown or foreign domains yield zero counts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Metrics"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/infra/ses-events": {
      "post": {
        "operationId": "recordSesEvents",
        "summary": "Receive signed Amazon SNS messages",
        "tags": [
          "Service"
        ],
        "description": "AWS SNS integration only. The configured SNS topic and SignatureVersion 2 RSA-SHA256 signature are verified from the message body.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SnsEnvelope"
              }
            },
            "text/plain": {
              "schema": {
                "type": "string",
                "contentMediaType": "application/json",
                "description": "Serialized SNS envelope with the same fields as the application/json representation."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event handled, duplicate or ignored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "required": [
                    "ok"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "403": {
            "description": "invalid_sns_message — SNS topic or signing envelope rejected.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMedia"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/docs": {
      "get": {
        "operationId": "redirectDocs",
        "summary": "Redirect to the quickstart",
        "tags": [
          "Reference"
        ],
        "security": [],
        "responses": {
          "302": {
            "description": "Quickstart URL.",
            "headers": {
              "Location": {
                "description": "Canonical quickstart path.",
                "schema": {
                  "type": "string",
                  "const": "/docs/"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/docs/": {
      "get": {
        "operationId": "getDocs",
        "summary": "Read the developer quickstart",
        "tags": [
          "Reference"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Node.js, Next.js and cURL quickstart.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/billing/credits": {
      "get": {
        "operationId": "getCredits",
        "summary": "Read the account plan and sending usage",
        "tags": [
          "Billing"
        ],
        "description": "Returns trial end, subscription state and usage per UTC day and calendar month.",
        "x-required-scope": "read",
        "responses": {
          "200": {
            "description": "Account plan and sending allowance.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditBalance"
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ]
      }
    },
    "/api/billing/top-ups": {
      "post": {
        "operationId": "createTopUp",
        "summary": "Retired prepaid checkout",
        "tags": [
          "Billing"
        ],
        "description": "All requests, including anonymous requests, receive the retirement notice.",
        "responses": {
          "410": {
            "description": "topups_retired — Use the subscription endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "deprecated": true,
        "security": []
      }
    },
    "/infra/paddle-events": {
      "post": {
        "operationId": "receivePaddleEvent",
        "summary": "Settle a signed Paddle billing event",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "PaddleSignature": []
          }
        ],
        "description": "Verified subscription.created, subscription.trialing, subscription.activated, subscription.updated, subscription.paused, subscription.canceled and subscription.past_due notifications reconcile the configured recurring price to the local account. Historical transaction.completed and adjustment events remain supported for legacy one-time orders. Duplicate and stale events cannot grant a second allowance.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "event_id",
                  "event_type",
                  "data"
                ],
                "properties": {
                  "event_id": {
                    "type": "string",
                    "pattern": "^evt_[a-z0-9]{26}$"
                  },
                  "event_type": {
                    "type": "string"
                  },
                  "data": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Paddle transaction or adjustment resource, selected by event_type."
                  }
                },
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "description": "invalid_signature — The Paddle signature is missing, invalid or stale.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMedia"
          },
          "422": {
            "description": "invalid_paddle_event — Invalid event envelope or inconsistent order data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "externalDocs": {
          "description": "Paddle transaction.completed reference",
          "url": "https://developer.paddle.com/webhooks/transactions/transaction-completed/"
        }
      }
    },
    "/billing/checkout": {
      "get": {
        "operationId": "getBillingCheckout",
        "summary": "Open the email pack checkout page",
        "tags": [
          "Billing"
        ],
        "security": [],
        "parameters": [
          {
            "name": "_ptxn",
            "in": "query",
            "required": false,
            "description": "Paddle transaction ID from the existing purchase link. Omit to view instructions.",
            "schema": {
              "type": "string",
              "pattern": "^txn_[a-z0-9]{26}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Checkout page for an existing transaction or payment-link instructions.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid transaction link or unexpected query parameters.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "description": "Public checkout is unavailable for this deployment.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/": {
      "get": {
        "operationId": "getHomepage",
        "summary": "Read the SendHQ homepage",
        "tags": [
          "Reference"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "SendHQ transactional email API overview and usage allowances.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/auth/magic-link": {
      "post": {
        "operationId": "requestMagicLink",
        "summary": "Request a single-use sign-in email",
        "tags": [
          "Authentication"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Generic acknowledgment, including throttled and invalid email addresses.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "additionalProperties": false
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/auth/verify": {
      "get": {
        "operationId": "verifyMagicLink",
        "summary": "Consume a sign-in token and issue an owner session",
        "tags": [
          "Authentication"
        ],
        "security": [],
        "responses": {
          "302": {
            "description": "Redirect to the dashboard.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "const": "/dashboard/"
                }
              },
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "invalid_token — Token invalid, expired or used.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/auth/session": {
      "get": {
        "operationId": "getOwnerSession",
        "summary": "Read the signed-in account",
        "tags": [
          "Authentication"
        ],
        "security": [
          {
            "OwnerSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Account identity.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "email",
                    "account_id"
                  ],
                  "properties": {
                    "email": {
                      "type": "string",
                      "format": "email"
                    },
                    "account_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated — No valid owner session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/auth/first-key": {
      "post": {
        "operationId": "claimFirstApiKey",
        "summary": "Claim the initial send/read API key once",
        "tags": [
          "Authentication"
        ],
        "security": [
          {
            "OwnerSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Secret on first claim, null afterwards.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "key"
                  ],
                  "properties": {
                    "key": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated — No valid owner session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "forbidden — Cross-origin request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/auth/signout": {
      "post": {
        "operationId": "signOut",
        "summary": "End the browser session",
        "tags": [
          "Authentication"
        ],
        "security": [],
        "responses": {
          "204": {
            "description": "The session cookie is cleared."
          },
          "403": {
            "description": "forbidden — Cross-origin request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/billing/subscribe": {
      "post": {
        "operationId": "createSubscriptionCheckout",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "BearerKey": []
          },
          {
            "OwnerSession": []
          }
        ],
        "summary": "Create a $7 monthly subscription checkout",
        "description": "Owner session or keys:manage bearer. The account trial starts at signup. This checkout bills $7 USD monthly starting at purchase, including early upgrades. A verified active subscription grants 50,000 sends per UTC calendar month.",
        "x-required-scope": "keys:manage",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [],
                "properties": {},
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "New checkout.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionCheckout"
                }
              }
            }
          },
          "200": {
            "description": "A checkout already pending for the account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionCheckout"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/InvalidKey"
          },
          "403": {
            "$ref": "#/components/responses/MissingScope"
          },
          "409": {
            "description": "subscription_exists — The account already has an active, trialing, paused or past-due subscription.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    }
  },
  "webhooks": {
    "emailLifecycle": {
      "post": {
        "operationId": "receiveWebhook",
        "summary": "Receive a signed email lifecycle event",
        "tags": [
          "Webhooks"
        ],
        "description": "MailForge sends the exact JSON bytes to the registered HTTPS URL. Verify the timestamp and HMAC-SHA256 signature over timestamp, a period, and the raw body, then deduplicate by event ID.",
        "security": [],
        "parameters": [
          {
            "name": "X-Mailforge-Timestamp",
            "in": "header",
            "required": true,
            "description": "Unix time in seconds.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+$"
            }
          },
          {
            "name": "X-Mailforge-Signature",
            "in": "header",
            "required": true,
            "description": "Hex-encoded HMAC-SHA256 using the signing secret.",
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Receiver acknowledged delivery."
          },
          "default": {
            "description": "Delivery failed. MailForge applies its retry schedule."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Account- and environment-scoped MailForge API key."
      },
      "PaddleSignature": {
        "type": "apiKey",
        "in": "header",
        "name": "Paddle-Signature",
        "description": "Paddle-Signature includes ts and h1. Compute HMAC-SHA256 over ts + \":\" + raw JSON body with the environment-specific notification secret."
      },
      "OwnerSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-sendhq_session",
        "description": "Signed owner session. Cookie-authenticated writes require the deployment’s own Origin."
      }
    },
    "responses": {
      "InvalidRequest": {
        "description": "invalid_request — Malformed, invalid or unexpected input.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InvalidKey": {
        "description": "invalid_api_key — Missing, malformed, unknown, revoked or wrong-environment credential.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        },
        "headers": {
          "WWW-Authenticate": {
            "description": "Bearer challenge.",
            "schema": {
              "type": "string",
              "const": "Bearer"
            }
          }
        }
      },
      "MissingScope": {
        "description": "key_missing_scope — The operation requires a scope the key does not hold.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Unavailable": {
        "description": "service_unavailable — A required service is unavailable.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimited": {
        "description": "rate_limited — This key exhausted its shared allowance of 120 requests per 60-second window.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Seconds until the window resets, rounded up.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        }
      },
      "InternalError": {
        "description": "internal_error — An unexpected service failure occurred.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "TooLarge": {
        "description": "invalid_request — The body exceeds 1 MiB.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "UnsupportedMedia": {
        "description": "invalid_request — Unsupported content type.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "param": {
                "type": "string",
                "description": "Field associated with this error, when available."
              }
            },
            "required": [
              "type",
              "message"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      },
      "Health": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "service": {
            "type": "string",
            "const": "mailforge"
          },
          "time": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "ok",
          "service",
          "time"
        ],
        "additionalProperties": false
      },
      "EmailStatus": {
        "type": "string",
        "enum": [
          "queued",
          "sent",
          "delivered",
          "bounced",
          "complained",
          "failed"
        ]
      },
      "SendEmailRequest": {
        "allOf": [
          {
            "$ref": "#/components/schemas/SendEmailFields"
          },
          {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "html": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "html"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "text"
                ]
              }
            ]
          }
        ]
      },
      "AcceptedEmail": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "const": "email"
          }
        },
        "required": [
          "id",
          "object"
        ],
        "additionalProperties": false
      },
      "EmailSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "to": {
            "type": "string",
            "format": "email",
            "maxLength": 254,
            "description": "One ASCII mailbox."
          },
          "subject": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/EmailStatus"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "to",
          "subject",
          "status",
          "created_at"
        ],
        "additionalProperties": false
      },
      "EmailEvent": {
        "type": "object",
        "properties": {
          "type": {
            "$ref": "#/components/schemas/EmailStatus"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "detail": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "type",
          "created_at",
          "detail"
        ],
        "additionalProperties": false
      },
      "EmailDetail": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "to": {
            "type": "string",
            "format": "email",
            "maxLength": 254,
            "description": "One ASCII mailbox."
          },
          "subject": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/EmailStatus"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "domain_id": {
            "type": "string",
            "format": "uuid"
          },
          "from": {
            "type": "string"
          },
          "html": {
            "type": [
              "string",
              "null"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "reply_to": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "headers": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EmailEvent"
            },
            "description": "Oldest first, in append order."
          }
        },
        "required": [
          "id",
          "to",
          "subject",
          "status",
          "created_at",
          "domain_id",
          "from",
          "html",
          "text",
          "reply_to",
          "headers",
          "events"
        ],
        "additionalProperties": false
      },
      "CreateDomainRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 208,
            "description": "ASCII DNS hostname or punycode with at least two labels. Maximum of 207 normalized characters, optionally followed by one trailing dot."
          }
        },
        "required": [
          "name"
        ],
        "additionalProperties": false
      },
      "DnsRecord": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "const": "TXT"
          },
          "name": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        },
        "required": [
          "type",
          "name",
          "value"
        ],
        "additionalProperties": false
      },
      "Domain": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "verified"
            ]
          },
          "records": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DnsRecord"
            },
            "maxItems": 3,
            "description": "Three DKIM, SPF and DMARC TXT records. Empty for legacy verified domains without enrollment records."
          }
        },
        "required": [
          "id",
          "name",
          "status",
          "records"
        ],
        "additionalProperties": false
      },
      "CreateWebhookRequest": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048,
            "description": "Public HTTPS endpoint without credentials or fragments."
          }
        },
        "required": [
          "url"
        ],
        "additionalProperties": false
      },
      "CreatedWebhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "disabled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "signing_secret": {
            "type": "string",
            "description": "Save this secret on registration. It is returned once."
          }
        },
        "required": [
          "id",
          "created_at",
          "disabled_at",
          "url",
          "signing_secret"
        ],
        "additionalProperties": false
      },
      "WebhookSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "disabled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "url_origin": {
            "type": "string",
            "format": "uri",
            "description": "HTTPS origin only, excluding the path and query."
          }
        },
        "required": [
          "id",
          "created_at",
          "disabled_at",
          "url_origin"
        ],
        "additionalProperties": false
      },
      "WebhookEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-9]+$"
          },
          "type": {
            "type": "string",
            "enum": [
              "email.sent",
              "email.delivered",
              "email.bounced",
              "email.complained",
              "email.failed"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "properties": {
              "email_id": {
                "type": "string",
                "format": "uuid"
              }
            },
            "required": [
              "email_id"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "type",
          "created_at",
          "data"
        ],
        "additionalProperties": false
      },
      "Environment": {
        "type": "string",
        "enum": [
          "live",
          "test"
        ]
      },
      "ApiScope": {
        "type": "string",
        "enum": [
          "send",
          "read",
          "webhooks:manage",
          "keys:manage"
        ]
      },
      "CreateKeyRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "description": "Trimmed name without control characters."
          },
          "scopes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ApiScope"
            },
            "minItems": 1,
            "maxItems": 4,
            "uniqueItems": true
          }
        },
        "required": [
          "name",
          "scopes"
        ],
        "additionalProperties": false
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Legacy keys may have a null name."
          },
          "scopes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ApiScope"
            },
            "minItems": 1,
            "maxItems": 4,
            "uniqueItems": true
          },
          "environment": {
            "$ref": "#/components/schemas/Environment"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "scopes",
          "environment",
          "created_at",
          "revoked_at"
        ],
        "additionalProperties": false
      },
      "CreatedKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "description": "Trimmed name without control characters."
          },
          "scopes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ApiScope"
            },
            "minItems": 1,
            "maxItems": 4,
            "uniqueItems": true
          },
          "environment": {
            "$ref": "#/components/schemas/Environment"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "key": {
            "type": "string",
            "description": "One-time bearer credential. Save it when the key is issued."
          }
        },
        "required": [
          "id",
          "name",
          "scopes",
          "environment",
          "created_at",
          "revoked_at",
          "key"
        ],
        "additionalProperties": false
      },
      "MetricCounts": {
        "type": "object",
        "properties": {
          "volume": {
            "type": "integer",
            "minimum": 0
          },
          "accepted": {
            "type": "integer",
            "minimum": 0
          },
          "delivered": {
            "type": "integer",
            "minimum": 0
          },
          "bounced": {
            "type": "integer",
            "minimum": 0
          },
          "complained": {
            "type": "integer",
            "minimum": 0
          },
          "delivery_rate": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1,
            "description": "Fraction of accepted emails. Null when the denominator is zero."
          },
          "bounce_rate": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1,
            "description": "Fraction of accepted emails. Null when the denominator is zero."
          },
          "complaint_rate": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1,
            "description": "Fraction of accepted emails. Null when the denominator is zero."
          }
        },
        "required": [
          "volume",
          "accepted",
          "delivered",
          "bounced",
          "complained",
          "delivery_rate",
          "bounce_rate",
          "complaint_rate"
        ],
        "additionalProperties": false
      },
      "MetricDay": {
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "volume": {
            "type": "integer",
            "minimum": 0
          },
          "accepted": {
            "type": "integer",
            "minimum": 0
          },
          "delivered": {
            "type": "integer",
            "minimum": 0
          },
          "bounced": {
            "type": "integer",
            "minimum": 0
          },
          "complained": {
            "type": "integer",
            "minimum": 0
          },
          "delivery_rate": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1,
            "description": "Fraction of accepted emails. Null when the denominator is zero."
          },
          "bounce_rate": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1,
            "description": "Fraction of accepted emails. Null when the denominator is zero."
          },
          "complaint_rate": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1,
            "description": "Fraction of accepted emails. Null when the denominator is zero."
          }
        },
        "required": [
          "date",
          "volume",
          "accepted",
          "delivered",
          "bounced",
          "complained",
          "delivery_rate",
          "bounce_rate",
          "complaint_rate"
        ],
        "additionalProperties": false
      },
      "Metrics": {
        "type": "object",
        "properties": {
          "days": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MetricDay"
            },
            "minItems": 14,
            "maxItems": 14,
            "description": "UTC creation-date cohorts, oldest first through today."
          },
          "totals": {
            "$ref": "#/components/schemas/MetricCounts"
          }
        },
        "required": [
          "days",
          "totals"
        ],
        "additionalProperties": false
      },
      "SnsEnvelope": {
        "type": "object",
        "properties": {
          "Type": {
            "type": "string",
            "enum": [
              "Notification",
              "SubscriptionConfirmation",
              "UnsubscribeConfirmation"
            ]
          },
          "MessageId": {
            "type": "string"
          },
          "Token": {
            "type": "string"
          },
          "TopicArn": {
            "type": "string"
          },
          "Message": {
            "type": "string"
          },
          "Timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "Subject": {
            "type": "string"
          },
          "SignatureVersion": {
            "type": "string",
            "const": "2"
          },
          "Signature": {
            "type": "string"
          },
          "SigningCertURL": {
            "type": "string",
            "format": "uri"
          },
          "SubscribeURL": {
            "type": "string",
            "format": "uri"
          }
        },
        "required": [
          "Type",
          "MessageId",
          "TopicArn",
          "Message",
          "Timestamp",
          "SignatureVersion",
          "Signature",
          "SigningCertURL"
        ],
        "allOf": [
          {
            "if": {
              "properties": {
                "Type": {
                  "enum": [
                    "SubscriptionConfirmation",
                    "UnsubscribeConfirmation"
                  ]
                }
              }
            },
            "then": {
              "required": [
                "Token",
                "SubscribeURL"
              ],
              "properties": {
                "Token": {
                  "type": "string"
                },
                "SubscribeURL": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          }
        ],
        "additionalProperties": true
      },
      "SendEmailFields": {
        "type": "object",
        "properties": {
          "from": {
            "type": "string",
            "maxLength": 998,
            "description": "A sender mailbox or an unquoted display name followed by <mailbox>."
          },
          "to": {
            "type": "string",
            "format": "email",
            "maxLength": 254,
            "description": "One ASCII mailbox."
          },
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 998,
            "description": "Nonblank subject without control characters."
          },
          "html": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string",
            "minLength": 1
          },
          "reply_to": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "maxLength": 254
          },
          "headers": {
            "type": "object",
            "maxProperties": 15,
            "propertyNames": {
              "maxLength": 126,
              "pattern": "^[xX]-(?![sS][eE][sS]-)[a-zA-Z0-9-]+$"
            },
            "additionalProperties": {
              "type": "string",
              "pattern": "^[ -~]{1,995}$"
            },
            "description": "Unique case-insensitive X-* names. A full header line may occupy at most 998 bytes."
          }
        },
        "required": [
          "from",
          "to",
          "subject"
        ],
        "additionalProperties": false
      },
      "CreditBalance": {
        "type": "object",
        "required": [
          "plan",
          "trial_ends_at",
          "daily_used",
          "daily_limit",
          "monthly_used",
          "monthly_limit",
          "subscription_status"
        ],
        "properties": {
          "plan": {
            "type": "string",
            "enum": [
              "trial",
              "subscription",
              "expired"
            ]
          },
          "trial_ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "daily_used": {
            "type": "integer",
            "minimum": 0,
            "description": "Trial-metered sends today (UTC)."
          },
          "daily_limit": {
            "type": "integer",
            "const": 2000
          },
          "monthly_used": {
            "type": "integer",
            "minimum": 0,
            "description": "Paid-plan sends in the current UTC calendar month."
          },
          "monthly_limit": {
            "type": "integer",
            "const": 50000
          },
          "subscription_status": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "additionalProperties": false
      },
      "SubscriptionCheckout": {
        "type": "object",
        "required": [
          "id",
          "transaction_id",
          "checkout_url"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "transaction_id": {
            "type": "string",
            "pattern": "^txn_[a-z0-9]{26}$"
          },
          "checkout_url": {
            "type": "string",
            "format": "uri"
          }
        },
        "additionalProperties": false
      }
    }
  }
}
