{
  "openapi": "3.1.0",
  "info": {
    "title": "Sentry Relay API",
    "description": "The zero-retention 2FA, OTP, Magic-Link & Authenticator Vault API engineered specifically for autonomous software, AI agents, and browser automation.",
    "version": "1.0.0",
    "contact": {
      "name": "Sentry Relay Support",
      "url": "https://sentryrelay.com/docs"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://sentryrelay.com",
      "description": "Production Multi-Region Cloud Run Cluster"
    }
  ],
  "tags": [
    {
      "name": "Identities",
      "description": "Dedicated bot inboxes and routing configuration"
    },
    {
      "name": "OTP & Magic Links",
      "description": "Long-polling and non-blocking OTP extraction"
    },
    {
      "name": "TOTP Authenticator",
      "description": "Envelope-encrypted RFC 6238 2FA token generator"
    },
    {
      "name": "SMS Phone Numbers",
      "description": "Dedicated Telnyx virtual carrier DID provisioning"
    },
    {
      "name": "Webhooks",
      "description": "Pro/Agency real-time HMAC-signed event dispatchers"
    },
    {
      "name": "Audit Logs",
      "description": "Sanitized compliance and event history"
    },
    {
      "name": "Model Context Protocol",
      "description": "Streamable HTTP MCP tool endpoint"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/api/v1/identities": {
      "get": {
        "tags": ["Identities"],
        "summary": "List accessible Identities",
        "description": "Returns cursor-paginated Identities accessible to the authenticated API key (filtered by scopedIdentityIds if the key is scoped).",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": "Maximum number of Identities to return per page (1..100, default: 50)."
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque pagination cursor returned by a previous page."
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of Identities",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Identity"
                          }
                        },
                        "nextCursor": {
                          "type": "string",
                          "nullable": true
                        }
                      }
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/UnauthorizedError" }
        }
      },
      "post": {
        "tags": ["Identities"],
        "summary": "Create a new Identity",
        "description": "Provisions a new isolated Identity inbox with a unique @in.sentryrelay.com inbound email address, optional Human-Fallback Safety Bridge™ routing, and optional custom extraction regex rules.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateIdentityRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created Identity",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "identity": {
                          "$ref": "#/components/schemas/Identity"
                        }
                      }
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationError" },
          "401": { "$ref": "#/components/responses/UnauthorizedError" },
          "403": { "$ref": "#/components/responses/PlanLimitError" }
        }
      }
    },
    "/api/v1/identities/{id}": {
      "get": {
        "tags": ["Identities"],
        "summary": "Get Identity details",
        "description": "Retrieves full configuration and attached channel metadata for a single Identity by ID (id_...) or slug.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID (e.g. id_01J...) or unique slug (e.g. checkout-bot)."
          }
        ],
        "responses": {
          "200": {
            "description": "Identity details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "identity": {
                          "$ref": "#/components/schemas/Identity"
                        }
                      }
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFoundError" }
        }
      },
      "patch": {
        "tags": ["Identities"],
        "summary": "Update Identity configuration",
        "description": "Updates an Identity's display name, active/paused status, Human-Fallback Safety Bridge™ routing, or custom regex extraction rules.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID (e.g. id_01J...) or unique slug."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateIdentityRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated Identity",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "identity": {
                          "$ref": "#/components/schemas/Identity"
                        }
                      }
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationError" },
          "404": { "$ref": "#/components/responses/NotFoundError" }
        }
      },
      "delete": {
        "tags": ["Identities"],
        "summary": "Delete Identity",
        "description": "Permanently deletes an Identity, releases any attached Telnyx SMS DID, and purges vaulted TOTP secrets.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          }
        ],
        "responses": {
          "200": {
            "description": "Identity deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean"
                        },
                        "id": {
                          "type": "string"
                        }
                      }
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFoundError" }
        }
      }
    },
    "/api/v1/identities/{id}/wait": {
      "get": {
        "tags": ["OTP & Magic Links"],
        "summary": "Long-poll for verification code",
        "description": "Holds connection open up to timeout (1..45s) waiting for an unconsumed auth event via Upstash Redis Pub/Sub and a 15-second default lookback ZSET. Returns 200 OK on both match (matched: true) and clean timeout (matched: false, timedOut: true).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          },
          {
            "name": "channel",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["email", "sms"]
            },
            "description": "Optional channel filter ('email' or 'sms')."
          },
          {
            "name": "sender",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Case-insensitive sender substring filter (e.g. 'stripe.com', 'github.com', '+12035550142'). Matches unwrapped originalSender on forwarded emails."
          },
          {
            "name": "subject",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Case-insensitive email subject substring filter."
          },
          {
            "name": "timeout",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 45,
              "default": 30
            },
            "description": "Maximum seconds to hold connection open waiting for a match (1..45, default: 30)."
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Epoch millisecond timestamp to start lookback search from (defaults to now - 15000ms)."
          },
          {
            "name": "consume",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            },
            "description": "Atomically mark the matched event as consumed via CLAIM_AUTH_EVENT_LUA (default: true)."
          },
          {
            "name": "includeNonAuth",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Include non-auth emails and SMS messages (with sanitized textBody and extracted links) in addition to extracted OTPs and magic links (default: false)."
          }
        ],
        "responses": {
          "200": {
            "description": "Match found or clean timeout",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WaitResponse"
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          },
          "429": { "$ref": "#/components/responses/RateLimitError" }
        }
      }
    },
    "/api/v1/identities/{id}/latest": {
      "get": {
        "tags": ["OTP & Magic Links"],
        "summary": "Instant non-blocking timeline check",
        "description": "Checks the Identity's Redis ZSET timeline for a recently received OTP or magic link without holding a long-polling connection open.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          },
          {
            "name": "channel",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["email", "sms"]
            },
            "description": "Optional channel filter ('email' or 'sms')."
          },
          {
            "name": "sender",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Case-insensitive sender substring filter."
          },
          {
            "name": "subject",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Case-insensitive email subject substring filter."
          },
          {
            "name": "lookbackSeconds",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 600,
              "default": 60
            },
            "description": "Seconds into the past to search (1..600, default: 60)."
          },
          {
            "name": "consume",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            },
            "description": "Atomically mark the matched event as consumed (default: true)."
          },
          {
            "name": "includeNonAuth",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Include non-auth emails and SMS messages (with sanitized textBody and extracted links) in addition to extracted OTPs and magic links (default: false)."
          }
        ],
        "responses": {
          "200": {
            "description": "Lookback result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WaitResponse"
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/identities/{id}/totp": {
      "get": {
        "tags": ["TOTP Authenticator"],
        "summary": "List vaulted TOTP secret metadata",
        "description": "Returns metadata (issuer, accountLabel, algorithm, digits, period) for all TOTP secrets vaulted under the Identity. Raw Base32 seeds are never returned.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          }
        ],
        "responses": {
          "200": {
            "description": "List of vaulted TOTP secret metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/TotpSecretMetadata"
                          }
                        }
                      }
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["TOTP Authenticator"],
        "summary": "Vault a new TOTP secret",
        "description": "Encrypts and stores a new RFC 6238 TOTP authenticator seed under the Identity using Google Cloud KMS AES-256-GCM envelope encryption (context-bound to Workspace, Identity, and Secret ID). Accepts either an otpauth://totp/... URI or a manual Base32 secret + issuer.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTotpSecretRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Vaulted TOTP secret metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "secret": {
                          "$ref": "#/components/schemas/TotpSecretMetadata"
                        }
                      }
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationError" },
          "403": { "$ref": "#/components/responses/PlanLimitError" }
        }
      }
    },
    "/api/v1/identities/{id}/totp/{secretId}": {
      "get": {
        "tags": ["TOTP Authenticator"],
        "summary": "Generate live RFC 6238 TOTP code",
        "description": "Decrypts the vaulted seed in volatile memory and computes the current 6- or 8-digit TOTP code, remainingSeconds in the current window, and nextCode (when remainingSeconds <= 5s).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          },
          {
            "name": "secretId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Secret ID (e.g. 'github_ops', 'aws_root')."
          }
        ],
        "responses": {
          "200": {
            "description": "Generated TOTP code and window metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/GeneratedTotpCode"
                    },
                    "error": {
                      "type": "null"
                    }
                  }
                }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFoundError" }
        }
      },
      "delete": {
        "tags": ["TOTP Authenticator"],
        "summary": "Delete vaulted TOTP secret",
        "description": "Permanently deletes the encrypted TOTP secret from the Identity vault.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          },
          {
            "name": "secretId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Secret ID to delete."
          }
        ],
        "responses": {
          "200": {
            "description": "TOTP secret permanently deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": { "type": "boolean" },
                        "secretId": { "type": "string" }
                      }
                    },
                    "error": { "type": "null" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/identities/{id}/sms/provision": {
      "post": {
        "tags": ["SMS Phone Numbers"],
        "summary": "Provision & attach a Telnyx US DID",
        "description": "Searches and orders a dedicated US local carrier phone number (DID) via Telnyx and binds it to the Identity for inbound SMS OTPs and TeXML <Dial> voice call bridging. Requires a paid plan (Builder, Growth/Pro, or Agency) with available DID quota.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProvisionSmsDidRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Provisioned phone number attached to Identity",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "identity": { "$ref": "#/components/schemas/Identity" },
                        "phoneNumber": { "type": "string", "example": "+12035550142" },
                        "telnyxPhoneNumberId": { "type": "string", "example": "telnyx_did_01J..." }
                      }
                    },
                    "error": { "type": "null" }
                  }
                }
              }
            }
          },
          "403": { "$ref": "#/components/responses/PlanLimitError" }
        }
      }
    },
    "/api/v1/identities/{id}/sms": {
      "delete": {
        "tags": ["SMS Phone Numbers"],
        "summary": "Release attached SMS phone number",
        "description": "Releases the Telnyx US phone number currently attached to the Identity and frees up one DID slot in your workspace quota.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Identity ID or unique slug."
          }
        ],
        "responses": {
          "200": {
            "description": "Phone number released",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "released": { "type": "boolean" },
                        "phoneNumber": { "type": "string" },
                        "identityId": { "type": "string" }
                      }
                    },
                    "error": { "type": "null" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/webhooks": {
      "get": {
        "tags": ["Webhooks"],
        "summary": "List outbound webhooks",
        "description": "Lists configured HTTPS outbound webhook endpoints for the workspace.",
        "responses": {
          "200": {
            "description": "Configured webhooks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/OutboundWebhook" }
                        }
                      }
                    },
                    "error": { "type": "null" }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["Webhooks"],
        "summary": "Create outbound webhook",
        "description": "Registers a new HMAC-SHA256 signed HTTPS webhook endpoint for real-time push delivery of extracted OTPs, magic links, and non-auth fallback events (available on Growth/Pro and Agency plans).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created webhook (includes whsec_ signing secret)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "webhook": { "$ref": "#/components/schemas/OutboundWebhook" }
                      }
                    },
                    "error": { "type": "null" }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/ValidationError" },
          "403": { "$ref": "#/components/responses/PlanLimitError" }
        }
      }
    },
    "/api/v1/webhooks/{webhookId}": {
      "delete": {
        "tags": ["Webhooks"],
        "summary": "Delete outbound webhook",
        "description": "Deletes an outbound webhook subscription.",
        "parameters": [
          {
            "name": "webhookId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Webhook ID (wh_...)."
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": { "type": "boolean" },
                        "id": { "type": "string" }
                      }
                    },
                    "error": { "type": "null" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/audit-logs": {
      "get": {
        "tags": ["Audit Logs"],
        "summary": "Query sanitized audit events",
        "description": "Queries zero-PII audit logs (with masked senders like ***@stripe.com). Supports CSV export (format=csv) on Agency & Fleet plans.",
        "parameters": [
          {
            "name": "identityId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter logs by Identity ID."
          },
          {
            "name": "eventType",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by event type (e.g. 'otp.extracted', 'totp.generated', 'sms.fallback_forwarded')."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO 8601 start timestamp filter."
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO 8601 end timestamp filter."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            },
            "description": "Maximum number of audit log entries to return (1..200, default: 50)."
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["json", "csv"]
            },
            "description": "Response format ('json' on all tiers; 'csv' on Agency & Fleet tier)."
          }
        ],
        "responses": {
          "200": {
            "description": "Audit log events (JSON or text/csv)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/AuditLogEntry" }
                        }
                      }
                    },
                    "error": { "type": "null" }
                  }
                }
              }
            }
          },
          "403": { "$ref": "#/components/responses/PlanLimitError" }
        }
      }
    },
    "/api/mcp": {
      "get": {
        "tags": ["Model Context Protocol"],
        "summary": "MCP server metadata",
        "description": "Returns server capabilities and the 6 canonical MCP tool schemas.",
        "responses": {
          "200": {
            "description": "MCP server information and tool list"
          }
        }
      },
      "post": {
        "tags": ["Model Context Protocol"],
        "summary": "Streamable HTTP MCP JSON-RPC endpoint",
        "description": "Executes standard Model Context Protocol JSON-RPC 2.0 requests (initialize, tools/list, tools/call) over stateless HTTPS.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/McpJsonRpcRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 response payload"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sr_live_... / sr_test_...",
        "description": "Sentry Relay API key. Prefix sr_live_ for production or sr_test_ for sandbox."
      }
    },
    "responses": {
      "ValidationError": {
        "description": "400 VALIDATION_ERROR — Request body or query parameters failed Zod schema validation."
      },
      "UnauthorizedError": {
        "description": "401 UNAUTHORIZED — Missing, invalid, or revoked Bearer API key."
      },
      "PlanLimitError": {
        "description": "403 PLAN_LIMIT_EXCEEDED / FORBIDDEN — Workspace quota reached or key is not authorized for the target Identity."
      },
      "NotFoundError": {
        "description": "404 NOT_FOUND — Requested Identity, TOTP secret, or Webhook does not exist."
      },
      "RateLimitError": {
        "description": "429 RATE_LIMITED — Per-minute rate limit or concurrent /wait connection cap exceeded."
      }
    },
    "schemas": {
      "Identity": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique Identity ULID (e.g. id_01J9...).",
            "example": "id_01J9X7K2M4P8Q1R3S5T7V9W0Y2"
          },
          "workspaceId": {
            "type": "string",
            "description": "Owning Workspace ID (ws_...).",
            "example": "ws_01J9X7K0000000000000000000"
          },
          "name": {
            "type": "string",
            "description": "Human-readable Identity label.",
            "example": "Client Acme — Stripe & ERP Bot"
          },
          "slug": {
            "type": "string",
            "description": "Unique URL-safe kebab-case slug within the workspace.",
            "example": "client-acme"
          },
          "status": {
            "type": "string",
            "enum": ["active", "paused", "grace_suspended"],
            "description": "Operational state of the Identity inbox.",
            "example": "active"
          },
          "emailAddress": {
            "type": "string",
            "description": "Full dedicated inbound email address on @in.sentryrelay.com.",
            "example": "client-acme@in.sentryrelay.com"
          },
          "smsPhoneNumber": {
            "type": "string",
            "nullable": true,
            "description": "Attached Telnyx US carrier phone number in E.164 format (or null if none attached).",
            "example": "+12035550142"
          },
          "totpSecretCount": {
            "type": "integer",
            "description": "Number of Cloud KMS-vaulted TOTP secrets attached to this Identity.",
            "example": 2
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 creation timestamp."
          }
        },
        "required": ["id", "workspaceId", "name", "slug", "status", "emailAddress"]
      },
      "CreateIdentityRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "Human-readable name for the Identity (1..120 chars).",
            "example": "Client Acme — Checkout Bot"
          },
          "slug": {
            "type": "string",
            "minLength": 2,
            "maxLength": 64,
            "description": "Optional lowercase kebab-case identifier (auto-derived from name if omitted).",
            "example": "client-acme"
          },
          "emailHandle": {
            "type": "string",
            "minLength": 3,
            "maxLength": 64,
            "description": "Optional local-part handle before @in.sentryrelay.com (3..64 lowercase alphanumeric, dots, underscores, or hyphens).",
            "example": "client-acme"
          },
          "fallback": {
            "type": "object",
            "description": "Optional Human-Fallback Safety Bridge™ configuration for routing non-auth SMS alerts and bridging inbound voice calls (Growth/Pro & Agency tiers).",
            "properties": {
              "enabled": {
                "type": "boolean",
                "default": false,
                "description": "Enable live human fallback routing for non_auth messages and voice calls."
              },
              "fallbackEmail": {
                "type": "string",
                "format": "email",
                "nullable": true,
                "description": "Operator or client email address to receive non-OTP SMS alerts via Resend."
              },
              "fallbackWebhookUrl": {
                "type": "string",
                "format": "uri",
                "nullable": true,
                "description": "HTTPS webhook URL (e.g. Slack/Discord incoming webhook) for non-OTP SMS alerts."
              },
              "voiceForwardToE164": {
                "type": "string",
                "nullable": true,
                "description": "E.164 phone number (e.g. +14155550199) to bridge inbound voice calls via Telnyx TeXML <Dial>."
              }
            }
          },
          "customRules": {
            "type": "array",
            "maxItems": 10,
            "description": "Optional custom deterministic regex rules evaluated in Stage 4 (up to 10 rules per Identity).",
            "items": {
              "type": "object",
              "properties": {
                "id": { "type": "string", "description": "Unique rule ID (1..64 chars)." },
                "name": { "type": "string", "description": "Rule label (1..120 chars)." },
                "senderContains": { "type": "string", "description": "Optional sender substring trigger." },
                "subjectContains": { "type": "string", "description": "Optional subject substring trigger." },
                "otpRegex": { "type": "string", "description": "Regex with capture group 1 for the OTP code." },
                "magicLinkRegex": { "type": "string", "description": "Regex with capture group 1 for the magic link URL." },
                "enabled": { "type": "boolean", "default": true }
              },
              "required": ["id", "name"]
            }
          }
        },
        "required": ["name"],
        "example": {
          "name": "Client Acme — Checkout Bot",
          "slug": "client-acme",
          "emailHandle": "client-acme",
          "fallback": {
            "enabled": true,
            "fallbackEmail": "ops@acme-client.com",
            "fallbackWebhookUrl": "https://hooks.slack.com/services/T000/B000/X000",
            "voiceForwardToE164": "+14155550199"
          }
        }
      },
      "UpdateIdentityRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "Updated human-readable display name."
          },
          "status": {
            "type": "string",
            "enum": ["active", "paused"],
            "description": "Set to 'paused' to temporarily stop ingesting inbound emails/SMS on this Identity."
          },
          "fallback": {
            "type": "object",
            "description": "Partial or full update to the Human-Fallback Safety Bridge™ configuration.",
            "properties": {
              "enabled": {
                "type": "boolean",
                "description": "Enable or disable Human-Fallback routing."
              },
              "fallbackEmail": {
                "type": "string",
                "format": "email",
                "nullable": true,
                "description": "Destination email for non-auth SMS alerts (or null to clear)."
              },
              "fallbackWebhookUrl": {
                "type": "string",
                "format": "uri",
                "nullable": true,
                "description": "HTTPS webhook URL for non-auth SMS alerts (or null to clear)."
              },
              "voiceForwardToE164": {
                "type": "string",
                "nullable": true,
                "description": "E.164 phone number for TeXML <Dial> voice call bridging (or null to clear)."
              }
            }
          },
          "customRules": {
            "type": "array",
            "maxItems": 10,
            "description": "Replacement array of custom Stage 4 regex extraction rules (max 10)."
          }
        },
        "example": {
          "name": "Client Acme — Production ERP Bot",
          "status": "active",
          "fallback": {
            "enabled": true,
            "fallbackEmail": "oncall@acme-client.com",
            "voiceForwardToE164": "+14155550199"
          }
        }
      },
      "WaitResponse": {
        "type": "object",
        "properties": {
          "matched": {
            "type": "boolean",
            "description": "True if a matching unconsumed auth event was claimed."
          },
          "timedOut": {
            "type": "boolean",
            "description": "True if the wait window elapsed with no matching event."
          },
          "event": {
            "type": "object",
            "nullable": true,
            "description": "The extracted verification event (or null on timeout).",
            "properties": {
              "id": {
                "type": "string",
                "example": "evt_01J9X8..."
              },
              "channel": {
                "type": "string",
                "enum": ["email", "sms"]
              },
              "classification": {
                "type": "string",
                "enum": ["otp", "magic_link", "otp_and_link", "non_auth"]
              },
              "otpCode": {
                "type": "string",
                "nullable": true,
                "example": "849201"
              },
              "magicLink": {
                "type": "string",
                "nullable": true,
                "example": "https://dashboard.stripe.com/login/verify?token=..."
              },
              "sender": {
                "type": "string",
                "example": "support@stripe.com"
              },
              "subject": {
                "type": "string",
                "nullable": true,
                "example": "Your Stripe verification code"
              },
              "confidence": {
                "type": "number",
                "example": 0.99
              },
              "textBody": {
                "type": "string",
                "nullable": true,
                "description": "Sanitized plain-text message body held in volatile Redis RAM for the workspace TTL."
              },
              "links": {
                "type": "array",
                "description": "All extracted HTTP/HTTPS links found in the message.",
                "items": {
                  "type": "object",
                  "properties": {
                    "text": { "type": "string" },
                    "href": { "type": "string", "format": "uri" }
                  }
                }
              },
              "expiresAtMs": {
                "type": "integer",
                "description": "Epoch millisecond timestamp when this message will be automatically evicted from Redis RAM."
              },
              "receivedAtIso": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "waitDurationMs": {
            "type": "integer",
            "description": "Total milliseconds elapsed during the wait call.",
            "example": 142
          }
        },
        "required": ["matched", "timedOut", "waitDurationMs"]
      },
      "TotpSecretMetadata": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "github_ops"
          },
          "issuer": {
            "type": "string",
            "example": "GitHub"
          },
          "accountLabel": {
            "type": "string",
            "example": "bot@company.com"
          },
          "algorithm": {
            "type": "string",
            "enum": ["SHA1", "SHA256", "SHA512"]
          },
          "digits": {
            "type": "integer",
            "enum": [6, 8]
          },
          "period": {
            "type": "integer",
            "enum": [30, 60]
          },
          "lastUsedAt": {
            "type": "string",
            "nullable": true
          }
        },
        "required": ["id", "issuer", "accountLabel", "algorithm", "digits", "period"]
      },
      "GeneratedTotpCode": {
        "type": "object",
        "properties": {
          "secretId": {
            "type": "string",
            "example": "github_ops"
          },
          "issuer": {
            "type": "string",
            "example": "GitHub"
          },
          "accountLabel": {
            "type": "string",
            "example": "bot@company.com"
          },
          "code": {
            "type": "string",
            "description": "Current 6- or 8-digit RFC 6238 code.",
            "example": "492817"
          },
          "remainingSeconds": {
            "type": "integer",
            "description": "Seconds remaining before the current window expires (1..60).",
            "example": 24
          },
          "nextCode": {
            "type": "string",
            "description": "Pre-computed code for the next window (included when remainingSeconds <= 5s)."
          },
          "period": {
            "type": "integer",
            "example": 30
          },
          "digits": {
            "type": "integer",
            "example": 6
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": ["code", "remainingSeconds", "period", "digits"]
      },
      "CreateTotpSecretRequest": {
        "type": "object",
        "description": "Provide EITHER (1) otpauthUri ('otpauth://totp/...') OR (2) manual Base32 secret + issuer.",
        "properties": {
          "id": {
            "type": "string",
            "maxLength": 64,
            "description": "Optional custom slug/ID for this secret (e.g. 'github_ops', 'aws_root'). Alphanumeric, underscores, or hyphens."
          },
          "otpauthUri": {
            "type": "string",
            "description": "Full otpauth://totp/... URI exported from an authenticator setup screen (automatically parses secret, issuer, accountLabel, algorithm, digits, and period)."
          },
          "secret": {
            "type": "string",
            "minLength": 8,
            "description": "Raw RFC 4648 Base32 secret string (used when otpauthUri is not provided, e.g. 'JBSWY3DPEHPK3PXP')."
          },
          "issuer": {
            "type": "string",
            "maxLength": 120,
            "description": "Service issuer name (required when providing raw Base32 secret, e.g. 'GitHub', 'AWS')."
          },
          "accountLabel": {
            "type": "string",
            "maxLength": 120,
            "default": "default",
            "description": "Account label associated with the TOTP secret (default: 'default')."
          },
          "algorithm": {
            "type": "string",
            "enum": ["SHA1", "SHA256", "SHA512"],
            "default": "SHA1",
            "description": "HMAC hashing algorithm (default: 'SHA1')."
          },
          "digits": {
            "type": "integer",
            "enum": [6, 8],
            "default": 6,
            "description": "Number of digits in generated code (6 or 8, default: 6)."
          },
          "period": {
            "type": "integer",
            "enum": [30, 60],
            "default": 30,
            "description": "Rotation window in seconds (30 or 60, default: 30)."
          }
        },
        "example": {
          "id": "github_ops",
          "secret": "JBSWY3DPEHPK3PXP",
          "issuer": "GitHub",
          "accountLabel": "bot-runner@company.com",
          "algorithm": "SHA1",
          "digits": 6,
          "period": 30
        }
      },
      "ProvisionSmsDidRequest": {
        "type": "object",
        "properties": {
          "areaCode": {
            "type": "string",
            "description": "Optional 3-digit US area code preference (e.g. '203', '415', '646')."
          },
          "phoneNumberE164": {
            "type": "string",
            "description": "Optional specific E.164 phone number to provision from available Telnyx inventory (e.g. '+12035550142')."
          }
        },
        "example": {
          "areaCode": "415"
        }
      },
      "CreateWebhookRequest": {
        "type": "object",
        "properties": {
          "targetUrl": {
            "type": "string",
            "format": "uri",
            "description": "HTTPS endpoint URL that will receive POST webhook deliveries signed with X-SentryRelay-Signature."
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "description": "List of event types to subscribe to (at least 1 required).",
            "items": {
              "type": "string",
              "enum": ["otp.extracted", "magic_link.extracted", "sms.fallback_triggered", "email.fallback_triggered"]
            }
          },
          "scopedIdentityIds": {
            "type": "array",
            "nullable": true,
            "description": "Optional list of Identity IDs to restrict this webhook to (null = all workspace Identities).",
            "items": {
              "type": "string"
            }
          }
        },
        "required": ["targetUrl", "events"],
        "example": {
          "targetUrl": "https://api.your-agency.com/webhooks/sentryrelay",
          "events": ["otp.extracted", "magic_link.extracted", "sms.fallback_triggered"],
          "scopedIdentityIds": ["id_01J9X7K2M4P8Q1R3S5T7V9W0Y2"]
        }
      },
      "OutboundWebhook": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "wh_01J9..." },
          "workspaceId": { "type": "string" },
          "targetUrl": { "type": "string", "format": "uri" },
          "events": {
            "type": "array",
            "items": { "type": "string" }
          },
          "scopedIdentityIds": {
            "type": "array",
            "nullable": true,
            "items": { "type": "string" }
          },
          "secret": {
            "type": "string",
            "description": "HMAC-SHA256 signing secret (whsec_...).",
            "example": "whsec_94k20a..."
          },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      },
      "AuditLogEntry": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "log_01J9..." },
          "workspaceId": { "type": "string" },
          "identityId": { "type": "string", "nullable": true },
          "eventType": { "type": "string", "example": "otp.extracted" },
          "metadata": {
            "type": "object",
            "description": "Sanitized, zero-PII event metadata (senders masked as ***@domain.com)."
          },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      },
      "McpJsonRpcRequest": {
        "type": "object",
        "properties": {
          "jsonrpc": {
            "type": "string",
            "description": "JSON-RPC protocol version (must be '2.0').",
            "example": "2.0"
          },
          "id": {
            "type": ["string", "number", "null"],
            "description": "Request correlation ID.",
            "example": 1
          },
          "method": {
            "type": "string",
            "description": "MCP JSON-RPC method ('initialize', 'tools/list', or 'tools/call').",
            "example": "tools/call"
          },
          "params": {
            "type": "object",
            "description": "Method parameters (for 'tools/call', pass { name, arguments })."
          }
        },
        "required": ["jsonrpc", "method"],
        "example": {
          "jsonrpc": "2.0",
          "id": 1,
          "method": "tools/call",
          "params": {
            "name": "wait_for_verification_code",
            "arguments": {
              "identity": "client-acme",
              "sender": "stripe.com",
              "timeoutSeconds": 30
            }
          }
        }
      }
    }
  }
}
