{
  "openapi": "3.1.0",
  "info": {
    "title": "Temp Mail Agency REST API",
    "version": "2.0.0",
    "summary": "Free zero-signup temporary email API with automatic OTP extraction",
    "description": "Receive-only disposable email REST API across separate live .com, organization .org.uk, and academic .edu.pl domain pools with automatic 4–8 digit OTP extraction, magic-link detection, attachment normalization, tracker/phishing risk analysis, and signed tma_v1 recovery tokens. CORS enabled (Access-Control-Allow-Origin: *), zero signup required.",
    "contact": {
      "name": "Temp Mail Agency Engineering",
      "url": "https://temp-mail.agency/temp-mail-api",
      "email": "support@temp-mail.agency"
    },
    "termsOfService": "https://temp-mail.agency/terms-of-service"
  },
  "servers": [
    {
      "url": "https://temp-mail.agency/api/v1",
      "description": "Production REST API v1"
    }
  ],
  "tags": [
    { "name": "Health", "description": "Service status and available domain pools" },
    { "name": "Domains", "description": "Live standard (.com), organization (.org.uk), and academic (.edu.pl) domain pools" },
    { "name": "Inboxes", "description": "Create, restore, extend TTL, and delete isolated temporary mailboxes" },
    { "name": "Messages", "description": "Read received messages and automatically extracted OTP verification codes" }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": ["Health"],
        "operationId": "getHealth",
        "summary": "Check API health and active provider pools",
        "responses": {
          "200": {
            "description": "Healthy service metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "ok" },
                    "providers": {
                      "type": "array",
                      "items": { "type": "string" },
                      "example": ["tempmail", "orgmail", "edumail"]
                    },
                    "mcp": { "type": "string", "example": "/mcp" },
                    "version": { "type": "string", "example": "2.0.0" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/domains": {
      "get": {
        "tags": ["Domains"],
        "operationId": "listDomains",
        "summary": "List live active disposable email domains",
        "parameters": [
          {
            "name": "provider",
            "in": "query",
            "required": false,
            "description": "Filter by pool: all, tempmail (.com), orgmail (.org.uk), or edumail (.edu.pl)",
            "schema": {
              "type": "string",
              "enum": ["all", "tempmail", "orgmail", "edumail"],
              "default": "all"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Active domain list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": { "type": "integer" },
                    "domains": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "domain": { "type": "string" },
                          "domain_id": { "type": ["integer", "string", "null"] },
                          "provider": { "type": "string", "enum": ["tempmail", "orgmail", "edumail"] },
                          "tier": { "type": "string" }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/inboxes": {
      "post": {
        "tags": ["Inboxes"],
        "operationId": "createInbox",
        "summary": "Create a new isolated temporary email inbox",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "provider": {
                    "type": "string",
                    "enum": ["tempmail", "orgmail", "edumail"],
                    "default": "tempmail",
                    "description": "Domain pool: tempmail (.com), orgmail (.org.uk), or edumail (.edu.pl)"
                  },
                  "alias": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 40,
                    "description": "Optional custom username before the @ sign"
                  },
                  "domain_id": {
                    "type": ["integer", "string"],
                    "description": "Optional specific domain_id returned by GET /domains"
                  },
                  "ttl": {
                    "type": "string",
                    "enum": ["10m", "1h", "24h", "7d", "never"],
                    "default": "24h"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Inbox created",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Inbox" }
              }
            }
          }
        }
      }
    },
    "/inboxes/restore": {
      "post": {
        "tags": ["Inboxes"],
        "operationId": "restoreInbox",
        "summary": "Restore a reusable inbox using its signed tma_v1 recovery token",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["recovery_token"],
                "properties": {
                  "recovery_token": {
                    "type": "string",
                    "description": "Signed tma_v1_... recovery token returned by POST /inboxes"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Restored inbox session",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Inbox" }
              }
            }
          }
        }
      }
    },
    "/inboxes/{inboxId}/ttl": {
      "patch": {
        "tags": ["Inboxes"],
        "operationId": "updateInboxTtl",
        "summary": "Update inbox expiration TTL and re-sign its recovery token",
        "parameters": [
          {
            "name": "inboxId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Signed inbox_id returned by POST /inboxes"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["ttl"],
                "properties": {
                  "ttl": {
                    "type": "string",
                    "enum": ["10m", "1h", "24h", "7d", "never"]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated inbox metadata and new recovery token",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Inbox" }
              }
            }
          }
        }
      }
    },
    "/inboxes/{inboxId}/messages": {
      "get": {
        "tags": ["Messages"],
        "operationId": "getInboxMessages",
        "summary": "Fetch messages with parsed OTPs, magic links, attachments & security flags",
        "parameters": [
          {
            "name": "inboxId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Inbox messages payload",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "address": { "type": "string" },
                    "count": { "type": "integer" },
                    "messages": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Message" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/inboxes/{inboxId}/code": {
      "get": {
        "tags": ["Messages"],
        "operationId": "getVerificationCode",
        "summary": "Extract the newest 4–8 digit OTP code or verification link directly",
        "parameters": [
          {
            "name": "inboxId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Latest extracted OTP verification code and link",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "found": { "type": "boolean" },
                    "code": { "type": ["string", "null"] },
                    "verification_link": { "type": ["string", "null"] },
                    "subject": { "type": ["string", "null"] },
                    "from": { "type": ["string", "null"] }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/inboxes/{inboxId}": {
      "delete": {
        "tags": ["Inboxes"],
        "operationId": "deleteInbox",
        "summary": "Burn and delete a temporary inbox immediately",
        "parameters": [
          {
            "name": "inboxId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Deletion confirmation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deleted": { "type": "boolean" },
                    "address": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Inbox": {
        "type": "object",
        "properties": {
          "inbox_id": { "type": "string" },
          "recovery_token": { "type": "string" },
          "address": { "type": "string", "format": "email" },
          "provider": { "type": "string", "enum": ["tempmail", "orgmail", "edumail"] },
          "ttl": { "type": "string" },
          "expires_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "from": { "type": "string" },
          "subject": { "type": "string" },
          "text": { "type": "string" },
          "html": { "type": "string" },
          "otp_code": { "type": ["string", "null"] },
          "verification_link": { "type": ["string", "null"] },
          "attachment_count": { "type": "integer" },
          "attachments": { "type": "array", "items": { "type": "object" } },
          "security": { "type": "object" },
          "received_at": { "type": "string" }
        }
      }
    }
  }
}
