{
  "openapi": "3.1.0",
  "info": {
    "title": "PikaMail Public and Temporary Inbox API",
    "version": "2.0.0",
    "description": "Browser-compatible receive-only inbox endpoints. Temporary and permanent addresses support optional passwords; password-free addresses are explicitly public. Permanent messages are retained for 30 days. The account API under /api/v1 requires an account API key."
  },
  "servers": [
    {
      "url": "https://pikamail.life/api"
    }
  ],
  "components": {
    "securitySchemes": {
      "InboxToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "Scoped token from inbox creation or password-protected opening."
      }
    },
    "schemas": {
      "InboxCreation": {
        "type": "object",
        "required": [
          "id",
          "token",
          "address",
          "expires",
          "public",
          "passwordProtected",
          "permanent"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "token": {
            "type": "string"
          },
          "address": {
            "type": "string",
            "format": "email"
          },
          "domain": {
            "type": "string"
          },
          "expires": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Null for permanent mail."
          },
          "public": {
            "type": "boolean"
          },
          "passwordProtected": {
            "type": "boolean"
          },
          "permanent": {
            "type": "boolean"
          }
        }
      }
    }
  },
  "paths": {
    "/inboxes": {
      "post": {
        "operationId": "createInbox",
        "summary": "Create temporary or permanent mail",
        "description": "No body creates a random private temporary inbox. Permanent mail accepts an optional password. With a password it is private and restorable; without one, public=true is required and anyone knowing its address can read messages. Permanent messages expire after 30 days. Rate limit: 3 creations per second per source IP.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "alias": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9]{8,14}$"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Optional enabled domain from GET /api/public/domains."
                  },
                  "public": {
                    "type": "boolean",
                    "default": false
                  },
                  "password": {
                    "type": "string",
                    "minLength": 6,
                    "maxLength": 128
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "temporary",
                      "permanent"
                    ],
                    "default": "temporary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created. Save token; it is shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxCreation"
                }
              }
            }
          },
          "400": {
            "description": "Invalid options"
          },
          "409": {
            "description": "Address already taken"
          },
          "429": {
            "description": "Rate limited; obey Retry-After"
          }
        }
      }
    },
    "/inboxes/open": {
      "post": {
        "operationId": "openTemporaryInbox",
        "summary": "Open an explicitly public or password-protected inbox",
        "description": "Explicitly public mail opens by address alone. Password-protected temporary or permanent mail requires its password. Private token-only mail cannot be opened by address alone. Rate limit: 12 attempts per source IP per minute.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "address"
                ],
                "properties": {
                  "address": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Public inbox metadata, or metadata and a new scoped token for password-protected mail"
          },
          "404": {
            "description": "Inbox unavailable or incorrect password"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/inboxes/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Address local part"
        }
      ],
      "get": {
        "operationId": "readTemporaryInbox",
        "summary": "Read inbox and message summaries",
        "security": [
          {
            "InboxToken": []
          },
          {}
        ],
        "description": "Public inboxes need no token. Private or password-protected inboxes need a Bearer token.",
        "responses": {
          "200": {
            "description": "Inbox metadata and messages"
          },
          "404": {
            "description": "Unavailable"
          }
        }
      },
      "delete": {
        "operationId": "deleteTemporaryInbox",
        "summary": "Delete inbox",
        "security": [
          {
            "InboxToken": []
          }
        ],
        "description": "Requires its creation or restored token even for public inboxes.",
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "403": {
            "description": "Owner token required"
          }
        }
      }
    },
    "/inboxes/{id}/messages/{messageId}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "messageId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "readTemporaryMessage",
        "summary": "Read received message",
        "security": [
          {
            "InboxToken": []
          },
          {}
        ],
        "description": "Public inboxes need no token. HTML is sanitized; attachments are blocked and discarded.",
        "responses": {
          "200": {
            "description": "Message content"
          },
          "404": {
            "description": "Unavailable"
          }
        }
      },
      "delete": {
        "operationId": "deleteTemporaryMessage",
        "summary": "Delete a temporary message",
        "security": [
          {
            "InboxToken": []
          }
        ],
        "description": "Requires a valid inbox token even if the inbox is public.",
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "403": {
            "description": "Token required"
          },
          "404": {
            "description": "Unavailable"
          }
        }
      }
    },
    "/public/metrics": {
      "get": {
        "operationId": "publicMetrics",
        "summary": "Get current aggregate service counts",
        "responses": {
          "200": {
            "description": "Counts from currently stored records; no uptime claim",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "asOf": {
                      "type": "integer"
                    },
                    "activeTemporaryInboxes": {
                      "type": "integer"
                    },
                    "permanentAddresses": {
                      "type": "integer"
                    },
                    "messagesReceived24h": {
                      "type": "integer"
                    },
                    "delivery": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
