{
  "openapi": "3.1.0",
  "info": {
    "title": "LlamaEmail API",
    "version": "1.0.0",
    "description": "Send and read email for your custom-domain mailbox. Messages appear in webmail Sent and Inbox."
  },
  "servers": [
    {
      "url": "https://app.llamaemail.com/v1",
      "description": "Production"
    }
  ],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "le_live_…"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": { "type": "string" },
              "code": { "type": "string" }
            },
            "required": ["message"]
          }
        }
      },
      "Email": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string", "enum": ["email"] },
          "folder": { "type": "string", "enum": ["inbox", "sent"] },
          "from": { "type": "string" },
          "to": { "type": "array", "items": { "type": "string" } },
          "cc": { "type": "array", "items": { "type": "string" } },
          "bcc": { "type": "array", "items": { "type": "string" } },
          "subject": { "type": "string" },
          "text": { "type": "string" },
          "html": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" },
          "state": { "type": "string" }
        }
      }
    }
  },
  "paths": {
    "/emails": {
      "post": {
        "summary": "Send an email",
        "operationId": "sendEmail",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": { "type": "string", "format": "uuid" },
            "description": "UUID. Retries with the same key return the same send."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["to"],
                "properties": {
                  "from": {
                    "type": "string",
                    "description": "Verified identity on the key's mailbox. Defaults to the mailbox address."
                  },
                  "to": {
                    "oneOf": [
                      { "type": "string" },
                      { "type": "array", "items": { "type": "string" } }
                    ]
                  },
                  "cc": {
                    "oneOf": [
                      { "type": "string" },
                      { "type": "array", "items": { "type": "string" } }
                    ]
                  },
                  "bcc": {
                    "oneOf": [
                      { "type": "string" },
                      { "type": "array", "items": { "type": "string" } }
                    ]
                  },
                  "subject": { "type": "string" },
                  "text": { "type": "string" },
                  "html": { "type": "string" },
                  "idempotency_key": { "type": "string", "format": "uuid" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted for delivery",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Email" }
              }
            }
          },
          "401": { "description": "Invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "Missing scope or from address", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Sending limit", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "get": {
        "summary": "List emails",
        "operationId": "listEmails",
        "parameters": [
          {
            "name": "folder",
            "in": "query",
            "schema": { "type": "string", "enum": ["inbox", "sent"], "default": "inbox" }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 }
          }
        ],
        "responses": {
          "200": {
            "description": "Email list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": { "type": "string", "enum": ["list"] },
                    "folder": { "type": "string" },
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Email" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/emails/{id}": {
      "get": {
        "summary": "Get an email",
        "operationId": "getEmail",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
          }
        ],
        "responses": {
          "200": {
            "description": "Email",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Email" }
              }
            }
          },
          "404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  }
}
