{
  "openapi": "3.1.0",
  "jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
  "info": {
    "title": "Fumi Public API",
    "version": "0.1.0",
    "description": "Transactional email submission and activity APIs. API keys are created in the Fumi dashboard and must only be used from trusted server-side environments. Scheduled delivery is environment-gated: Pilot accepts scheduled messages while production returns scheduled_delivery_not_enabled until its separate activation release.",
    "x-fumi-scheduled-delivery": "environment-gated",
    "license": {
      "name": "Proprietary",
      "identifier": "LicenseRef-Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://app.fumihq.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Emails",
      "description": "Submit email and inspect workspace-scoped message activity."
    }
  ],
  "paths": {
    "/v1/emails": {
      "get": {
        "operationId": "listEmails",
        "summary": "List emails",
        "description": "Returns the newest workspace messages. A domain-scoped key only returns messages for its assigned domain.",
        "tags": ["Emails"],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of messages to return.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Newest messages.",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailListResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "sendEmail",
        "summary": "Send an email",
        "description": "Validates and queues a transactional email. When scheduled delivery is enabled for the deployment, scheduled_at stores it for delivery up to 30 days in the future; otherwise that field returns scheduled_delivery_not_enabled. Reusing an Idempotency-Key with the same canonical payload returns the original message; reusing it with a different payload is rejected.",
        "tags": ["Emails"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Application-defined key for safe replay. Scope is the authenticated workspace.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendEmailRequest"
              },
              "examples": {
                "direct": {
                  "summary": "Direct-content email",
                  "value": {
                    "from": {
                      "address": "hello@mail.example.com",
                      "name": "Acme"
                    },
                    "to": "person@example.net",
                    "subject": "Your receipt",
                    "html": "<h1>Thanks for your order</h1>",
                    "text": "Thanks for your order",
                    "tags": {
                      "order_id": "order_1842"
                    }
                  }
                },
                "template": {
                  "summary": "Published template version",
                  "value": {
                    "from": "hello@mail.example.com",
                    "to": ["person@example.net"],
                    "template": {
                      "id": "welcome-aboard",
                      "version": 1,
                      "variables": {
                        "first_name": "Taylor",
                        "dashboard_url": "https://example.com/app"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An idempotent replay returned the existing message.",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendEmailResponse"
                }
              }
            }
          },
          "202": {
            "description": "The message was accepted for asynchronous delivery.",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendEmailResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/v1/emails/{id}": {
      "get": {
        "operationId": "getEmail",
        "summary": "Retrieve an email",
        "description": "Returns workspace-scoped message metadata, event history, and per-recipient outcomes.",
        "tags": ["Emails"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Fumi message ID.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Message detail.",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailDetail"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "rescheduleEmail",
        "summary": "Reschedule an email",
        "description": "Changes the delivery time of an email that is still scheduled. The new time must be an ISO 8601 date-time no more than 30 days in the future.",
        "tags": ["Emails"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Fumi message ID.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RescheduleEmailRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The delivery time was updated.",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScheduledEmailMutation"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/v1/emails/{id}/cancel": {
      "post": {
        "operationId": "cancelEmail",
        "summary": "Cancel a scheduled email",
        "description": "Cancels an email that has not yet crossed the scheduled delivery boundary.",
        "tags": ["Emails"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Fumi message ID.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The scheduled email was canceled.",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScheduledEmailMutation"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Fumi API key",
        "description": "Use an API key created in the dashboard. Sending, read-only, full, and optional domain restrictions are enforced by the API."
      }
    },
    "headers": {
      "RequestId": {
        "description": "Identifier for support and API-log correlation.",
        "schema": {
          "type": "string"
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "The request body, query, or headers are invalid.",
        "$ref": "#/components/responses/ErrorResponse"
      },
      "Unauthorized": {
        "description": "The API key is missing, invalid, expired, or revoked.",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Forbidden": {
        "description": "The API key permission or domain scope does not allow this operation.",
        "$ref": "#/components/responses/ErrorResponse"
      },
      "NotFound": {
        "description": "The requested message does not exist in the authenticated scope.",
        "$ref": "#/components/responses/ErrorResponse"
      },
      "Conflict": {
        "description": "The request conflicts with existing state, including a reused idempotency key with different content.",
        "$ref": "#/components/responses/ErrorResponse"
      },
      "UnprocessableEntity": {
        "description": "The request is syntactically valid but cannot be admitted for delivery.",
        "$ref": "#/components/responses/ErrorResponse"
      },
      "TooManyRequests": {
        "description": "The API key rate limit was exceeded.",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/RequestId"
          },
          "Retry-After": {
            "description": "Seconds until the caller should retry, when available.",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InternalError": {
        "description": "An unexpected server error occurred.",
        "$ref": "#/components/responses/ErrorResponse"
      },
      "ErrorResponse": {
        "description": "The request failed.",
        "headers": {
          "X-Request-ID": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "EmailAddress": {
        "type": "string",
        "format": "email",
        "maxLength": 320
      },
      "NamedEmailAddress": {
        "type": "object",
        "required": ["address", "name"],
        "properties": {
          "address": {
            "$ref": "#/components/schemas/EmailAddress"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          }
        }
      },
      "EmailAddressList": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/EmailAddress"
          },
          {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/EmailAddress"
            }
          }
        ]
      },
      "TemplateSend": {
        "type": "object",
        "required": ["id", "version"],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "variables": {
            "type": "object",
            "maxProperties": 50,
            "propertyNames": {
              "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
              "maxLength": 64
            },
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string",
                  "maxLength": 20000
                },
                {
                  "type": "number"
                }
              ]
            },
            "default": {}
          }
        }
      },
      "Attachment": {
        "type": "object",
        "required": ["filename", "content", "type"],
        "properties": {
          "filename": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "content": {
            "type": "string",
            "minLength": 1,
            "maxLength": 7000000,
            "description": "Base64-encoded attachment bytes."
          },
          "type": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "pattern": "^[A-Za-z0-9!#$&^_.+-]+/[A-Za-z0-9!#$&^_.+-]+$",
            "examples": ["application/pdf"]
          },
          "disposition": {
            "type": "string",
            "enum": ["attachment", "inline"],
            "default": "attachment"
          },
          "content_id": {
            "type": "string",
            "maxLength": 255
          }
        }
      },
      "SendEmailRequest": {
        "type": "object",
        "required": ["from"],
        "description": "At least one recipient is required across to, cc, and bcc; the combined maximum is 50 and a recipient may occur only once. Provide html, text, or an immutable published template. A direct-content request also requires subject.",
        "properties": {
          "from": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/EmailAddress"
              },
              {
                "$ref": "#/components/schemas/NamedEmailAddress"
              }
            ]
          },
          "to": {
            "$ref": "#/components/schemas/EmailAddressList"
          },
          "cc": {
            "$ref": "#/components/schemas/EmailAddressList"
          },
          "bcc": {
            "$ref": "#/components/schemas/EmailAddressList"
          },
          "reply_to": {
            "$ref": "#/components/schemas/EmailAddress"
          },
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 998
          },
          "html": {
            "type": "string",
            "maxLength": 4500000
          },
          "text": {
            "type": "string",
            "maxLength": 4500000
          },
          "template": {
            "$ref": "#/components/schemas/TemplateSend"
          },
          "headers": {
            "type": "object",
            "propertyNames": {
              "maxLength": 128
            },
            "additionalProperties": {
              "type": "string",
              "maxLength": 4096
            },
            "default": {}
          },
          "attachments": {
            "type": "array",
            "maxItems": 32,
            "items": {
              "$ref": "#/components/schemas/Attachment"
            },
            "default": []
          },
          "tags": {
            "type": "object",
            "maxProperties": 50,
            "propertyNames": {
              "minLength": 1,
              "maxLength": 64,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            },
            "additionalProperties": {
              "type": "string",
              "maxLength": 256
            },
            "default": {}
          },
          "scheduled_at": {
            "type": "string",
            "format": "date-time",
            "description": "Future delivery time, up to 30 days from submission. Offset-aware ISO 8601 values are required."
          }
        },
        "allOf": [
          {
            "anyOf": [
              {
                "required": ["to"]
              },
              {
                "required": ["cc"]
              },
              {
                "required": ["bcc"]
              }
            ]
          },
          {
            "anyOf": [
              {
                "required": ["template"]
              },
              {
                "required": ["subject"],
                "anyOf": [
                  {
                    "required": ["html"]
                  },
                  {
                    "required": ["text"]
                  }
                ]
              }
            ]
          }
        ]
      },
      "EmailStatus": {
        "type": "string",
        "enum": [
          "scheduled",
          "canceled",
          "queued",
          "preparing",
          "sending",
          "retrying",
          "accepted",
          "sent",
          "delivered",
          "partially_delivered",
          "failed",
          "delivery_unknown",
          "bounced",
          "rejected",
          "complained",
          "received",
          "parsing",
          "parse_failed"
        ]
      },
      "SendEmailResponse": {
        "type": "object",
        "required": ["id", "status", "duplicate"],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/EmailStatus"
          },
          "duplicate": {
            "type": "boolean"
          }
        }
      },
      "RescheduleEmailRequest": {
        "type": "object",
        "required": ["scheduled_at"],
        "additionalProperties": false,
        "properties": {
          "scheduled_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ScheduledEmailMutation": {
        "type": "object",
        "required": ["id", "status", "scheduled_at", "canceled_at"],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["scheduled", "canceled"]
          },
          "scheduled_at": {
            "type": "string",
            "format": "date-time"
          },
          "canceled_at": {
            "type": ["string", "null"],
            "format": "date-time"
          }
        }
      },
      "EmailSummary": {
        "type": "object",
        "required": [
          "id",
          "direction",
          "template_id",
          "template_version",
          "from_address",
          "from_name",
          "to",
          "subject",
          "status",
          "provider_message_id",
          "error_code",
          "scheduled_at",
          "canceled_at",
          "created_at",
          "delivered_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "direction": {
            "type": "string",
            "enum": ["outbound", "inbound"]
          },
          "template_id": {
            "type": ["string", "null"]
          },
          "template_version": {
            "type": ["integer", "null"]
          },
          "from_address": {
            "type": "string"
          },
          "from_name": {
            "type": ["string", "null"]
          },
          "to": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "subject": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/EmailStatus"
          },
          "provider_message_id": {
            "type": ["string", "null"]
          },
          "error_code": {
            "type": ["string", "null"]
          },
          "scheduled_at": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "canceled_at": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "delivered_at": {
            "type": ["string", "null"],
            "format": "date-time"
          }
        }
      },
      "EmailEvent": {
        "type": "object",
        "required": ["type", "detail", "occurred_at"],
        "properties": {
          "type": {
            "type": "string"
          },
          "detail": {
            "type": "object",
            "additionalProperties": true
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "RecipientOutcome": {
        "type": "object",
        "required": [
          "recipient",
          "recipient_kind",
          "status",
          "error_code",
          "error_message",
          "occurred_at"
        ],
        "properties": {
          "recipient": {
            "type": "string"
          },
          "recipient_kind": {
            "type": "string",
            "enum": ["to", "cc", "bcc"]
          },
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": ["string", "null"]
          },
          "error_message": {
            "type": ["string", "null"]
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "EmailDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/EmailSummary"
          },
          {
            "type": "object",
            "required": [
              "domain_id",
              "cc",
              "bcc",
              "reply_to",
              "error_message",
              "tags",
              "accepted_at",
              "failed_at",
              "events",
              "recipients"
            ],
            "properties": {
              "domain_id": {
                "type": ["string", "null"]
              },
              "cc": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "bcc": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "reply_to": {
                "type": ["string", "null"]
              },
              "error_message": {
                "type": ["string", "null"]
              },
              "tags": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              },
              "accepted_at": {
                "type": ["string", "null"],
                "format": "date-time"
              },
              "failed_at": {
                "type": ["string", "null"],
                "format": "date-time"
              },
              "events": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/EmailEvent"
                }
              },
              "recipients": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/RecipientOutcome"
                }
              }
            }
          }
        ]
      },
      "EmailListResponse": {
        "type": "object",
        "required": ["data"],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EmailSummary"
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error", "request_id"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": true
            }
          },
          "request_id": {
            "type": "string"
          }
        }
      }
    }
  }
}
