{
 "openapi": "3.1.0",
 "info": {
  "title": "AssertInbox API",
  "version": "0.1.0",
  "description": "Test email inboxes. Free beta, run by AI agents."
 },
 "servers": [
  {
   "url": "https://assertinbox.com"
  }
 ],
 "paths": {
  "/v1/keys": {
   "post": {
    "summary": "Create an API key and namespace",
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "api_key": {
           "type": "string"
          },
          "namespace": {
           "type": "string"
          },
          "address_template": {
           "type": "string"
          }
         }
        },
        "example": {
         "api_key": "ai_0123456789abcdef",
         "namespace": "k3x9a1bz",
         "address_template": "k3x9a1bz.<tag>@assertinbox.com"
        }
       }
      }
     },
     "403": {
      "description": "signups_closed",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "operationId": "createKey"
   }
  },
  "/v1/messages": {
   "get": {
    "summary": "List messages, newest first",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "tag",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "example": "signup-1"
     },
     {
      "name": "since",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix time in seconds; only messages received at or after it.",
      "example": 1796464000
     },
     {
      "name": "from",
      "in": "query",
      "description": "Case-insensitive substring of the sender.",
      "schema": {
       "type": "string"
      },
      "example": "noreply@example.com"
     },
     {
      "name": "subject",
      "in": "query",
      "description": "Case-insensitive substring of the subject.",
      "schema": {
       "type": "string"
      },
      "example": "verification"
     },
     {
      "name": "after",
      "in": "query",
      "description": "A message id. Only messages that arrived after that one are returned (an unknown id adds no constraint).",
      "schema": {
       "type": "string"
      },
      "example": "2f1c0b1e-0000-4000-8000-000000000001"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "messages": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Message"
           }
          }
         }
        },
        "example": {
         "messages": [
          {
           "id": "2f1c0b1e-0000-4000-8000-000000000001",
           "tag": "signup-1",
           "ts": 1796464450,
           "from": "noreply@example.com",
           "subject": "Your code",
           "text": "Your verification code is 482913",
           "html": "",
           "otp": "482913",
           "magic_link": "https://example.com/verify?t=abc",
           "links": [
            "https://example.com/verify?t=abc"
           ]
          }
         ]
        }
       }
      }
     },
     "401": {
      "description": "unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "key_disabled",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; 2000 API requests per key per UTC day; see Retry-After",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "operationId": "listMessages"
   },
   "delete": {
    "summary": "Delete messages for a tag, or all",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "tag",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "example": "signup-1"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        },
        "example": {
         "ok": true
        }
       }
      }
     },
     "401": {
      "description": "unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "key_disabled",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; 2000 API requests per key per UTC day; see Retry-After",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "operationId": "deleteMessages"
   }
  },
  "/v1/messages/{id}": {
   "get": {
    "summary": "Get one message",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "example": "2f1c0b1e-0000-4000-8000-000000000001"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Message"
        },
        "example": {
         "id": "2f1c0b1e-0000-4000-8000-000000000001",
         "tag": "signup-1",
         "ts": 1796464450,
         "from": "noreply@example.com",
         "subject": "Your code",
         "text": "Your verification code is 482913",
         "html": "",
         "otp": "482913",
         "magic_link": "https://example.com/verify?t=abc",
         "links": [
          "https://example.com/verify?t=abc"
         ]
        }
       }
      }
     },
     "401": {
      "description": "unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "key_disabled",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "not_found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; 2000 API requests per key per UTC day; see Retry-After",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "operationId": "getMessage"
   }
  },
  "/v1/wait": {
   "get": {
    "summary": "Long-poll for the newest matching message (max 25 s)",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "tag",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "example": "signup-1"
     },
     {
      "name": "since",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix time in seconds; only messages received at or after it.",
      "example": 1796464000
     },
     {
      "name": "timeout",
      "in": "query",
      "schema": {
       "type": "integer",
       "maximum": 25,
       "default": 20
      },
      "example": 20
     },
     {
      "name": "from",
      "in": "query",
      "description": "Case-insensitive substring of the sender.",
      "schema": {
       "type": "string"
      },
      "example": "noreply@example.com"
     },
     {
      "name": "subject",
      "in": "query",
      "description": "Case-insensitive substring of the subject.",
      "schema": {
       "type": "string"
      },
      "example": "verification"
     },
     {
      "name": "after",
      "in": "query",
      "description": "A message id. Only messages that arrived after that one are returned (an unknown id adds no constraint).",
      "schema": {
       "type": "string"
      },
      "example": "2f1c0b1e-0000-4000-8000-000000000001"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Message"
        },
        "example": {
         "id": "2f1c0b1e-0000-4000-8000-000000000001",
         "tag": "signup-1",
         "ts": 1796464450,
         "from": "noreply@example.com",
         "subject": "Your code",
         "text": "Your verification code is 482913",
         "html": "",
         "otp": "482913",
         "magic_link": "https://example.com/verify?t=abc",
         "links": [
          "https://example.com/verify?t=abc"
         ]
        }
       }
      }
     },
     "400": {
      "description": "tag_required",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "key_disabled",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "408": {
      "description": "timeout",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; 2000 API requests per key per UTC day; see Retry-After",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "operationId": "waitForMessage"
   }
  },
  "/v1/me": {
   "get": {
    "summary": "Your namespace, usage today and limits",
    "security": [
     {
      "bearer": []
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "namespace": {
           "type": "string"
          },
          "address_template": {
           "type": "string"
          },
          "created_at": {
           "type": "integer"
          },
          "activated": {
           "type": "boolean"
          },
          "messages_today": {
           "type": "integer"
          },
          "api_calls_today": {
           "type": "integer"
          },
          "limits": {
           "type": "object",
           "properties": {
            "messages_per_day": {
             "type": "integer"
            },
            "api_calls_per_day": {
             "type": "integer"
            },
            "retention_hours": {
             "type": "integer"
            }
           }
          }
         }
        },
        "example": {
         "namespace": "k3x9a1bz",
         "address_template": "k3x9a1bz.<tag>@assertinbox.com",
         "created_at": 1796460000,
         "activated": true,
         "messages_today": 3,
         "api_calls_today": 12,
         "limits": {
          "messages_per_day": 200,
          "api_calls_per_day": 2000,
          "retention_hours": 24
         }
        }
       }
      }
     },
     "401": {
      "description": "unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "key_disabled",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; see Retry-After",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "operationId": "getMe"
   }
  },
  "/v1/keys/me": {
   "delete": {
    "operationId": "deleteKey",
    "summary": "Delete every message and usage row for your namespace and permanently disable the key",
    "security": [
     {
      "bearer": []
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "deleted": {
           "type": "boolean"
          }
         }
        },
        "example": {
         "deleted": true
        }
       }
      }
     },
     "401": {
      "description": "unauthorized"
     }
    }
   }
  },
  "/v1/keys/me/rotate": {
   "post": {
    "operationId": "rotateKey",
    "summary": "Issue a new API key for the same namespace; the old key stops working at once",
    "security": [
     {
      "bearer": []
     }
    ],
    "responses": {
     "200": {
      "description": "New key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "api_key": {
           "type": "string"
          },
          "namespace": {
           "type": "string"
          }
         }
        },
        "example": {
         "api_key": "ai_fedcba9876543210",
         "namespace": "k3x9a1bz"
        }
       }
      }
     },
     "401": {
      "description": "unauthorized"
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer"
   }
  },
  "schemas": {
   "Message": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "tag": {
      "type": "string"
     },
     "ts": {
      "type": "integer"
     },
     "from": {
      "type": "string"
     },
     "subject": {
      "type": "string"
     },
     "text": {
      "type": "string"
     },
     "html": {
      "type": "string"
     },
     "otp": {
      "type": [
       "string",
       "null"
      ]
     },
     "links": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "magic_link": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "error",
     "message"
    ],
    "properties": {
     "error": {
      "$ref": "#/components/schemas/ErrorCode"
     },
     "message": {
      "type": "string"
     }
    }
   },
   "ErrorCode": {
    "type": "string",
    "enum": [
     "unauthorized",
     "key_disabled",
     "signups_closed",
     "rate_limited",
     "not_found",
     "timeout",
     "tag_required",
     "method_not_allowed"
    ],
    "description": "Stable error codes. See https://assertinbox.com/docs/limits"
   }
  }
 }
}
