{
  "openapi": "3.0.3",
  "info": {
    "title": "Ravi API",
    "version": "1.0.0",
    "description": "Identity provider for AI agents \u2014 provisioned phone numbers, email addresses, TOTP, OTP extraction, and E2E-encrypted passwords and secrets."
  },
  "paths": {
    "/api/email-inbox/": {
      "get": {
        "operationId": "email_inbox_list",
        "description": "List email threads grouped by thread_id, newest first. Each thread includes message count, unread count, subject, preview, and attachment names. Filterable by has_unread and inbox.",
        "tags": [
          "Inbox"
        ],
        "security": [
          {
            "identityKeyAuth": []
          },
          {
            "managementKeyAuth": []
          },
          {
            "jwtAuth": []
          },
          {
            "cookieAuth": []
          },
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/EmailThread"
                  }
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/api/email-inbox/{id}/": {
      "get": {
        "operationId": "email_inbox_retrieve",
        "description": "Retrieve a single email thread by thread_id, returning all messages in chronological order. Returns 404 if the thread is not found.",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "schema": {
              "type": "string",
              "pattern": "^[^/]+$"
            },
            "required": true
          }
        ],
        "tags": [
          "Inbox"
        ],
        "security": [
          {
            "identityKeyAuth": []
          },
          {
            "managementKeyAuth": []
          },
          {
            "jwtAuth": []
          },
          {
            "cookieAuth": []
          },
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailThreadDetail"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/api/sms-inbox/": {
      "get": {
        "operationId": "sms_inbox_list",
        "description": "List SMS conversations grouped by sender, newest first. Each conversation includes message count, unread count, preview, and phone number. Filterable by has_unread and phone.",
        "tags": [
          "Inbox"
        ],
        "security": [
          {
            "identityKeyAuth": []
          },
          {
            "managementKeyAuth": []
          },
          {
            "jwtAuth": []
          },
          {
            "cookieAuth": []
          },
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SMSConversation"
                  }
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/api/sms-inbox/{id}/": {
      "get": {
        "operationId": "sms_inbox_retrieve",
        "description": "Retrieve a single SMS conversation by conversation_id ({phone_id}_{from_number}). Returns all messages in chronological order. Returns 400 for an invalid conversation ID format, 404 if not found.",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "schema": {
              "type": "string"
            },
            "required": true
          }
        ],
        "tags": [
          "Inbox"
        ],
        "security": [
          {
            "identityKeyAuth": []
          },
          {
            "managementKeyAuth": []
          },
          {
            "jwtAuth": []
          },
          {
            "cookieAuth": []
          },
          {
            "basicAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SMSConversationDetail"
                }
              }
            },
            "description": ""
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "EmailAttachment": {
        "type": "object",
        "description": "Full attachment representation including a presigned download URL.",
        "properties": {
          "uuid": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "filename": {
            "type": "string",
            "description": "Original filename",
            "maxLength": 255
          },
          "content_type": {
            "type": "string",
            "description": "MIME content type",
            "maxLength": 255
          },
          "size": {
            "type": "integer",
            "maximum": 2147483647,
            "minimum": 0,
            "description": "File size in bytes"
          },
          "content_id": {
            "type": "string",
            "description": "Content-ID for inline images (RFC 2392)",
            "maxLength": 255
          },
          "is_inline": {
            "type": "boolean",
            "description": "Whether this is an inline image (CID reference)"
          },
          "download_url": {
            "type": "string",
            "readOnly": true
          },
          "created_dt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "required": [
          "content_type",
          "created_dt",
          "download_url",
          "filename",
          "size",
          "uuid"
        ]
      },
      "EmailThread": {
        "type": "object",
        "properties": {
          "thread_id": {
            "type": "string"
          },
          "subject": {
            "type": "string"
          },
          "preview": {
            "type": "string"
          },
          "from_email": {
            "type": "string",
            "format": "email"
          },
          "from_display_name": {
            "type": "string",
            "default": ""
          },
          "inbox": {
            "type": "string",
            "nullable": true,
            "readOnly": true
          },
          "message_count": {
            "type": "integer"
          },
          "unread_count": {
            "type": "integer"
          },
          "attachment_names": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "latest_message_dt": {
            "type": "string",
            "format": "date-time"
          },
          "oldest_message_dt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "attachment_names",
          "from_email",
          "inbox",
          "latest_message_dt",
          "message_count",
          "oldest_message_dt",
          "preview",
          "subject",
          "thread_id",
          "unread_count"
        ]
      },
      "EmailThreadDetail": {
        "type": "object",
        "properties": {
          "thread_id": {
            "type": "string"
          },
          "subject": {
            "type": "string"
          },
          "message_count": {
            "type": "integer"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EmailThreadMessage"
            }
          }
        },
        "required": [
          "message_count",
          "messages",
          "subject",
          "thread_id"
        ]
      },
      "EmailThreadMessage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "readOnly": true
          },
          "from_email": {
            "type": "string",
            "format": "email",
            "description": "The sender's email address",
            "maxLength": 254
          },
          "from_display_name": {
            "type": "string",
            "description": "The sender's display name from the From header",
            "maxLength": 255
          },
          "to_email": {
            "type": "string",
            "format": "email",
            "description": "The recipient's email address",
            "maxLength": 254
          },
          "cc": {
            "type": "string",
            "description": "CC recipients (comma-separated email addresses)"
          },
          "subject": {
            "type": "string",
            "description": "The email subject line (server-side encrypted)"
          },
          "text_content": {
            "type": "string",
            "description": "The plain text content of the email body (server-side encrypted)"
          },
          "html_content": {
            "type": "string",
            "description": "The HTML content of the email body (server-side encrypted)"
          },
          "direction": {
            "enum": [
              "incoming",
              "outgoing"
            ],
            "type": "string",
            "x-spec-enum-id": "0f9b1c9d69d835bd",
            "description": "Whether this message was received (incoming) or sent (outgoing)\n\n* `incoming` - Incoming\n* `outgoing` - Outgoing"
          },
          "is_read": {
            "type": "boolean",
            "description": "Whether the user has read this message"
          },
          "attachments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EmailAttachment"
            },
            "readOnly": true
          },
          "created_dt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "required": [
          "attachments",
          "created_dt",
          "from_email",
          "id",
          "to_email"
        ]
      },
      "SMSConversation": {
        "type": "object",
        "properties": {
          "conversation_id": {
            "type": "string",
            "description": "Composite key: {phone_id}_{from_number}"
          },
          "from_number": {
            "type": "string",
            "description": "External phone number in E.164 format"
          },
          "phone": {
            "type": "string",
            "nullable": true,
            "readOnly": true,
            "description": "URL to the associated RaviPhone resource"
          },
          "phone_number": {
            "type": "string",
            "description": "The Ravi phone number in E.164 format"
          },
          "preview": {
            "type": "string",
            "description": "Truncated preview of the latest message content"
          },
          "message_count": {
            "type": "integer",
            "description": "Total number of messages in the conversation"
          },
          "unread_count": {
            "type": "integer",
            "description": "Number of unread messages in the conversation"
          },
          "latest_message_dt": {
            "type": "string",
            "format": "date-time",
            "description": "Timestamp of the most recent message"
          }
        },
        "required": [
          "conversation_id",
          "from_number",
          "latest_message_dt",
          "message_count",
          "phone",
          "phone_number",
          "preview",
          "unread_count"
        ]
      },
      "SMSConversationDetail": {
        "type": "object",
        "properties": {
          "conversation_id": {
            "type": "string",
            "description": "Composite key: {phone_id}_{from_number}"
          },
          "from_number": {
            "type": "string",
            "description": "External phone number in E.164 format"
          },
          "phone": {
            "type": "string",
            "description": "The Ravi phone number in E.164 format"
          },
          "message_count": {
            "type": "integer",
            "description": "Total number of messages in the conversation"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SMSConversationMessage"
            },
            "description": "All messages in the conversation, ordered by date"
          }
        },
        "required": [
          "conversation_id",
          "from_number",
          "message_count",
          "messages",
          "phone"
        ]
      },
      "SMSConversationMessage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "readOnly": true
          },
          "body": {
            "type": "string",
            "description": "Message body (server-side encrypted)."
          },
          "direction": {
            "enum": [
              "incoming",
              "outgoing"
            ],
            "type": "string",
            "x-spec-enum-id": "0f9b1c9d69d835bd",
            "description": "Whether this message was received (incoming) or sent (outgoing)\n\n* `incoming` - Incoming\n* `outgoing` - Outgoing"
          },
          "is_read": {
            "type": "boolean",
            "description": "Whether the user has read this message"
          },
          "created_dt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "required": [
          "created_dt",
          "id"
        ]
      }
    }
  }
}
