{
  "openapi": "3.1.0",
  "info": {
    "title": "SendHarbor Platform API",
    "version": "1.15.1",
    "description": "Кабинет клиентов и API отправки через выделенные Android-телефоны. Cookie mutations требуют X-CSRF-Token; API ключ определяет tenant и разрешённые scopes. QR содержит одноразовый код: по умолчанию 20 минут либо явно выбранный бессрочный режим. Отправка проходит через сохраняемую очередь и лимиты SIM. SMSGate credentials никогда не передаются браузеру. Контракт для интеграции платформы. Внутренний mobile proxy использует совместимый протокол SMSGate v1.51.1; регистрация через одноразовый QR описана отдельно. Подписанные команды и события Magenda: HMAC-SHA256 по timestamp.rawBody, допуск времени 300 секунд, постоянные ID для повторов. Полный протокол: docs/webhooks.md. Необязательный email при создании QR автоматически связывается с телефоном после успешной регистрации; клиент определяется API-ключом, отдельные ID клиники/пользователя не нужны. Это контакт платформы, не создание login и не проверка владения почтой. Optional webhook provisioning through the QR API requires devices:write, integrations:write and idempotencyKey. The platform generates and saves the secret; it is never echoed in API, QR or mobile responses. Version 1.6 adds absolute deadlines, read-only signed validation before dispatch, cancellation tombstones, tenant phone STOP/START suppression and audited unknown-outcome acknowledgement. Version 1.7 adds managed Magenda portal access, explicit admin/support roles, account controls, stable message pagination, nicknames, offboarding and a persisted guided SMS verification. SIM document moderation is retired: no administrator approval or operator-document submission is required. The sender/recipient profile remains enabled by default: technical SIM identity, tenant sender settings, purpose-specific customer-reported recipient consent and a recipient-local sending window are independent sending conditions. These records do not register a brand/campaign or verify legal/operator approval. Existing queues wait until prerequisites are satisfied, subject to their original expiry. Router extension: invitation-based owners, isolated projects and keys, owner/operator/viewer membership, phone pools, late route binding and external message IDs. New project webhooks add projectId; legacy event allowlists are preserved. New projects may use public HTTPS callbacks; DNS/IP pinning, private-network rejection and no-redirect policy still apply. Platform/account extension: platform projects own integration credentials and isolated client accounts. A client account remains the tenant data boundary; email never merges accounts. Platform keys require explicit accountId for account API calls. New managed webhooks contain parent projectId and accountId; legacy contracts are preserved. Usage is an immutable deduplicated ledger; billing is currently free. See docs/platform-accounts.md. Integration channels: HTTP commands, signed webhook commands and opt-in WebSocket; outgoing webhook events independently selectable. Named immutable batches share the existing queue and per-SIM guards. Realtime journal retention7 days /10,000 events per account, explicit cursor-gap handling. Public guide: /docs; contract: /docs/openapi.json. Local feature extension: separate sandbox keys/storage/scenarios and explicit test callbacks; queued-only replaceKey/replaceVersion with monotonic race protection; private temporary /connect onboarding link and exact-origin embed module. See docs/gateway-features.md. Live SIM testing: explicit customer-controlled 60-minute real SMS trials, one proven recipient per SIM, durable rolling segment budgets, no commercial clearance. Optional first-party test webhook inbox retains signed-event metadata only. Public guide /docs#docs-live-sim-test; endpoint receipts never prove SMS delivery."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "components": {
    "securitySchemes": {
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "sms_session"
      },
      "csrf": {
        "type": "apiKey",
        "in": "header",
        "name": "X-CSRF-Token"
      },
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Tenant key with devices:read/write, messages:read/send, integrations:write scopes. integrations:write allows QR provisioning and reading existing integration identity; manual writes require a full session."
      },
      "pairingCode": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Code <одноразовый код из QR>. По умолчанию 20 минут; static действует до использования или отзыва. Не API-ключ кабинета."
      },
      "mobileToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "Индивидуальный токен Android-устройства, полученный при QR-привязке. Не API-ключ кабинета. Mobile proxy принимает только активное локально привязанное устройство готового клиента; отзыв закрывает открытые соединения. На proxy: 600 запросов/мин на устройство, 6000/мин на IP, 16 соединений на устройство (из них до 2 SSE), 4096 всего. Превышение лимита устройства даёт 429, общей ёмкости — 503."
      },
      "webhookTimestamp": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Sms-Timestamp",
        "description": "Unix timestamp в секундах; отклонение от времени сервера не более 300 секунд. При повторе обновляется."
      },
      "webhookSignature": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Sms-Signature",
        "description": "sha256=<lowercase hex HMAC-SHA256(secret UTF-8, timestamp + \".\" + точное исходное JSON-тело UTF-8)>. Секрет не base64-декодируется."
      },
      "provisioning": {
        "type": "http",
        "scheme": "bearer",
        "description": "Server-only PROVISIONING_TOKEN shp_ followed by 43 base64url characters; cannot access normal tenant API."
      },
      "platformKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Platform backend key spk_ +43 base64url characters. Only its own accounts; explicit accountId query or X-SendHarbor-Account required for account APIs. Never share with customers/Android."
      },
      "websocketTicket": {
        "type": "apiKey",
        "in": "header",
        "name": "Sec-WebSocket-Protocol",
        "description": "Two subprotocols: sendharbor.v1 and ticket.<one-use-ticket>. The server selects sendharbor.v1; ticket is not echoed as selected protocol. Never put credentials in URL."
      },
      "sandboxKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "ssk_ plus43 base64url characters; seven-day account-bound test key. ONLY /api/sandbox. Cannot enroll phones, access real messages/keys, mint WS tickets or create further keys. Parent key revocation invalidates derived test keys."
      },
      "onboardingLink": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Onboarding plus the short-lived43-character fragment token. Restricted status and customer email-confirmation operations for one setup/account. Never project management, owner acceptance or cellular sending; no account/device selectors."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "requestId": {
                "type": "string",
                "format": "uuid",
                "description": "Тот же ID в X-Request-ID. Можно передать поддержке; тело запроса и секреты в журнал не записываются."
              },
              "onboarding": {
                "$ref": "#/components/schemas/OnboardingRecovery",
                "description": "Optional, only for authenticated matching POST /api/pairings replay that returns pairing_not_pending; never for arbitrary errors."
              },
              "legal": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "string"
                  },
                  "termsUrl": {
                    "type": "string"
                  },
                  "acceptanceUrl": {
                    "type": "string"
                  },
                  "action": {
                    "enum": [
                      "project_owner_acceptance",
                      "customer_acceptance",
                      "company_acceptance"
                    ]
                  },
                  "sessionId": {
                    "type": "string"
                  },
                  "allowedOrigin": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "kind": {
                    "enum": [
                      "integrator",
                      "sender",
                      "company"
                    ]
                  },
                  "accountId": {
                    "type": "string"
                  },
                  "projectId": {
                    "type": "string"
                  },
                  "acceptInApp": {
                    "type": "boolean"
                  }
                },
                "description": "terms_acceptance_required is the contracting owner integration hold. sender_terms_acceptance_required uses legal.kind=sender for one customer in customer mode or company for the owner coverage hold. Company mode requires no customer assent; follow legal.action and the current mode. Metadata remains scoped to the authenticated connection."
              },
              "missingVariables": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,31}$"
                },
                "description": "Only for template_variables_missing: every variable without a value, in order of first appearance."
              }
            }
          }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "name": {
            "type": "string"
          },
          "role": {
            "enum": [
              "admin",
              "customer"
            ]
          },
          "tenantId": {
            "type": [
              "string",
              "null"
            ]
          },
          "mfaEnabled": {
            "type": "boolean"
          },
          "mfaSetupRequired": {
            "type": "boolean"
          }
        }
      },
      "Session": {
        "type": "object",
        "properties": {
          "user": {
            "$ref": "#/components/schemas/User"
          },
          "csrfToken": {
            "type": "string"
          },
          "capabilities": {
            "type": "object",
            "properties": {
              "projects": {
                "type": "boolean"
              }
            },
            "required": [],
            "additionalProperties": false
          },
          "legal": {
            "$ref": "#/components/schemas/ServiceTermsDescriptor"
          }
        }
      },
      "Tenant": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Device": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "lastSeen": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "simCards": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "readiness": {
            "$ref": "#/components/schemas/Readiness"
          },
          "platformUser": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/PlatformUser"
              },
              {
                "type": "null"
              }
            ],
            "description": "Контакт из успешно использованного QR; null для подключений без email, включая прежние устройства."
          },
          "sending": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DeviceSending"
              },
              {
                "type": "null"
              }
            ],
            "description": "Compact runtime for this phone in the selected tenant. API keys need messages:read as well as devices:read; otherwise null. Customer/read-only/managed sessions remain tenant-scoped. Null or unavailable is not a zero queue or a ready phone."
          }
        }
      },
      "Pairing": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "enum": [
              "pending",
              "registering",
              "linked",
              "failed",
              "expired",
              "cancelled"
            ]
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "deviceId": {
            "type": "string"
          },
          "qrDataUrl": {
            "type": "string",
            "description": "Contains the one-time enrollment code. Returned on creation and identical pending POST replay with idempotencyKey; never returned by GET or written to logs."
          },
          "serverUrl": {
            "type": "string"
          },
          "mode": {
            "enum": [
              "temporary",
              "static"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "enrollmentPayload": {
            "$ref": "#/components/schemas/EnrollmentPayload",
            "description": "Contains the one-time enrollment code. Returned on creation and identical pending POST replay with idempotencyKey; never returned by GET or written to logs."
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "maxLength": 254,
            "description": "Нормализованный email из запроса либо null. Доступен также в GET; до успешной регистрации не создаёт связь с телефоном. Не включается в QR/enrollmentPayload."
          },
          "principalId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 128,
            "description": "Stable authenticated platform identity; email remains a label."
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Null while a pool job has no eligible phone. A planned route can change before dispatch; dispatched routes are immutable."
          },
          "phone": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "description": "Queued — только серверная очередь; submitting/unknown — результат неоднозначен, автоповтора нет; Pending/Processed/Sent/Delivered/Failed — шлюз; rejected — отказ; expired/cancelled — завершено до передачи шлюзу."
          },
          "stateSource": {
            "enum": [
              "portal",
              "gateway"
            ]
          },
          "statusCheckedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "error": {
            "type": "string"
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8,
            "description": "Null while an automatic route is unassigned. Actual slot is captured at hand-off."
          },
          "segments": {
            "type": "integer",
            "minimum": 1
          },
          "encoding": {
            "enum": [
              "GSM-7",
              "UCS-2"
            ]
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "nextAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "queueReason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Причина ожидания: paused, interval, second_limit, minute_limit, hour_limit, day_limit, month_limit, quiet_hours, awaiting_device, circuit_open, integration_paused, callback_backlog, gateway_unavailable, validation_unavailable, waiting. Срок следующей проверки не является гарантией времени доставки. Since 1.10.0: billing_limit and temporary_network. No new send occurs before all independent conditions and the deadline permit it. SIM document review is retired. Technical holds include diagnostics_stale, sim_missing, sim_identity_unavailable, sim_identity_changed and app_upgrade_required. With the sender/recipient profile enabled, independent holds include us_business_profile_required, us_consent_required, us_consent_expired, us_consent_revoked, us_recipient_quiet_hours and us_control_stale. An offline phone or missing consent/profile has no promised resume time. Recipient quiet hours supply the next eligible UTC instant; every other gate and expiry must still permit dispatch. scheduled: no cellular hand-off before sendAt; automatically resumes when due and all other gates allow it. Live tests may wait with live_test_limit and resume only before their original expiry; invalidated, revoked or expired trial contexts cannot authorize dispatch. risk_review: SendHarbor paused the account after risk signals; the SMS keeps its original expiry and resumes when an administrator lifts the pause (GET /api/risk-review). content_review: the text and link check held this SMS at admission (docs/risk-review.md); it is accepted, keeps its original expiry and continues when an administrator releases it, or ends cancelled with error CONTENT_REVIEW_CANCELLED. GET /api/messages/{id} names the rule in contentReview."
          },
          "resolution": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/MessageResolution"
              },
              {
                "type": "null"
              }
            ],
            "description": "Audited operator acknowledgement. Does not assert delivery and never resends this SMS. Later real gateway receipts may still update its state."
          },
          "redactedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "platformUser": {
            "$ref": "#/components/schemas/MessagePlatformUser"
          },
          "deviceName": {
            "type": [
              "string",
              "null"
            ]
          },
          "sender": {
            "$ref": "#/components/schemas/MessageSender"
          },
          "routing": {
            "$ref": "#/components/schemas/MessageRouting"
          },
          "status": {
            "$ref": "#/components/schemas/MessageStatus"
          },
          "submittedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "timeline": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "object",
              "properties": {
                "sequence": {
                  "type": "integer",
                  "minimum": 1
                },
                "state": {
                  "type": "string"
                },
                "phase": {
                  "enum": [
                    "queued",
                    "submitted",
                    "sending",
                    "sent",
                    "delivered",
                    "failed",
                    "expired",
                    "cancelled",
                    "unknown"
                  ]
                },
                "reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "occurredAt": {
                  "type": "string",
                  "format": "date-time"
                },
                "error": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "sequence",
                "state",
                "phase",
                "reason",
                "occurredAt",
                "error"
              ],
              "additionalProperties": false
            },
            "description": "Last 50 server observations, chronological. Sequence continues beyond this window. Missing historical milestones are not reconstructed."
          },
          "priority": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2,
            "default": 0,
            "description": "0 normal, 1 high, 2 urgent. Only undispatched messages are reordered. Same recipient on the same route remains FIFO; explicit different SIM routes remain independent. Waiting increases effective priority every 10 minutes, preventing normal traffic starvation. Priority does not bypass quotas, quiet hours, STOP, sender affinity or expiry. Changing priority on a nonzero-priority idempotent request conflicts; omitted and 0 preserve the legacy hash. An unassigned automatic request preserves recipient order with every earlier explicit/automatic request; a later explicit request cannot jump across it."
          },
          "purpose": {
            "$ref": "#/components/schemas/MessagePurpose"
          },
          "projectId": {
            "type": "string",
            "description": "Parent platform ID for managed accounts; legacy project contract otherwise"
          },
          "poolId": {
            "type": [
              "string",
              "null"
            ]
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ]
          },
          "accountId": {
            "type": "string",
            "description": "Client owner for managed accounts"
          },
          "replacement": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "key",
              "version",
              "replacedBy"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "version": {
                "type": "integer"
              },
              "replacedBy": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "sendAt": {
            "type": "string",
            "format": "date-time",
            "description": "Optional original scheduled instant; absent on legacy/immediate messages. Remains available after completion."
          },
          "liveTest": {
            "type": "boolean",
            "description": "True for a real controlled Live SIM test message; false/absent is ordinary traffic. This is not sandbox simulation or commercial carrier approval. Legacy ordinary webhook payloads omit this extension."
          },
          "retryOf": {
            "type": "string",
            "description": "Original message ID for an administrator-confirmed retry in the same account. The retry is a separate message; follow retryOf to recover the original externalId. Present from its first queued status event."
          },
          "contentReview": {
            "$ref": "#/components/schemas/ContentReview",
            "description": "Only in GET /api/messages/{id}, and only for an SMS the text and link check held."
          }
        }
      },
      "Key": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "prefix": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "items": {
              "enum": [
                "devices:read",
                "devices:write",
                "messages:read",
                "messages:send",
                "integrations:write"
              ]
            }
          },
          "createdAt": {
            "type": "string"
          },
          "lastUsedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "revokedAt": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "MessageInput": {
        "type": "object",
        "required": [
          "phone",
          "text",
          "idempotencyKey"
        ],
        "properties": {
          "deviceId": {
            "type": "string",
            "description": "The phone that sends this SMS. Required unless poolId is set."
          },
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000,
            "description": "The exact SMS text is stored without trimming. At most 5000 UTF-16 code units; text that is empty or only whitespace is rejected."
          },
          "idempotencyKey": {
            "type": "string",
            "minLength": 8,
            "maxLength": 128,
            "description": "One key per intent to send. A repeat with the same content returns the same message. Changed content returns 409. An unknown outcome is never retried automatically. The us-control: prefix is reserved for internal, payload-bound replies and is rejected for public message admission."
          },
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8,
            "description": "1-based SIM slot. Explicit slot never automatically falls back. If omitted: fixed mode pins the preferred SIM at admission; automatic mode selects an eligible SIM at hand-off. Android 5.0 supports only SIM1/system default. The default US profile requires API 22+ accepted SIM identity; API 21 cannot qualify for that profile."
          },
          "ttlSeconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 604800,
            "description": "How long the message may wait before sending. Defaults to the policy value (86400). With sendAt, TTL starts at max(server admission, sendAt); expiresAt remains an earlier hard deadline and must be after sendAt."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "description": "Absolute ISO 8601 deadline with timezone, fixed at business-event creation. Effective expiry is the earlier of expiresAt and TTL; expired input remains idempotently expired and is never dispatched."
          },
          "priority": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2,
            "default": 0,
            "description": "0 normal, 1 high, 2 urgent. Only undispatched messages are reordered. Same recipient on the same route remains FIFO; explicit different SIM routes remain independent. Waiting increases effective priority every 10 minutes, preventing normal traffic starvation. Priority does not bypass quotas, quiet hours, STOP, sender affinity or expiry. Changing priority on a nonzero-priority idempotent request conflicts; omitted and 0 preserve the legacy hash. An unassigned automatic request preserves recipient order with every earlier explicit/automatic request; a later explicit request cannot jump across it."
          },
          "purpose": {
            "$ref": "#/components/schemas/MessagePurpose"
          },
          "poolId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "replaceKey": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
            "description": "Account-scoped business notification key. Requires replaceVersion. Only the previous queued, undispatched SMS can be superseded."
          },
          "replaceVersion": {
            "type": "integer",
            "minimum": 1,
            "maximum": 2147483647,
            "description": "Strictly increasing business revision. Old/equal versions reject with 409; exact idempotency replays return their original (possibly superseded) message."
          },
          "sendAt": {
            "type": "string",
            "format": "date-time",
            "description": "Send no earlier than this absolute ISO 8601 instant with timezone. At most 30 days after server admission. Past times are immediately due. Durable server-side scheduling; future jobs do not block due conversations or reserve SIM capacity. TTL starts at max(admission time, sendAt). All limits, STOP, consent, carrier permission and quiet-hour checks run again at dispatch. This is not a delivery-time guarantee."
          },
          "maxSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "Optional safety cap on estimated SMS parts per message. A larger payload is rejected before admission (message_segment_limit); a batch is atomic. No silent truncation, transliteration or rewriting. Omitted preserves legacy behavior; the web composer pins the reviewed estimate by default. Not a carrier bill or delivery guarantee. Changing the cap on an idempotent retry conflicts."
          }
        },
        "oneOf": [
          {
            "required": [
              "deviceId"
            ],
            "not": {
              "required": [
                "poolId"
              ]
            }
          },
          {
            "required": [
              "poolId"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "deviceId"
                  ]
                },
                {
                  "required": [
                    "simNumber"
                  ]
                }
              ]
            }
          }
        ],
        "description": "Choose deviceId or poolId. An empty/unavailable pool retains the job until TTL. externalId is unique within this project; retries use the same idempotencyKey. Pool routing never repeats an already dispatched or unknown attempt on another device. replaceKey and replaceVersion must be supplied together. Unknown/submitted/sent outcomes cannot be replaced; changing recipient/sender never permits a second attempt of an uncertain SMS."
      },
      "Integration": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "enabled": {
            "type": "boolean"
          },
          "endpoint": {
            "type": "string",
            "format": "uri"
          },
          "commandUrl": {
            "type": "string",
            "format": "uri"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "lastError": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "enabled",
          "endpoint",
          "commandUrl",
          "createdAt",
          "updatedAt"
        ]
      },
      "IntegrationInput": {
        "type": "object",
        "properties": {
          "endpoint": {
            "type": "string",
            "format": "uri",
            "maxLength": 2000,
            "description": "HTTPS URL разрешённого hostname без credentials/query/fragment. {integrationId} заменяется ID. HTTP/private networks только при явном local-test server config."
          },
          "enabled": {
            "type": "boolean",
            "description": "При false приостанавливаются приём новых команд и доставка событий; очереди сохраняются."
          }
        },
        "required": [
          "endpoint",
          "enabled"
        ]
      },
      "IntegrationSaved": {
        "type": "object",
        "properties": {
          "integration": {
            "$ref": "#/components/schemas/Integration"
          },
          "secret": {
            "type": "string",
            "description": "Показывается только при первом создании или ротации. 32 случайных байта в base64url; сам текст строки используется как ключ HMAC."
          }
        },
        "required": [
          "integration"
        ]
      },
      "DeliverySummary": {
        "type": "object",
        "properties": {
          "pending": {
            "type": "integer",
            "minimum": 0
          },
          "delivered": {
            "type": "integer",
            "minimum": 0
          },
          "failed": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "pending",
          "delivered",
          "failed"
        ]
      },
      "WebhookDelivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "type": "string"
          },
          "status": {
            "enum": [
              "pending",
              "delivering",
              "delivered",
              "failed"
            ]
          },
          "attempts": {
            "type": "integer",
            "minimum": 0
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "nextAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastError": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "type",
          "status",
          "attempts",
          "createdAt",
          "deliveredAt",
          "nextAttemptAt",
          "lastError"
        ]
      },
      "SmsCommand": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Постоянный ID команды для всех повторов."
          },
          "version": {
            "const": 1
          },
          "type": {
            "const": "sms.send"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "properties": {
              "externalId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              },
              "deviceId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              },
              "phone": {
                "type": "string",
                "pattern": "^\\+[1-9]\\d{6,14}$",
                "maxLength": 16
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 5000,
                "description": "The exact SMS text is stored without trimming. At most 5000 UTF-16 code units; text that is empty or only whitespace is rejected."
              },
              "simNumber": {
                "type": "integer",
                "minimum": 1,
                "maximum": 8,
                "description": "1-based SIM slot. Explicit slot never automatically falls back. If omitted: fixed mode pins the preferred SIM at admission; automatic mode selects an eligible SIM at hand-off. Android 5.0 supports only SIM1/system default. The default US profile requires API 22+ accepted SIM identity; API 21 cannot qualify for that profile."
              },
              "ttlSeconds": {
                "type": "integer",
                "minimum": 60,
                "maximum": 604800,
                "description": "Срок от сохранения команды сервером, не от начала поздней обработки. Не доверяет удалённому createdAt."
              },
              "expiresAt": {
                "type": "string",
                "format": "date-time",
                "description": "Absolute ISO 8601 deadline with timezone, fixed at business-event creation. Effective expiry is the earlier of expiresAt and TTL; expired input remains idempotently expired and is never dispatched."
              },
              "requireValidation": {
                "type": "boolean",
                "description": "Requires expiresAt. Before dispatch the signed callback message.validate must return exactly 204. 409 cancels; all other statuses/timeouts pause the queue until retry/deadline."
              },
              "priority": {
                "type": "integer",
                "minimum": 0,
                "maximum": 2,
                "default": 0,
                "description": "0 normal, 1 high, 2 urgent; default 0. Uses the same priority aging and recipient/route ordering as MessageInput. An unassigned automatic request preserves ordering with explicit requests for that recipient. Does not bypass limits, expiry, STOP or unknown-outcome safety. Signed-command replay still requires the exact original bytes, including whether priority was present."
              },
              "purpose": {
                "$ref": "#/components/schemas/MessagePurpose",
                "description": "Same purpose rules as direct/batch API. Signed replay must preserve the exact original bytes, including whether purpose was supplied."
              },
              "poolId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "description": "Project phone pool. Mutually exclusive with deviceId and simNumber; route is chosen before hand-off."
              },
              "replaceKey": {
                "type": "string",
                "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
                "description": "Account-scoped business notification key. Requires replaceVersion. Only the previous queued, undispatched SMS can be superseded."
              },
              "replaceVersion": {
                "type": "integer",
                "minimum": 1,
                "maximum": 2147483647,
                "description": "Strictly increasing business revision. Old/equal versions reject with 409; exact idempotency replays return their original (possibly superseded) message."
              },
              "sendAt": {
                "type": "string",
                "format": "date-time",
                "description": "Send no earlier than this absolute ISO 8601 instant with timezone. At most 30 days after server admission. Past times are immediately due. Durable server-side scheduling; future jobs do not block due conversations or reserve SIM capacity. TTL starts at max(admission time, sendAt). All limits, STOP, consent, carrier permission and quiet-hour checks run again at dispatch. This is not a delivery-time guarantee."
              },
              "maxSegments": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100,
                "description": "Optional safety cap on estimated SMS parts per message. A larger payload is rejected before admission (message_segment_limit); a batch is atomic. No silent truncation, transliteration or rewriting. Omitted preserves legacy behavior; the web composer pins the reviewed estimate by default. Not a carrier bill or delivery guarantee. Changing the cap on an idempotent retry conflicts."
              }
            },
            "required": [
              "externalId",
              "phone",
              "text"
            ],
            "oneOf": [
              {
                "required": [
                  "deviceId"
                ],
                "not": {
                  "required": [
                    "poolId"
                  ]
                }
              },
              {
                "required": [
                  "poolId"
                ],
                "not": {
                  "anyOf": [
                    {
                      "required": [
                        "deviceId"
                      ]
                    },
                    {
                      "required": [
                        "simNumber"
                      ]
                    }
                  ]
                }
              }
            ]
          }
        },
        "required": [
          "id",
          "version",
          "type",
          "createdAt",
          "data"
        ],
        "description": "Подписанная команда. Не передавайте tenantId: клиент определяется ID интеграции и подписью. Повторы должны использовать точные прежние байты тела, включая createdAt."
      },
      "CommandAccepted": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "accepted": {
            "const": true
          },
          "messageId": {
            "type": "string",
            "description": "ID SMS в шлюзе; не подтверждает отправку или доставку."
          }
        },
        "required": [
          "id",
          "accepted",
          "messageId"
        ]
      },
      "IncomingSms": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Постоянный ID входящего SMS на этом телефоне; повтор с другим содержимым даёт 409."
          },
          "phone": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Номер, короткий код или буквенный отправитель."
          },
          "text": {
            "type": "string",
            "maxLength": 20000,
            "description": "Точный текст с пробелами; допускается пустая строка. Не более 20000 UTF-16 code units и 80000 UTF-8 байт."
          },
          "receivedAt": {
            "type": "string",
            "format": "date-time"
          },
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "recipientPhone": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^\\+[1-9]\\d{6,14}$",
            "description": "Actual receiving SIM number captured durably on device, when Android supplies valid E.164. Optional; not part of legacy deduplication fingerprint."
          }
        },
        "required": [
          "id",
          "phone",
          "text",
          "receivedAt"
        ],
        "description": "Authenticated incoming SMS. With the US profile enabled, exact HELP/INFO, STOP/STOPALL/UNSUBSCRIBE/CANCEL/END/QUIT/REVOKE/OPTOUT/OPT OUT, START/UNSTOP may create a fixed private reply. Requires a complete business profile, actual incoming SIM number and fresh accepted SIM generation. Replies are pinned, deduplicated, expire in ten minutes, and are limited to one per minute per tenant/recipient and ten per hour per device. Configured sending limits and technical SIM identity checks still apply; archived document reviews and their caps do not. STOP suppression is independent of reply availability. No public input grants a control exemption."
      },
      "AndroidRelease": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri-reference"
          },
          "version": {
            "type": "string"
          },
          "versionName": {
            "type": "string"
          },
          "versionCode": {
            "type": "integer",
            "minimum": 1
          },
          "packageName": {
            "type": "string"
          },
          "minSdk": {
            "type": "integer",
            "minimum": 21
          },
          "targetSdk": {
            "type": "integer",
            "minimum": 21
          },
          "release": {
            "type": "boolean"
          },
          "channel": {
            "enum": [
              "pilot",
              "stable"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "signerSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "publishedAt": {
            "type": "string",
            "format": "date-time"
          },
          "releaseNotes": {
            "type": "string",
            "maxLength": 4000
          },
          "rollout": {
            "type": "string",
            "enum": [
              "pilot",
              "all",
              "paused"
            ],
            "description": "Optional initial distribution policy, independent of the signing channel. Publisher defaults new artifacts to pilot. The saved per-sha256 admin policy overrides this value. Legacy omission falls back to channel pilot=>pilot, stable=>all."
          }
        },
        "required": [
          "url",
          "version",
          "minSdk",
          "release",
          "sha256"
        ]
      },
      "AndroidUpdate": {
        "allOf": [
          {
            "$ref": "#/components/schemas/AndroidRelease"
          },
          {
            "required": [
              "packageName",
              "versionName",
              "versionCode",
              "targetSdk",
              "signerSha256",
              "channel",
              "publishedAt",
              "releaseNotes"
            ]
          }
        ]
      },
      "MagendaEvent": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "const": 1
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "const": "message.status"
              },
              "data": {
                "type": "object",
                "properties": {
                  "externalId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "messageId": {
                    "type": "string"
                  },
                  "deviceId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Null while a pool has no selected phone. An assigned queue route remains tentative until hand-off."
                  },
                  "phone": {
                    "type": "string"
                  },
                  "state": {
                    "type": "string",
                    "description": "Legacy state: Queued maps to Pending, submitting to unknown, expired/cancelled to rejected. New consumers use status.phase and status.sequence."
                  },
                  "error": {
                    "type": "string"
                  },
                  "resolution": {
                    "type": "object",
                    "properties": {
                      "decision": {
                        "const": "acknowledged_unknown"
                      },
                      "resolvedAt": {
                        "type": "string",
                        "format": "date-time"
                      }
                    },
                    "required": [
                      "decision",
                      "resolvedAt"
                    ],
                    "additionalProperties": false,
                    "description": "Operator acknowledgement of an unknown outcome. No retransmission and no assertion of delivery; the private review note is not sent."
                  },
                  "platformUser": {
                    "$ref": "#/components/schemas/MessagePlatformUser"
                  },
                  "deviceName": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "sender": {
                    "$ref": "#/components/schemas/MessageSender"
                  },
                  "routing": {
                    "$ref": "#/components/schemas/MessageRouting"
                  },
                  "status": {
                    "$ref": "#/components/schemas/MessageStatus"
                  },
                  "submittedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "sentAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "deliveredAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "simNumber": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1,
                    "maximum": 8
                  },
                  "queueReason": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Current server-queue hold reason. SIM document review is retired. Technical holds include diagnostics_stale, sim_missing, sim_identity_unavailable, sim_identity_changed and app_upgrade_required. With the sender/recipient profile enabled, independent holds include us_business_profile_required, us_consent_required, us_consent_expired, us_consent_revoked, us_recipient_quiet_hours and us_control_stale. An offline phone or missing consent/profile has no promised resume time. Recipient quiet hours supply the next eligible UTC instant; every other gate and expiry must still permit dispatch."
                  },
                  "nextAttemptAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "expiresAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "purpose": {
                    "$ref": "#/components/schemas/MessagePurpose"
                  },
                  "projectId": {
                    "type": "string",
                    "description": "Present for opted-in router projects only."
                  },
                  "poolId": {
                    "type": "string",
                    "description": "Present for messages admitted through a pool."
                  },
                  "retryOf": {
                    "type": "string",
                    "description": "Original message ID for an administrator-confirmed retry in the same account. The retry is a separate message; follow retryOf to recover the original externalId. Present from its first queued status event."
                  }
                },
                "required": [
                  "externalId",
                  "messageId",
                  "deviceId",
                  "state"
                ]
              },
              "projectId": {
                "type": "string",
                "description": "Present for opted-in router projects only. Legacy integrations retain their existing envelope."
              }
            },
            "required": [
              "id",
              "version",
              "createdAt",
              "type",
              "data"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "const": 1
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "const": "message.received"
              },
              "data": {
                "type": "object",
                "properties": {
                  "messageId": {
                    "type": "string"
                  },
                  "deviceId": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "text": {
                    "type": "string"
                  },
                  "receivedAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "simNumber": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8
                  },
                  "consent": {
                    "type": "object",
                    "properties": {
                      "status": {
                        "enum": [
                          "stopped",
                          "started"
                        ]
                      },
                      "effectiveAt": {
                        "type": "string",
                        "format": "date-time"
                      }
                    },
                    "required": [
                      "status",
                      "effectiveAt"
                    ],
                    "additionalProperties": false,
                    "description": "Current authoritative opt-out state after timestamp ordering. A delayed raw STOP may carry started; consumers must use this state and effectiveAt."
                  },
                  "platformUser": {
                    "$ref": "#/components/schemas/MessagePlatformUser"
                  },
                  "deviceName": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "recipientPhone": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^\\+[1-9]\\d{6,14}$"
                  },
                  "projectId": {
                    "type": "string",
                    "description": "Present for opted-in router projects only."
                  }
                },
                "required": [
                  "messageId",
                  "deviceId",
                  "phone",
                  "text",
                  "receivedAt"
                ]
              },
              "projectId": {
                "type": "string",
                "description": "Present for opted-in router projects only. Legacy integrations retain their existing envelope."
              }
            },
            "required": [
              "id",
              "version",
              "createdAt",
              "type",
              "data"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "const": 1
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "const": "device.status"
              },
              "data": {
                "type": "object",
                "properties": {
                  "deviceId": {
                    "type": "string"
                  },
                  "state": {
                    "enum": [
                      "linked",
                      "online",
                      "offline",
                      "revoked"
                    ]
                  },
                  "lastSeen": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "pairingId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Present for linked events created by this server. Also present for revoked when the original pairing is known. Correlate within the same integration. Persist revocation as terminal for that pairing so a delayed linked event cannot re-enable the phone. Not included for online/offline; email is never included."
                  },
                  "projectId": {
                    "type": "string",
                    "description": "Present for opted-in router projects only."
                  }
                },
                "required": [
                  "deviceId",
                  "state",
                  "lastSeen"
                ]
              },
              "projectId": {
                "type": "string",
                "description": "Present for opted-in router projects only. Legacy integrations retain their existing envelope."
              }
            },
            "required": [
              "id",
              "version",
              "createdAt",
              "type",
              "data"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "const": 1
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "const": "integration.test"
              },
              "data": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string"
                  },
                  "projectId": {
                    "type": "string",
                    "description": "Present for opted-in router projects only."
                  }
                },
                "required": [
                  "message"
                ]
              },
              "projectId": {
                "type": "string",
                "description": "Present for opted-in router projects only. Legacy integrations retain their existing envelope."
              }
            },
            "required": [
              "id",
              "version",
              "createdAt",
              "type",
              "data"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "const": 1
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "const": "message.validate"
              },
              "data": {
                "type": "object",
                "properties": {
                  "externalId": {
                    "type": "string"
                  },
                  "messageId": {
                    "type": "string"
                  },
                  "deviceId": {
                    "type": "string"
                  },
                  "expiresAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "projectId": {
                    "type": "string",
                    "description": "Present for opted-in router projects only."
                  },
                  "poolId": {
                    "type": "string",
                    "description": "Present for pool-routed preflight requests."
                  }
                },
                "required": [
                  "externalId",
                  "messageId",
                  "deviceId",
                  "expiresAt"
                ],
                "additionalProperties": false
              },
              "projectId": {
                "type": "string",
                "description": "Present for opted-in router projects only. Legacy integrations retain their existing envelope."
              }
            },
            "required": [
              "id",
              "version",
              "createdAt",
              "type",
              "data"
            ],
            "description": "Synchronous signed preflight on the configured callback endpoint. Respond 204 only if still valid, 409 if obsolete. All other responses hold the queue. Runs before upstream submission and from APK 1.6 before modem handoff; it is not a durable status event."
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "const": 1
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "const": "support.incident"
              },
              "data": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "tenantId": {
                    "type": "string"
                  },
                  "deviceId": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string",
                    "description": "Includes sim_attention: an automatic-pool SIM needs attention even if another SIM continues sending."
                  },
                  "title": {
                    "type": "string"
                  },
                  "instruction": {
                    "type": "string"
                  },
                  "severity": {
                    "enum": [
                      "warning",
                      "error"
                    ]
                  },
                  "openedAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "lastSeenAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "resolvedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "acknowledgedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "acknowledgedBy": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "state": {
                    "enum": [
                      "open",
                      "recovered",
                      "device_revoked"
                    ]
                  },
                  "messageId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "projectId": {
                    "type": "string",
                    "description": "Present for opted-in router projects only."
                  }
                },
                "required": [
                  "id",
                  "tenantId",
                  "deviceId",
                  "code",
                  "title",
                  "instruction",
                  "severity",
                  "openedAt",
                  "lastSeenAt",
                  "resolvedAt",
                  "acknowledgedAt",
                  "acknowledgedBy",
                  "state"
                ],
                "additionalProperties": false
              },
              "projectId": {
                "type": "string",
                "description": "Present for opted-in router projects only. Legacy integrations retain their existing envelope."
              }
            },
            "required": [
              "id",
              "version",
              "createdAt",
              "type",
              "data"
            ],
            "description": "Durable signed incident lifecycle notification. No SMS body, recipient or credentials. Acknowledge in SendHarbor does not itself resolve the condition."
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "const": 1
              },
              "type": {
                "const": "project.incident"
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "projectId": {
                "type": "string"
              },
              "data": {
                "type": "object",
                "properties": {
                  "projectId": {
                    "type": "string"
                  },
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "code": {
                    "enum": [
                      "queue_stalled",
                      "phones_offline",
                      "webhook_failed",
                      "webhook_delayed"
                    ]
                  },
                  "state": {
                    "enum": [
                      "open",
                      "recovered"
                    ]
                  },
                  "openedAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "resolvedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  }
                },
                "required": [
                  "id",
                  "projectId",
                  "code",
                  "state",
                  "openedAt",
                  "resolvedAt"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "id",
              "version",
              "type",
              "createdAt",
              "projectId",
              "data"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "const": 1
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "const": "appointment.reply"
              },
              "data": {
                "type": "object",
                "properties": {
                  "appointmentId": {
                    "type": "string"
                  },
                  "externalId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "answer": {
                    "enum": [
                      "confirm",
                      "reschedule"
                    ]
                  },
                  "status": {
                    "enum": [
                      "confirmed",
                      "reschedule_requested"
                    ]
                  },
                  "phone": {
                    "type": "string"
                  },
                  "startsAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "timeZone": {
                    "type": "string"
                  },
                  "deviceId": {
                    "type": "string"
                  },
                  "messageId": {
                    "type": "string",
                    "description": "The incoming SMS, as messageId of its message.received event."
                  },
                  "receivedAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "appointmentId",
                  "externalId",
                  "answer",
                  "status",
                  "phone",
                  "startsAt",
                  "timeZone",
                  "deviceId",
                  "messageId",
                  "receivedAt"
                ]
              }
            },
            "required": [
              "id",
              "version",
              "createdAt",
              "type",
              "data"
            ],
            "description": "A reply 1 or 2 from the client's number within 48 hours after an appointment SMS was handed to the phone, applied to that number's nearest upcoming appointment. Opt-out words are never an answer. The same SMS also arrives as message.received."
          }
        ],
        "description": "Durable events reuse the same ID/body with a fresh HMAC timestamp on retry; order is not guaranteed. message.validate is a synchronous signed decision request, not an outbox event."
      },
      "ReadinessCheck": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "warning",
              "error",
              "unknown",
              "not_applicable"
            ]
          },
          "label": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "action": {
            "type": [
              "string",
              "null"
            ]
          },
          "advisory": {
            "type": "boolean",
            "description": "True for a fresh Play-managed update schedule which the app cannot inspect. Unknown advisory checks do not prevent SMS readiness; actual warning/error and stale checks still do."
          }
        },
        "required": [
          "id",
          "status",
          "label",
          "detail",
          "action"
        ]
      },
      "Readiness": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ready",
              "attention",
              "unknown"
            ]
          },
          "checkedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "stale": {
            "type": "boolean"
          },
          "clockMismatch": {
            "type": "boolean"
          },
          "freshnessMs": {
            "type": "integer",
            "const": 300000
          },
          "appVersion": {
            "type": [
              "string",
              "null"
            ]
          },
          "checks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReadinessCheck"
            }
          },
          "rcsSetup": {
            "$ref": "#/components/schemas/RcsSetup"
          },
          "outgoingHold": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/OutgoingHold"
              },
              {
                "type": "null"
              }
            ],
            "description": "Null when not reported, stale, expired, revoked or clock-mismatched. A fresh report without outgoingHold clears previous evidence."
          }
        },
        "required": [
          "status",
          "checkedAt",
          "stale",
          "clockMismatch",
          "freshnessMs",
          "appVersion",
          "checks",
          "rcsSetup",
          "outgoingHold"
        ]
      },
      "DiagnosticsApp": {
        "type": "object",
        "properties": {
          "versionName": {
            "type": "string",
            "pattern": "^[0-9][A-Za-z0-9.+_-]{0,63}$"
          },
          "versionCode": {
            "type": "integer",
            "minimum": 1
          },
          "sdk": {
            "type": "integer",
            "minimum": 21,
            "maximum": 1000
          },
          "distribution": {
            "type": "string",
            "enum": [
              "direct",
              "play"
            ]
          }
        },
        "required": [
          "versionName",
          "versionCode",
          "sdk",
          "distribution"
        ],
        "additionalProperties": false
      },
      "DiagnosticsBattery": {
        "type": "object",
        "properties": {
          "percent": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 100
          },
          "charging": {
            "type": [
              "boolean",
              "null"
            ]
          }
        },
        "required": [],
        "additionalProperties": false
      },
      "DiagnosticsQueues": {
        "type": "object",
        "properties": {
          "incomingPending": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1000000
          },
          "incomingFailed": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1000000
          }
        },
        "required": [],
        "additionalProperties": false
      },
      "MobileDiagnosticEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "code": {
            "type": "string",
            "enum": [
              "diagnostics_started",
              "settings_changed",
              "gateway_started",
              "gateway_stopped",
              "connection_lost",
              "connection_restored",
              "report_failed",
              "report_restored",
              "incoming_pending",
              "incoming_failed",
              "incoming_recovered",
              "update_check_started",
              "update_available",
              "update_downloaded",
              "update_install_started",
              "update_user_action",
              "update_installed",
              "update_failed",
              "pairing_completed",
              "permission_changed"
            ]
          }
        },
        "required": [
          "id",
          "occurredAt",
          "code"
        ],
        "additionalProperties": false
      },
      "DiagnosticReport": {
        "type": "object",
        "properties": {
          "version": {
            "const": 1
          },
          "collectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "app": {
            "$ref": "#/components/schemas/DiagnosticsApp"
          },
          "checks": {
            "type": "object",
            "properties": {
              "paired": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "sms_send": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "sms_receive": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "phone_permission": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "notifications": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "sim": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "cellular": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "internet": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "gateway_service": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "cloud_connection": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "autostart": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "battery_optimization": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "charging": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "app_updates": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "install_permission": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "incoming_queue": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              },
              "rcs_setup": {
                "type": "string",
                "enum": [
                  "ok",
                  "warning",
                  "error",
                  "unknown",
                  "not_applicable"
                ]
              }
            },
            "required": [],
            "additionalProperties": false
          },
          "battery": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DiagnosticsBattery"
              },
              {
                "type": "null"
              }
            ]
          },
          "queues": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DiagnosticsQueues"
              },
              {
                "type": "null"
              }
            ]
          },
          "events": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/MobileDiagnosticEvent"
            }
          },
          "simCards": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "object",
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "phoneNumber": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^\\+[1-9]\\d{6,14}$"
                },
                "carrierName": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 100
                },
                "identityState": {
                  "enum": [
                    "accepted",
                    "changed",
                    "unknown"
                  ]
                },
                "cellular": {
                  "enum": [
                    "ok",
                    "error",
                    "unknown"
                  ]
                },
                "verificationTag": {
                  "type": "string",
                  "format": "uuid",
                  "description": "Random privacy-preserving local SIM configuration tag. Rotates after SIM/configuration change. Not ICCID, IMSI or a hardware identifier. Required for new SIM-specific verification, optional for legacy diagnostic clients."
                },
                "rcsDisabledConfirmedAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time",
                  "description": "Manual user assertion for this accepted verificationTag and current server/device enrollment; never automatic RCS detection. Omit only for older APKs, null when unconfirmed. Timestamp cannot be later than collectedAt. Reconfirming or clearing invalidates previous incoming-test evidence."
                },
                "carrierId": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 1,
                  "maximum": 2147483647,
                  "description": "Android carrier ID of the SIM (TelephonyManager.getSimCarrierId / SubscriptionInfo.getCarrierId), used to match the SIM catalog. Send only after the server answered simNetwork: true."
                },
                "mcc": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^\\d{3}$",
                  "description": "Home mobile country code of the SIM. Sent together with mnc; never ICCID or IMSI."
                },
                "mnc": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^\\d{2,3}$",
                  "description": "Home mobile network code of the SIM with its original length (01 and 001 differ). Sent together with mcc."
                }
              },
              "required": [
                "simNumber",
                "identityState",
                "cellular"
              ],
              "additionalProperties": false
            },
            "description": "Active SIMs only, unique slots. No ICCID or subscription ID. Automatic routing requires fresh reports (5 minutes) and accepted identity."
          },
          "outgoingHold": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/OutgoingHold"
              },
              {
                "type": "null"
              }
            ],
            "description": "Null when not reported, stale, expired, revoked or clock-mismatched. A fresh report without outgoingHold clears previous evidence."
          }
        },
        "required": [
          "version",
          "collectedAt",
          "app",
          "checks"
        ],
        "additionalProperties": false
      },
      "OperationalEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "level": {
            "type": "string",
            "enum": [
              "info",
              "warning",
              "error"
            ]
          },
          "category": {
            "type": "string",
            "enum": [
              "device",
              "connection",
              "permissions",
              "updates",
              "messages",
              "integration",
              "system"
            ]
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "detail": {
            "type": [
              "string",
              "null"
            ]
          },
          "correlationId": {
            "type": [
              "string",
              "null"
            ]
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "occurredAt",
          "level",
          "category",
          "code",
          "message",
          "detail",
          "correlationId",
          "deviceId"
        ]
      },
      "DeviceDiagnostics": {
        "type": "object",
        "properties": {
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "device": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "lastSeen": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "revoked": {
                "type": "boolean"
              }
            },
            "required": [
              "id",
              "lastSeen",
              "revoked"
            ]
          },
          "readiness": {
            "$ref": "#/components/schemas/Readiness"
          },
          "app": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DiagnosticsApp"
              },
              {
                "type": "null"
              }
            ]
          },
          "battery": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DiagnosticsBattery"
              },
              {
                "type": "null"
              }
            ]
          },
          "queues": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DiagnosticsQueues"
              },
              {
                "type": "null"
              }
            ]
          },
          "advice": {
            "$ref": "#/components/schemas/SmartAdvice"
          },
          "rcsSetup": {
            "$ref": "#/components/schemas/RcsSetup"
          },
          "usMessaging": {
            "$ref": "#/components/schemas/UsMessagingCompactOverview"
          },
          "usLaunch": {
            "$ref": "#/components/schemas/UsLaunchCompactOverview"
          },
          "outgoingHold": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/OutgoingHold"
              },
              {
                "type": "null"
              }
            ],
            "description": "Null when not reported, stale, expired, revoked or clock-mismatched. A fresh report without outgoingHold clears previous evidence."
          }
        },
        "required": [
          "generatedAt",
          "device",
          "readiness",
          "app",
          "battery",
          "queues",
          "advice",
          "rcsSetup",
          "outgoingHold"
        ]
      },
      "IntegrationHealth": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "unknown",
              "ok",
              "warning",
              "paused"
            ]
          },
          "lastDeliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Последняя успешная доставка текущей конфигурации; null, пока её нет. История прежних конфигураций остаётся в журнале доставок."
          },
          "lastCommandAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "pendingCommands": {
            "type": "integer"
          },
          "failedCommands": {
            "type": "integer"
          },
          "pendingDeliveries": {
            "type": "integer"
          },
          "failedDeliveries": {
            "type": "integer"
          },
          "oldestPendingAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "workerEnabled": {
            "type": "boolean",
            "description": "Whether background processing is enabled in server configuration. When present, workerAvailable separately reports a recent connected worker heartbeat."
          },
          "freshnessMs": {
            "type": "integer",
            "const": 86400000
          },
          "capacity": {
            "$ref": "#/components/schemas/IntegrationCapacity",
            "description": "Присутствует только после создания интеграции."
          },
          "workerAvailable": {
            "type": "boolean",
            "description": "Optional on the distributed runtime. True only while a worker has a fresh connected RabbitMQ heartbeat; absence retains the legacy runtime contract."
          },
          "workers": {
            "type": "object",
            "properties": {
              "lastSeenAt": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              },
              "validUntil": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              }
            },
            "required": [
              "lastSeenAt",
              "validUntil"
            ],
            "description": "Worker heartbeat freshness; not proof of SMS submission or delivery."
          }
        },
        "required": [
          "status",
          "lastDeliveredAt",
          "lastCommandAt",
          "pendingCommands",
          "failedCommands",
          "pendingDeliveries",
          "failedDeliveries",
          "oldestPendingAt",
          "workerEnabled",
          "freshnessMs"
        ],
        "description": "Состояние worker и очередей. Доставка подтверждена только успешным HTTP callback за последние 24 часа для текущих endpoint и секрета. Смена адреса/ротация, включая завершение старого in-flight callback, требует новой успешной доставки. Заполненная очередь отражается как warning, если интеграция и worker включены."
      },
      "IntegrationCapacity": {
        "type": "object",
        "description": "Backlog одной интеграции. История завершённых команд и доставленных событий не входит в лимиты. Результат уже допущенной SMS и отзыв устройства могут временно превысить предел; новые отправки тогда блокируются.",
        "required": [
          "commands",
          "deliveries",
          "blocked"
        ],
        "properties": {
          "commands": {
            "type": "object",
            "required": [
              "used",
              "limit"
            ],
            "properties": {
              "used": {
                "type": "integer",
                "minimum": 0
              },
              "limit": {
                "type": "integer",
                "default": 1000
              }
            }
          },
          "deliveries": {
            "type": "object",
            "required": [
              "used",
              "limit",
              "bytes",
              "maxBytes"
            ],
            "properties": {
              "used": {
                "type": "integer",
                "minimum": 0,
                "description": "pending + delivering + failed"
              },
              "limit": {
                "type": "integer",
                "default": 2000
              },
              "bytes": {
                "type": "integer",
                "minimum": 0,
                "description": "Суммарные UTF-8 байты исходных JSON недоставленных событий"
              },
              "maxBytes": {
                "type": "integer",
                "default": 16777216
              }
            }
          },
          "blocked": {
            "type": "boolean",
            "description": "Достигнут предел активных команд, количества событий либо осталось менее 1024 байт для допуска новой отправки. Большое входящее событие может не поместиться даже при blocked=false."
          }
        }
      },
      "EnrollmentPayload": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "type": {
                "const": "smsgate-enrollment"
              },
              "version": {
                "const": 1
              },
              "serverUrl": {
                "type": "string",
                "format": "uri"
              },
              "code": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_-]{43}$"
              },
              "expiresAt": {
                "type": "string",
                "format": "date-time"
              }
            },
            "required": [
              "type",
              "version",
              "serverUrl",
              "code",
              "expiresAt"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "const": "smsgate-enrollment"
              },
              "version": {
                "const": 2
              },
              "serverUrl": {
                "type": "string",
                "format": "uri"
              },
              "code": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_-]{43}$"
              },
              "expiresAt": {
                "type": "null"
              }
            },
            "required": [
              "type",
              "version",
              "serverUrl",
              "code",
              "expiresAt"
            ],
            "additionalProperties": false
          }
        ],
        "description": "Точные данные QR. Email пользователя платформы и API-ключ сюда не входят; email хранится только на сервере."
      },
      "SmartAdvice": {
        "type": "object",
        "properties": {
          "version": {
            "const": 1
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "freshness": {
            "enum": [
              "fresh",
              "stale",
              "missing",
              "revoked"
            ]
          },
          "summary": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "detail": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "title",
              "detail"
            ]
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "severity": {
                  "enum": [
                    "error",
                    "warning",
                    "info"
                  ]
                },
                "title": {
                  "type": "string"
                },
                "detail": {
                  "type": "string"
                },
                "actions": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "label": {
                        "type": "string"
                      },
                      "target": {
                        "enum": [
                          "phone",
                          "portal",
                          "carrier",
                          "support"
                        ]
                      },
                      "checkId": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "label",
                      "target"
                    ]
                  }
                },
                "evidence": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "code",
                "severity",
                "title",
                "detail",
                "actions",
                "evidence"
              ]
            }
          },
          "sms": {
            "type": "object",
            "properties": {
              "windowHours": {
                "const": 24
              },
              "total": {
                "type": "integer"
              },
              "queued": {
                "type": "integer"
              },
              "pending": {
                "type": "integer"
              },
              "sent": {
                "type": "integer"
              },
              "delivered": {
                "type": "integer"
              },
              "failed": {
                "type": "integer"
              },
              "unknown": {
                "type": "integer"
              },
              "cancelled": {
                "type": "integer"
              },
              "expired": {
                "type": "integer"
              },
              "lastFailureAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "lastCheckedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            },
            "required": [
              "windowHours",
              "total",
              "queued",
              "pending",
              "sent",
              "delivered",
              "failed",
              "unknown",
              "cancelled",
              "expired",
              "lastFailureAt",
              "lastCheckedAt"
            ]
          },
          "faq": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "question": {
                  "type": "string"
                },
                "answer": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "question",
                "answer"
              ]
            }
          }
        },
        "required": [
          "version",
          "generatedAt",
          "freshness",
          "summary",
          "items",
          "sms",
          "faq"
        ],
        "description": "Детерминированные подсказки из свежих проверок и сохранённых статусов SMS за последние 24 часа. Не подтверждают баланс SIM, ограничения оператора или фактическую доставку. Не включают тексты SMS, номера или raw error."
      },
      "SendingPolicy": {
        "type": "object",
        "properties": {
          "paused": {
            "type": "boolean"
          },
          "intervalSeconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 86400
          },
          "maxSegmentsPerHour": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "description": "0 disables this app cap; carrier restrictions still apply."
          },
          "maxSegmentsPerDay": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100000,
            "description": "0 disables this app cap; carrier restrictions still apply."
          },
          "maxSegmentsPerMonth": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000000,
            "description": "0 disables this app cap; carrier restrictions still apply."
          },
          "quietHours": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "properties": {
                  "timezone": {
                    "type": "string",
                    "description": "IANA timezone, например America/New_York"
                  },
                  "start": {
                    "type": "string",
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
                  },
                  "end": {
                    "type": "string",
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
                  }
                },
                "required": [
                  "timezone",
                  "start",
                  "end"
                ],
                "additionalProperties": false
              }
            ]
          },
          "defaultSimNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "ttlSeconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 604800
          },
          "simOverrides": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "object",
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "paused": {
                  "type": "boolean"
                },
                "intervalSeconds": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 86400
                },
                "maxSegmentsPerHour": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "description": "0 disables this app cap; carrier restrictions still apply."
                },
                "maxSegmentsPerDay": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 100000,
                  "description": "0 disables this app cap; carrier restrictions still apply."
                },
                "maxSegmentsPerMonth": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 1000000,
                  "description": "0 disables this app cap; carrier restrictions still apply."
                },
                "quietHours": {
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "timezone": {
                          "type": "string",
                          "description": "IANA timezone, например America/New_York"
                        },
                        "start": {
                          "type": "string",
                          "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
                        },
                        "end": {
                          "type": "string",
                          "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
                        }
                      },
                      "required": [
                        "timezone",
                        "start",
                        "end"
                      ],
                      "additionalProperties": false
                    }
                  ]
                },
                "maxSegmentsPerSecond": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "default": 0,
                  "description": "Since 1.9.0: rolling SMS-part cap; 0 disables this short window. Omission in PUT preserves the current cap (including the same existing SIM override). A new/legacy stored rule defaults to 0. All enabled windows and interval apply together."
                },
                "maxSegmentsPerMinute": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "default": 0,
                  "description": "Since 1.9.0: rolling SMS-part cap; 0 disables this short window. Omission in PUT preserves the current cap (including the same existing SIM override). A new/legacy stored rule defaults to 0. All enabled windows and interval apply together."
                }
              },
              "required": [
                "simNumber",
                "paused",
                "intervalSeconds",
                "maxSegmentsPerHour",
                "maxSegmentsPerDay",
                "maxSegmentsPerMonth",
                "quietHours"
              ],
              "additionalProperties": false
            }
          },
          "routingMode": {
            "enum": [
              "fixed",
              "round_robin",
              "failover"
            ],
            "default": "fixed"
          },
          "enabledSimNumbers": {
            "type": "array",
            "minItems": 1,
            "maxItems": 8,
            "uniqueItems": true,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          },
          "stickyRecipient": {
            "type": "boolean",
            "default": true
          },
          "maxSegmentsPerSecond": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "default": 0,
            "description": "Since 1.9.0: rolling SMS-part cap; 0 disables this short window. Omission in PUT preserves the current cap (including the same existing SIM override). A new/legacy stored rule defaults to 0. All enabled windows and interval apply together."
          },
          "maxSegmentsPerMinute": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "default": 0,
            "description": "Since 1.9.0: rolling SMS-part cap; 0 disables this short window. Omission in PUT preserves the current cap (including the same existing SIM override). A new/legacy stored rule defaults to 0. All enabled windows and interval apply together."
          },
          "simBudgets": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/SimBillingBudget"
            },
            "description": "Unique SIM slots. Omission preserves existing budgets; [] explicitly removes them. Separate from the rolling 30-day cap. Defaults to no package budget."
          }
        },
        "required": [
          "paused",
          "intervalSeconds",
          "maxSegmentsPerHour",
          "maxSegmentsPerDay",
          "maxSegmentsPerMonth",
          "quietHours",
          "defaultSimNumber",
          "ttlSeconds",
          "simOverrides"
        ],
        "additionalProperties": false,
        "description": "Полная замена политики. Интервал на часть SMS; окна 1ч/24ч/30суток скользящие. Все окна независимы и действуют одновременно; дневной/месячный потолок может быть ниже часового. SIM override полный, номера уникальны. Общая paused останавливает все SIM. Изменение не сбрасывает расход. Лимиты количества частей SMS по умолчанию выключены; интервал на часть настраивается отдельно. Сохранённые пользовательские правила не меняются. Это настройки SendHarbor, не разрешение оператора. Fixed defaults to preferred SIM and preserves explicit API slot overrides. Automatic pool must contain preferred SIM. Per-SIM limits always apply; no automatic retry after hand-off. Sticky recipients wait for their original SIM; idle associations follow history retention (default 30 days). Since 1.9.0 optional second/minute caps default to 0 on new/legacy rules and omitted PUT fields preserve existing values. Explicit 0 disables any of the five rolling caps. intervalSeconds=0 disables the additional pause; it does not bypass quotas or in-flight dispatch fencing. A multipart SMS must fit every enabled whole window. Since 1.10.0, optional simBudgets apply independent calendar billing cycles. Active/unknown conversations and pending webhook commands preserve sender affinity beyond history retention. Recognized temporary network failures pause new queued work for 30 seconds, 120 seconds, then 600 seconds; the fourth consecutive failure requires manual review. The failed message itself is never retried. Definitive message-format/recipient errors do not block unrelated recipients. Generic radio failure does not prove insufficient balance and remains manual."
      },
      "SendingPolicyInput": {
        "type": "object",
        "properties": {
          "paused": {
            "type": "boolean"
          },
          "intervalSeconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 86400
          },
          "maxSegmentsPerHour": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "description": "0 disables this app cap; carrier restrictions still apply."
          },
          "maxSegmentsPerDay": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100000,
            "description": "0 disables this app cap; carrier restrictions still apply."
          },
          "maxSegmentsPerMonth": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000000,
            "description": "0 disables this app cap; carrier restrictions still apply."
          },
          "quietHours": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "properties": {
                  "timezone": {
                    "type": "string",
                    "description": "IANA timezone, например America/New_York"
                  },
                  "start": {
                    "type": "string",
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
                  },
                  "end": {
                    "type": "string",
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
                  }
                },
                "required": [
                  "timezone",
                  "start",
                  "end"
                ],
                "additionalProperties": false
              }
            ]
          },
          "defaultSimNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "ttlSeconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 604800
          },
          "simOverrides": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "object",
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "paused": {
                  "type": "boolean"
                },
                "intervalSeconds": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 86400
                },
                "maxSegmentsPerHour": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "description": "0 disables this app cap; carrier restrictions still apply."
                },
                "maxSegmentsPerDay": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 100000,
                  "description": "0 disables this app cap; carrier restrictions still apply."
                },
                "maxSegmentsPerMonth": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 1000000,
                  "description": "0 disables this app cap; carrier restrictions still apply."
                },
                "quietHours": {
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "timezone": {
                          "type": "string",
                          "description": "IANA timezone, например America/New_York"
                        },
                        "start": {
                          "type": "string",
                          "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
                        },
                        "end": {
                          "type": "string",
                          "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
                        }
                      },
                      "required": [
                        "timezone",
                        "start",
                        "end"
                      ],
                      "additionalProperties": false
                    }
                  ]
                },
                "maxSegmentsPerSecond": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "default": 0,
                  "description": "Since 1.9.0: rolling SMS-part cap; 0 disables this short window. Omission in PUT preserves the current cap (including the same existing SIM override). A new/legacy stored rule defaults to 0. All enabled windows and interval apply together."
                },
                "maxSegmentsPerMinute": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "default": 0,
                  "description": "Since 1.9.0: rolling SMS-part cap; 0 disables this short window. Omission in PUT preserves the current cap (including the same existing SIM override). A new/legacy stored rule defaults to 0. All enabled windows and interval apply together."
                }
              },
              "required": [
                "simNumber",
                "paused",
                "intervalSeconds",
                "maxSegmentsPerHour",
                "maxSegmentsPerDay",
                "maxSegmentsPerMonth",
                "quietHours"
              ],
              "additionalProperties": false
            }
          },
          "resetCircuit": {
            "type": "boolean",
            "default": false,
            "description": "Explicitly clear the protective stop after checking. Does not repeat unknown SMS and does not reset usage."
          },
          "routingMode": {
            "enum": [
              "fixed",
              "round_robin",
              "failover"
            ],
            "default": "fixed"
          },
          "enabledSimNumbers": {
            "type": "array",
            "minItems": 1,
            "maxItems": 8,
            "uniqueItems": true,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          },
          "stickyRecipient": {
            "type": "boolean",
            "default": true
          },
          "maxSegmentsPerSecond": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "default": 0,
            "description": "Since 1.9.0: rolling SMS-part cap; 0 disables this short window. Omission in PUT preserves the current cap (including the same existing SIM override). A new/legacy stored rule defaults to 0. All enabled windows and interval apply together."
          },
          "maxSegmentsPerMinute": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "default": 0,
            "description": "Since 1.9.0: rolling SMS-part cap; 0 disables this short window. Omission in PUT preserves the current cap (including the same existing SIM override). A new/legacy stored rule defaults to 0. All enabled windows and interval apply together."
          },
          "simBudgets": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/SimBillingBudget"
            },
            "description": "Unique SIM slots. Omission preserves existing budgets; [] explicitly removes them. Separate from the rolling 30-day cap. Defaults to no package budget."
          }
        },
        "required": [
          "paused",
          "intervalSeconds",
          "maxSegmentsPerHour",
          "maxSegmentsPerDay",
          "maxSegmentsPerMonth",
          "quietHours",
          "defaultSimNumber",
          "ttlSeconds",
          "simOverrides"
        ],
        "additionalProperties": false,
        "description": "Полная замена политики. Интервал на часть SMS; окна 1ч/24ч/30суток скользящие. Все окна независимы и действуют одновременно; дневной/месячный потолок может быть ниже часового. SIM override полный, номера уникальны. Общая paused останавливает все SIM. Изменение не сбрасывает расход. Лимиты количества частей SMS по умолчанию выключены; интервал на часть настраивается отдельно. Сохранённые пользовательские правила не меняются. Это настройки SendHarbor, не разрешение оператора. Fixed defaults to preferred SIM and preserves explicit API slot overrides. Automatic pool must contain preferred SIM. Per-SIM limits always apply; no automatic retry after hand-off. Sticky recipients wait for their original SIM; idle associations follow history retention (default 30 days). Since 1.9.0 optional second/minute caps default to 0 on new/legacy rules and omitted PUT fields preserve existing values. Explicit 0 disables any of the five rolling caps. intervalSeconds=0 disables the additional pause; it does not bypass quotas or in-flight dispatch fencing. A multipart SMS must fit every enabled whole window. Since 1.10.0, optional simBudgets apply independent calendar billing cycles. Active/unknown conversations and pending webhook commands preserve sender affinity beyond history retention. Recognized temporary network failures pause new queued work for 30 seconds, 120 seconds, then 600 seconds; the fourth consecutive failure requires manual review. The failed message itself is never retried. Definitive message-format/recipient errors do not block unrelated recipients. Generic radio failure does not prove insufficient balance and remains manual."
      },
      "SendingPolicyResponse": {
        "type": "object",
        "properties": {
          "policy": {
            "$ref": "#/components/schemas/SendingPolicy"
          },
          "runtime": {
            "type": "object",
            "properties": {
              "queued": {
                "type": "integer",
                "minimum": 0
              },
              "capacity": {
                "const": 1000
              },
              "workerEnabled": {
                "type": "boolean",
                "description": "Whether background processing is enabled in server configuration. When present, workerAvailable separately reports a recent connected worker heartbeat."
              },
              "routes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "simNumber": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 8
                    },
                    "segmentsLastHour": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "segmentsLast24h": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "segmentsLast30d": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "nextAllowedAt": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    },
                    "circuitOpen": {
                      "type": "boolean",
                      "description": "An active safety pause. A recognized temporary failure clears the active pause after its bounded deadline, preserving attempt history internally. Unknown outcomes and exhausted recovery require explicit review."
                    },
                    "circuitReason": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "reason": {
                      "type": "string",
                      "description": " billing_limit: calendar SIM budget exhausted; temporary_network: bounded cooldown for new unsent work after a definitive temporary failure. nextAttemptAt/eligibleAt is an earliest check, not a delivery guarantee. No automatic resend of the failed/unknown message."
                    },
                    "availability": {
                      "enum": [
                        "ready",
                        "missing",
                        "changed",
                        "unavailable",
                        "unknown",
                        "stale"
                      ]
                    },
                    "selected": {
                      "type": "boolean"
                    },
                    "phoneNumber": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^\\+[1-9]\\d{6,14}$"
                    },
                    "carrierName": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "segmentsLastSecond": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "segmentsLastMinute": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "eligibilityReason": {
                      "type": "string",
                      "description": "Since 1.8.1: current SIM eligibility, including when queued=0. Honors limits, worker/pause, unresolved sends and automatic-route health/pool. Not a next-message assignment."
                    },
                    "eligibleAt": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time",
                      "description": "Since 1.8.1: earliest next eligibility check for eligibilitySegments; null if unknown or blocked. Available even when no job is pinned. Not a dispatch/delivery promise."
                    },
                    "eligibleNow": {
                      "type": "boolean",
                      "description": "Since 1.8.1: eligibility conditions met at collectedAt, not a reservation or prediction of the next SIM."
                    },
                    "eligibilitySegments": {
                      "type": "integer",
                      "minimum": 1,
                      "description": "Since 1.8.1: segments of the first pinned job, or 1 when none is pinned. Automatic jobs may need a different budget or a sticky sender."
                    },
                    "eligibilityLimit": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "enum": [
                        "second",
                        "minute",
                        "hour",
                        "day",
                        "month",
                        "billing",
                        null
                      ],
                      "description": "Since 1.9.0: window currently preventing eligibility, including message_exceeds_limit. null for other causes."
                    },
                    "blockedByLimit": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "enum": [
                        "second",
                        "minute",
                        "hour",
                        "day",
                        "month",
                        "billing",
                        null
                      ],
                      "description": "Since 1.9.0: window currently preventing eligibility, including message_exceeds_limit. null for other causes."
                    },
                    "limits": {
                      "type": "object",
                      "properties": {
                        "hour": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "0 disables this app cap; carrier restrictions still apply."
                        },
                        "day": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "0 disables this app cap; carrier restrictions still apply."
                        },
                        "month": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "0 disables this app cap; carrier restrictions still apply."
                        },
                        "second": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 10000,
                          "description": "SMS parts; 0 disables this window."
                        },
                        "minute": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 10000,
                          "description": "SMS parts; 0 disables this window."
                        }
                      },
                      "required": [
                        "hour",
                        "day",
                        "month"
                      ]
                    },
                    "lastSentAt": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time",
                      "description": "Since 1.8.1: latest actual Android Sent timestamp retained for this tenant/device/SIM in a Sent or Delivered record. Null if unavailable; never inferred from dispatch, quota reservation or polling."
                    },
                    "billingBudget": {
                      "$ref": "#/components/schemas/SimBillingUsage"
                    }
                  },
                  "required": [
                    "simNumber",
                    "segmentsLastHour",
                    "segmentsLast24h",
                    "segmentsLast30d",
                    "nextAllowedAt",
                    "circuitOpen",
                    "circuitReason",
                    "reason"
                  ]
                }
              },
              "automaticQueue": {
                "type": "object",
                "properties": {
                  "queued": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "reason": {
                    "type": "string"
                  },
                  "nextAttemptAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "blockedByLimit": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "second",
                      "minute",
                      "hour",
                      "day",
                      "month",
                      "billing",
                      null
                    ],
                    "description": "Since 1.9.0: window currently preventing eligibility, including message_exceeds_limit. null for other causes."
                  }
                },
                "required": [
                  "queued",
                  "reason",
                  "nextAttemptAt"
                ],
                "additionalProperties": false
              },
              "collectedAt": {
                "type": "string",
                "format": "date-time"
              },
              "workerAvailable": {
                "type": "boolean",
                "description": "Optional on the distributed runtime. True only while a worker has a fresh connected RabbitMQ heartbeat; absence retains the legacy runtime contract."
              },
              "workers": {
                "type": "object",
                "properties": {
                  "lastSeenAt": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true
                  },
                  "validUntil": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true
                  }
                },
                "required": [
                  "lastSeenAt",
                  "validUntil"
                ],
                "description": "Worker heartbeat freshness; not proof of SMS submission or delivery."
              }
            },
            "required": [
              "queued",
              "capacity",
              "workerEnabled",
              "routes"
            ]
          }
        },
        "required": [
          "policy",
          "runtime"
        ]
      },
      "MagendaClinicLink": {
        "type": "object",
        "properties": {
          "clinicId": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$",
            "description": "ID клиники Magenda; максимальное значение 18446744073709551615."
          },
          "clinicName": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 160
          },
          "source": {
            "enum": [
              "manual",
              "provisioning"
            ]
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "clinicId",
          "clinicName",
          "source",
          "updatedAt"
        ],
        "description": "Clinic association: manual support label or stable association created by provisioning. Neither proves successful SMS delivery."
      },
      "AdminSupportTenant": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "status": {
            "enum": [
              "provisioning",
              "creating",
              "ready",
              "failed"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "magendaLink": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/MagendaClinicLink"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "name",
          "email",
          "status",
          "createdAt",
          "magendaLink"
        ]
      },
      "AdminSupportUser": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "role": {
            "enum": [
              "admin",
              "customer"
            ]
          },
          "projectRole": {
            "enum": [
              "owner",
              "operator",
              "viewer"
            ],
            "description": "Present for Router projects; legacy users retain their original shape."
          }
        },
        "required": [
          "id",
          "name",
          "email",
          "role"
        ],
        "description": "Локальный пользователь кабинета SendHarbor. Не импортированный пользователь Magenda."
      },
      "AdminSupportGuidance": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "severity": {
            "enum": [
              "error",
              "warning",
              "info"
            ]
          },
          "title": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "instruction": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "severity",
          "title",
          "detail",
          "instruction"
        ],
        "description": "Подсказка из сохранённых статусов и свежей диагностики. Проверка баланса у оператора — действие для клиента, не измеренный факт."
      },
      "AdminSupportMagenda": {
        "type": "object",
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "id": {
            "type": [
              "string",
              "null"
            ]
          },
          "enabled": {
            "type": "boolean"
          },
          "status": {
            "enum": [
              "not_configured",
              "paused",
              "warning",
              "ok",
              "unknown"
            ]
          },
          "lastDeliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastCommandAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "oldestPendingAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "pendingCommands": {
            "type": "integer",
            "minimum": 0
          },
          "failedCommands": {
            "type": "integer",
            "minimum": 0
          },
          "pendingDeliveries": {
            "type": "integer",
            "minimum": 0
          },
          "failedDeliveries": {
            "type": "integer",
            "minimum": 0
          },
          "workerEnabled": {
            "type": "boolean",
            "description": "Whether background processing is enabled in server configuration. When present, workerAvailable separately reports a recent connected worker heartbeat."
          },
          "workerAvailable": {
            "type": "boolean",
            "description": "Optional on the distributed runtime. True only while a worker has a fresh connected RabbitMQ heartbeat; absence retains the legacy runtime contract."
          },
          "workers": {
            "type": "object",
            "properties": {
              "lastSeenAt": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              },
              "validUntil": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              }
            },
            "required": [
              "lastSeenAt",
              "validUntil"
            ],
            "description": "Worker heartbeat freshness; not proof of SMS submission or delivery."
          }
        },
        "required": [
          "configured",
          "id",
          "enabled",
          "status",
          "lastDeliveredAt",
          "lastCommandAt",
          "oldestPendingAt",
          "pendingCommands",
          "failedCommands",
          "pendingDeliveries",
          "failedDeliveries",
          "workerEnabled"
        ],
        "description": "Состояние локальной интеграции. ok требует подтверждённой доставки события за 24 часа для текущего endpoint/секрета; не доказывает SMS delivery или принадлежность clinic_id."
      },
      "AdminSupportCustomer": {
        "type": "object",
        "properties": {
          "tenant": {
            "$ref": "#/components/schemas/AdminSupportTenant"
          },
          "users": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminSupportUser"
            },
            "maxItems": 5
          },
          "userCount": {
            "type": "integer",
            "minimum": 0
          },
          "deviceCount": {
            "type": "integer",
            "minimum": 0
          },
          "activeDeviceCount": {
            "type": "integer",
            "minimum": 0
          },
          "deviceCounts": {
            "type": "object",
            "properties": {
              "online": {
                "type": "integer",
                "minimum": 0
              },
              "offline": {
                "type": "integer",
                "minimum": 0
              },
              "unknown": {
                "type": "integer",
                "minimum": 0
              },
              "revoked": {
                "type": "integer",
                "minimum": 0
              },
              "attention": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "online",
              "offline",
              "unknown",
              "revoked",
              "attention"
            ]
          },
          "magenda": {
            "$ref": "#/components/schemas/AdminSupportMagenda"
          },
          "summary": {
            "$ref": "#/components/schemas/AdminSupportGuidance"
          },
          "platformUsers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminSupportPlatformUser"
            },
            "maxItems": 5
          },
          "platformUserCount": {
            "type": "integer",
            "minimum": 0
          },
          "incidents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SupportIncident"
            },
            "maxItems": 100
          }
        },
        "required": [
          "tenant",
          "users",
          "userCount",
          "deviceCount",
          "activeDeviceCount",
          "deviceCounts",
          "magenda",
          "summary",
          "platformUsers",
          "platformUserCount"
        ],
        "description": "Включает клиента без интеграции или телефона. users содержит до 5 локальных пользователей; полный список постранично доступен в карточке клиента. deviceCounts.attention пересекается с online/offline: это свежие предупреждения проверок, не отдельное состояние связи. platformUsers содержит первые 5 групп телефонов по email из успешно использованных QR; platformUserCount — количество всех групп. Эти контакты не входят в users/userCount кабинета. Полный список platformUsers имеет отдельную пагинацию в карточке."
      },
      "AdminSupportConnection": {
        "type": "object",
        "properties": {
          "status": {
            "enum": [
              "online",
              "offline",
              "unknown",
              "revoked"
            ]
          },
          "lastContactAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "source": {
            "enum": [
              "diagnostics",
              "gateway",
              null
            ]
          },
          "detail": {
            "type": "string"
          }
        },
        "required": [
          "status",
          "lastContactAt",
          "source",
          "detail"
        ],
        "description": "Связь оценивается по последнему допустимому времени gateway lastSeen либо приёма диагностики; online в пределах freshnessMs не подтверждает отправку SMS. Старый сохранённый флаг online не используется как доказательство текущей связи."
      },
      "SendingStatusSnapshot": {
        "type": "object",
        "properties": {
          "version": {
            "const": 1
          },
          "deviceId": {
            "type": "string"
          },
          "collectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "workerEnabled": {
            "type": "boolean",
            "description": "Whether background processing is enabled in server configuration. When present, workerAvailable separately reports a recent connected worker heartbeat."
          },
          "queued": {
            "type": "integer",
            "minimum": 0
          },
          "routes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "queued": {
                  "type": "integer",
                  "minimum": 0
                },
                "reason": {
                  "type": "string",
                  "description": "waiting, second_limit, minute_limit, hour_limit, day_limit, month_limit, interval, quiet_hours, paused, circuit_open, awaiting_device, worker_paused, gateway_unavailable, callback_backlog integration_paused или validation_unavailable. message_exceeds_limit means the complete queued multipart SMS cannot fit any time under the current rule; nextAttemptAt/eligibleAt are null, eligibleNow is false. billing_limit: calendar SIM budget exhausted; temporary_network: bounded cooldown for new unsent work after a definitive temporary failure. nextAttemptAt/eligibleAt is an earliest check, not a delivery guarantee. No automatic resend of the failed/unknown message."
                },
                "nextAttemptAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "eligibilityReason": {
                  "type": "string",
                  "description": "Since 1.8.1: current SIM eligibility, including when queued=0. Honors limits, worker/pause, unresolved sends and automatic-route health/pool. Not a next-message assignment."
                },
                "eligibleAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time",
                  "description": "Since 1.8.1: earliest next eligibility check for eligibilitySegments; null if unknown or blocked. Available even when no job is pinned. Not a dispatch/delivery promise."
                },
                "eligibleNow": {
                  "type": "boolean",
                  "description": "Since 1.8.1: eligibility conditions met at collectedAt, not a reservation or prediction of the next SIM."
                },
                "eligibilitySegments": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Since 1.8.1: segments of the first pinned job, or 1 when none is pinned. Automatic jobs may need a different budget or a sticky sender."
                },
                "lastSentAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time",
                  "description": "Since 1.8.1: latest actual Android Sent timestamp retained for this tenant/device/SIM in a Sent or Delivered record. Null if unavailable; never inferred from dispatch, quota reservation or polling."
                },
                "circuitOpen": {
                  "type": "boolean",
                  "description": "An active safety pause. A recognized temporary failure clears the active pause after its bounded deadline, preserving attempt history internally. Unknown outcomes and exhausted recovery require explicit review."
                },
                "limits": {
                  "type": "object",
                  "properties": {
                    "hour": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "0 disables this app cap; carrier restrictions still apply."
                    },
                    "day": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "0 disables this app cap; carrier restrictions still apply."
                    },
                    "month": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "0 disables this app cap; carrier restrictions still apply."
                    },
                    "second": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 10000,
                      "description": "SMS parts; 0 disables this window."
                    },
                    "minute": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 10000,
                      "description": "SMS parts; 0 disables this window."
                    }
                  },
                  "required": [
                    "hour",
                    "day",
                    "month"
                  ]
                },
                "usage": {
                  "type": "object",
                  "properties": {
                    "hour": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "day": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "month": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "second": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Reserved SMS parts in this rolling window."
                    },
                    "minute": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Reserved SMS parts in this rolling window."
                    }
                  },
                  "required": [
                    "hour",
                    "day",
                    "month"
                  ]
                },
                "availability": {
                  "enum": [
                    "ready",
                    "missing",
                    "changed",
                    "unavailable",
                    "unknown",
                    "stale"
                  ]
                },
                "selected": {
                  "type": "boolean"
                },
                "phoneNumber": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^\\+[1-9]\\d{6,14}$"
                },
                "carrierName": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "eligibilityLimit": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "second",
                    "minute",
                    "hour",
                    "day",
                    "month",
                    "billing",
                    null
                  ],
                  "description": "Since 1.9.0: window currently preventing eligibility, including message_exceeds_limit. null for other causes."
                },
                "blockedByLimit": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "second",
                    "minute",
                    "hour",
                    "day",
                    "month",
                    "billing",
                    null
                  ],
                  "description": "Since 1.9.0: window currently preventing eligibility, including message_exceeds_limit. null for other causes."
                },
                "billingBudget": {
                  "$ref": "#/components/schemas/SimBillingUsage"
                },
                "usMessaging": {
                  "$ref": "#/components/schemas/UsMessagingSummary",
                  "description": "Optional, present only for a saved per-SIM record. Informational only; never used by SMS dispatch/limits. Older clients may ignore this additive field."
                },
                "usLaunch": {
                  "$ref": "#/components/schemas/UsLaunchMobileSummary"
                }
              },
              "required": [
                "simNumber",
                "queued",
                "reason",
                "nextAttemptAt",
                "circuitOpen",
                "limits",
                "usage"
              ]
            },
            "maxItems": 8
          },
          "resolvedMessageIds": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Recent operator-reviewed outcomes belonging to this authenticated device; phone may retain review locally without changing actual modem state. No SMS body, recipient or review note."
          },
          "routing": {
            "type": "object",
            "properties": {
              "mode": {
                "enum": [
                  "fixed",
                  "round_robin",
                  "failover"
                ],
                "default": "fixed"
              },
              "allowedSimNumbers": {
                "type": "array",
                "minItems": 1,
                "maxItems": 8,
                "uniqueItems": true,
                "items": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                }
              },
              "preferredSimNumber": {
                "type": "integer",
                "minimum": 1,
                "maximum": 8
              },
              "stickyRecipient": {
                "type": "boolean"
              }
            },
            "required": [
              "mode",
              "allowedSimNumbers",
              "preferredSimNumber",
              "stickyRecipient"
            ],
            "additionalProperties": false
          },
          "automaticQueue": {
            "type": "object",
            "properties": {
              "queued": {
                "type": "integer",
                "minimum": 0
              },
              "reason": {
                "type": "string"
              },
              "nextAttemptAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "blockedByLimit": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "second",
                  "minute",
                  "hour",
                  "day",
                  "month",
                  "billing",
                  null
                ],
                "description": "Since 1.9.0: window currently preventing eligibility, including message_exceeds_limit. null for other causes."
              }
            },
            "required": [
              "queued",
              "reason",
              "nextAttemptAt"
            ],
            "additionalProperties": false
          },
          "metrics": {
            "$ref": "#/components/schemas/MessageMetrics",
            "description": "Own-device ordinary business-message metrics. Additive; old servers can omit this field. The operational queued/routes fields remain unchanged and can include verification/control traffic. Mobile responses can also include incoming receipts by server stored_at; their window is independent of the outgoing creation cohort."
          },
          "context": {
            "type": "object",
            "additionalProperties": false,
            "description": "Optional display-only labels for the authenticated phone and its assigned customer. Never contains sibling accounts, login credentials or SMS content. Old clients may ignore this object; missing labels do not affect routing.",
            "required": [
              "accountName",
              "projectName",
              "deviceName"
            ],
            "properties": {
              "accountName": {
                "type": "string",
                "maxLength": 120
              },
              "projectName": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 120
              },
              "deviceName": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 120
              }
            }
          },
          "workerAvailable": {
            "type": "boolean",
            "description": "Optional on the distributed runtime. True only while a worker has a fresh connected RabbitMQ heartbeat; absence retains the legacy runtime contract."
          },
          "workers": {
            "type": "object",
            "properties": {
              "lastSeenAt": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              },
              "validUntil": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              }
            },
            "required": [
              "lastSeenAt",
              "validUntil"
            ],
            "description": "Worker heartbeat freshness; not proof of SMS submission or delivery."
          }
        },
        "required": [
          "version",
          "deviceId",
          "collectedAt",
          "workerEnabled",
          "queued",
          "routes"
        ],
        "description": "Сохранённая живая очередь по SIM; истёкшие SMS не входят в queued. GET не отправляет и не повторяет SMS. nextAttemptAt учитывает бюджет частей первого сообщения либо null, если время неизвестно. Лимиты/usage измеряются частями SMS за час, 24 часа и 30 суток; queued измеряется сообщениями. queued = sum(routes[].queued) + automaticQueue.queued. Per-route counts contain pinned queue only. Added queue reasons: sim_unavailable, sim_diagnostics_stale, no_eligible_sim, routing_disabled. automaticQueue.reason=conversation_order means all unassigned messages await earlier pinned work for those recipients; nextAttemptAt is null until that work progresses. This is queued work, not a failed SMS; another SIM may still have capacity for unrelated recipients. nextAttemptAt is a check/earliest capacity estimate, not a delivery promise; null beyond message expiry. Since 1.9.0: limits/usage also include second and minute. A message larger than a full active cap after policy edits remains queued with message_exceeds_limit and no invented retry time until rules change or TTL expires. Brand-new oversized requests retain HTTP 400 message_exceeds_budget. Since 1.10.0: routes[].billingBudget is optional; billing_limit and temporary_network may resume only later queued work. The same recipient/route head observes priority with aging while preserving FIFO within its conversation."
      },
      "AdminSupportPhone": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "maxLength": 120,
            "description": "Operator nickname, cached device name, or Android fallback. Treat as untrusted display text."
          },
          "revoked": {
            "type": "boolean"
          },
          "lastSeen": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "connection": {
            "$ref": "#/components/schemas/AdminSupportConnection"
          },
          "readiness": {
            "$ref": "#/components/schemas/Readiness"
          },
          "app": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DiagnosticsApp"
              },
              {
                "type": "null"
              }
            ]
          },
          "battery": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DiagnosticsBattery"
              },
              {
                "type": "null"
              }
            ]
          },
          "queues": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DiagnosticsQueues"
              },
              {
                "type": "null"
              }
            ]
          },
          "sms": {
            "$ref": "#/components/schemas/SmartAdvice/properties/sms"
          },
          "lastFailure": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string"
                  },
                  "at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "simNumber": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1,
                    "maximum": 8
                  }
                },
                "required": [
                  "code",
                  "at",
                  "simNumber"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "sending": {
            "$ref": "#/components/schemas/SendingStatusSnapshot"
          },
          "guidance": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminSupportGuidance"
            }
          },
          "platformUser": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/PlatformUser"
              },
              {
                "type": "null"
              }
            ],
            "description": "Pairing contact/identity snapshot of current device. Null only when neither email nor principalId was supplied."
          },
          "incidents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SupportIncident"
            },
            "maxItems": 100
          },
          "nickname": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 80
          },
          "usMessaging": {
            "$ref": "#/components/schemas/UsMessagingCompactOverview"
          },
          "usLaunch": {
            "$ref": "#/components/schemas/UsLaunchCompactOverview"
          }
        },
        "required": [
          "id",
          "name",
          "revoked",
          "lastSeen",
          "connection",
          "readiness",
          "app",
          "battery",
          "queues",
          "sms",
          "lastFailure",
          "sending",
          "guidance",
          "platformUser"
        ],
        "description": "Без телефонов получателей, SMS-текстов, raw ошибок, секретов и адресов webhook. app/battery/queues — последний сохранённый отчёт, поэтому перед использованием проверяйте readiness.stale/clockMismatch/checkedAt. lastFailure — разрешённая классификация последнего сохранённого отказа за 24 часа, не доказательство текущего баланса."
      },
      "AdminSupportList": {
        "type": "object",
        "properties": {
          "collectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "freshnessMs": {
            "const": 300000
          },
          "freshUntil": {
            "type": "string",
            "format": "date-time",
            "description": "Срок валидности самого раннего актуального свидетельства на странице. UI должен перезагрузить данные или отметить их устаревшими после этого времени."
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminSupportCustomer"
            },
            "maxItems": 50
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "hasMore": {
            "type": "boolean"
          },
          "nextAfter": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "collectedAt",
          "freshnessMs",
          "freshUntil",
          "items",
          "total",
          "hasMore",
          "nextAfter"
        ],
        "description": "total относится ко всему текущему фильтру, не только к странице. Следующий запрос сохраняет q/state/limit и передаёт nextAfter как after; порядок лексикографический по tenant ID."
      },
      "AdminSupportDetail": {
        "type": "object",
        "properties": {
          "collectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "freshnessMs": {
            "const": 300000
          },
          "freshUntil": {
            "type": "string",
            "format": "date-time",
            "description": "Срок валидности самого раннего актуального свидетельства на странице. UI должен перезагрузить данные или отметить их устаревшими после этого времени."
          },
          "customer": {
            "$ref": "#/components/schemas/AdminSupportCustomer"
          },
          "users": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminSupportUser"
            },
            "maxItems": 100
          },
          "usersHasMore": {
            "type": "boolean"
          },
          "usersNextAfter": {
            "type": [
              "string",
              "null"
            ]
          },
          "devices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminSupportPhone"
            },
            "maxItems": 50
          },
          "devicesHasMore": {
            "type": "boolean"
          },
          "devicesNextAfter": {
            "type": [
              "string",
              "null"
            ]
          },
          "platformUsers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminSupportPlatformUser"
            },
            "maxItems": 100
          },
          "platformUsersHasMore": {
            "type": "boolean"
          },
          "platformUsersNextAfter": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 254,
            "description": "Email-курсор для platformUsersAfter следующего запроса либо null."
          },
          "router": {
            "$ref": "#/components/schemas/RouterStatus"
          }
        },
        "required": [
          "collectedAt",
          "freshnessMs",
          "freshUntil",
          "customer",
          "users",
          "usersHasMore",
          "usersNextAfter",
          "devices",
          "devicesHasMore",
          "devicesNextAfter",
          "platformUsers",
          "platformUsersHasMore",
          "platformUsersNextAfter"
        ],
        "description": "Локальные пользователи и телефоны имеют независимые курсоры по ID, контакты платформы platformUsers — по email. Превью первых пяти users/platformUsers из customer не является полным списком. Создание QR без сканирования не добавляет platformUsers."
      },
      "AdminSupportDeviceDetail": {
        "type": "object",
        "properties": {
          "collectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "freshnessMs": {
            "const": 300000
          },
          "freshUntil": {
            "type": "string",
            "format": "date-time",
            "description": "Срок валидности самого раннего актуального свидетельства на странице. UI должен перезагрузить данные или отметить их устаревшими после этого времени."
          },
          "tenant": {
            "$ref": "#/components/schemas/AdminSupportTenant"
          },
          "device": {
            "$ref": "#/components/schemas/AdminSupportPhone"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OperationalEvent"
            },
            "maxItems": 50
          }
        },
        "required": [
          "collectedAt",
          "freshnessMs",
          "freshUntil",
          "tenant",
          "device",
          "events"
        ],
        "description": "Последние 50 структурированных событий телефона за 7 дней. Не raw Android logs и не сообщения SMS."
      },
      "MagendaClinicLinkInput": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "clinicId": {
                "type": "string",
                "pattern": "^[1-9][0-9]{0,19}$",
                "description": "Положительный clinic ID, максимум uint64; передавать строкой."
              },
              "clinicName": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 160,
                "description": "Необязательно; пустая строка/null очищает имя. Управляющие и форматирующие Unicode-символы запрещены."
              }
            },
            "required": [
              "clinicId"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "clinicId": {
                "type": "null"
              }
            },
            "required": [
              "clinicId"
            ],
            "additionalProperties": false
          }
        ],
        "description": "Укажите существующий ID клиники после сверки integration UUID в Magenda. {clinicId:null} удаляет только информационную ссылку, не интеграцию. Клиент задаётся в URL; tenantId в query не принимается."
      },
      "PlatformUser": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "maxLength": 254,
            "description": "Нормализованный адрес пользователя платформы: trim и lowercase, без удаления точек или +suffix."
          },
          "source": {
            "const": "pairing",
            "description": "Contact/identity supplied by the authorized backend at pairing; not email verification."
          },
          "linkedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Время успешной локальной привязки этого телефона."
          },
          "principalId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 128,
            "description": "Stable identity supplied by the platform within this tenant, not email-based authorization."
          }
        },
        "required": [
          "email",
          "source",
          "linkedAt"
        ],
        "description": "Контакт пользователя платформы в рамках клиента телефона. Не создаёт учётную запись кабинета и не объединяет клиентов с одинаковой почтой. Только после успешной регистрации; хранится также у отозванного телефона."
      },
      "AdminSupportPlatformUser": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "deviceCount": {
            "type": "integer",
            "minimum": 1,
            "description": "Все телефоны этого клиента с данным email, включая отозванные."
          },
          "activeDeviceCount": {
            "type": "integer",
            "minimum": 0,
            "description": "Телефоны этого клиента с данным email, которые не отозваны."
          },
          "linkedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Дата первой успешной привязки телефона с этим email внутри клиента."
          }
        },
        "required": [
          "email",
          "deviceCount",
          "activeDeviceCount",
          "linkedAt"
        ],
        "description": "Группа подключённых телефонов по нормализованному email внутри одного клиента. Не учётная запись кабинета и не глобальный пользователь между клиентами."
      },
      "PairingWebhookInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "endpoint",
          "secret"
        ],
        "properties": {
          "endpoint": {
            "type": "string",
            "maxLength": 2000,
            "description": "HTTPS URL in WEBHOOK_ALLOWED_HOSTS, no credentials/query/fragment. {integrationId} is replaced with integration ID. Canonicalized as URL. HTTP/private networks require explicit local-test settings.",
            "examples": [
              "https://magenda.example/api/v1/webhooks/sms-gateway/{integrationId}"
            ]
          },
          "secret": {
            "type": "string",
            "writeOnly": true,
            "minLength": 43,
            "maxLength": 128,
            "pattern": "^[A-Za-z0-9_-]{43,128}$",
            "description": "Cryptographically random secret generated and persisted by the platform before requesting QR. Example: 32 random bytes in unpadded base64url or 64 hex characters. Use the UTF-8 string as HMAC key, without decoding. Reuse the same saved secret for all phones in this tenant. Never echoed."
          }
        },
        "description": "Atomically create enabled integration and QR. Existing integration is reused only with matching endpoint and secret; paused/different configuration returns 409 integration_conflict without overwriting it."
      },
      "PairingCreated": {
        "type": "object",
        "required": [
          "pairing"
        ],
        "properties": {
          "pairing": {
            "$ref": "#/components/schemas/Pairing"
          },
          "integration": {
            "$ref": "#/components/schemas/Integration",
            "description": "Present only for webhook requests, without secret. Save integration ID, commandUrl and pairing ID before showing the QR."
          }
        }
      },
      "OnboardingRecovery": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "pairing",
          "integration"
        ],
        "description": "Safe metadata included only in pairing_not_pending after same-tenant authorization, identical canonical request hash and valid bound integration revision. No QR/code/email/deviceId/secret. Recover IDs into the same attempt, then GET pairing status before explicit restart. registering/linked must retain correlation; only confirmed expired/cancelled/failed permit a new attempt. Configuration changes yield pairing_integration_changed without this object.",
        "properties": {
          "pairing": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "status",
              "expiresAt"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "status": {
                "type": "string",
                "enum": [
                  "registering",
                  "linked",
                  "expired",
                  "cancelled",
                  "failed"
                ]
              },
              "expiresAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "integration": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "endpoint",
                  "enabled"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "endpoint": {
                    "type": "string",
                    "format": "uri"
                  },
                  "enabled": {
                    "type": "boolean"
                  }
                }
              }
            ],
            "description": "Known bound integration without secret. Null for legacy idempotent QR without webhook."
          }
        }
      },
      "MessageResolution": {
        "type": "object",
        "required": [
          "decision",
          "note",
          "actorId",
          "resolvedAt"
        ],
        "properties": {
          "decision": {
            "const": "acknowledged_unknown"
          },
          "note": {
            "type": "string",
            "minLength": 10,
            "maxLength": 1000
          },
          "actorId": {
            "type": "string"
          },
          "resolvedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SmsCancelCommand": {
        "type": "object",
        "required": [
          "id",
          "version",
          "type",
          "createdAt",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "const": 1
          },
          "type": {
            "const": "sms.cancel"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "externalId"
            ],
            "properties": {
              "externalId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              }
            }
          }
        }
      },
      "CancelCommandAccepted": {
        "type": "object",
        "required": [
          "id",
          "accepted",
          "messageId",
          "cancelled",
          "state"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "accepted": {
            "const": true
          },
          "messageId": {
            "type": [
              "string",
              "null"
            ]
          },
          "cancelled": {
            "type": "boolean",
            "description": "True only for undispatched/cancelled/absent messages; a missing send gets a durable tombstone against reordered arrival."
          },
          "state": {
            "type": "string"
          }
        }
      },
      "SupportIncident": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "tenantId": {
            "type": "string"
          },
          "deviceId": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "instruction": {
            "type": "string"
          },
          "severity": {
            "enum": [
              "warning",
              "error"
            ]
          },
          "openedAt": {
            "type": "string",
            "format": "date-time"
          },
          "lastSeenAt": {
            "type": "string",
            "format": "date-time"
          },
          "resolvedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "acknowledgedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "acknowledgedBy": {
            "type": [
              "string",
              "null"
            ]
          },
          "messageId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Related SMS ID when known, for an authorized support deep link."
          }
        },
        "required": [
          "id",
          "tenantId",
          "deviceId",
          "code",
          "title",
          "instruction",
          "severity",
          "openedAt",
          "lastSeenAt",
          "resolvedAt",
          "acknowledgedAt",
          "acknowledgedBy"
        ]
      },
      "MessagePlatformUser": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "principalId": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "email": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "email"
              },
              "source": {
                "const": "pairing"
              },
              "linkedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            },
            "required": [
              "principalId",
              "email",
              "source",
              "linkedAt"
            ],
            "additionalProperties": false
          },
          {
            "type": "null"
          }
        ],
        "description": "Immutable pairing owner snapshot at message admission/first incoming acceptance. Contact metadata, not an authorization credential. Legacy unlinked history remains null."
      },
      "MessageSender": {
        "type": "object",
        "properties": {
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8
          },
          "phoneNumber": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "phoneNumberSource": {
            "enum": [
              "device_report",
              "unknown"
            ]
          }
        },
        "required": [
          "simNumber",
          "phoneNumber",
          "phoneNumberSource"
        ],
        "additionalProperties": false
      },
      "MessageRouting": {
        "type": "object",
        "properties": {
          "mode": {
            "enum": [
              "fixed",
              "round_robin",
              "failover"
            ]
          },
          "selection": {
            "enum": [
              "explicit",
              "default",
              "balanced",
              "failover",
              "sticky",
              "pending"
            ]
          },
          "pinned": {
            "type": "boolean",
            "description": "Explicit/default route or sticky recipient restriction; actual handed-off SMS never change SIM regardless of this flag."
          }
        },
        "required": [
          "mode",
          "selection",
          "pinned"
        ],
        "additionalProperties": false
      },
      "MessageStatus": {
        "type": "object",
        "properties": {
          "phase": {
            "enum": [
              "queued",
              "submitted",
              "sending",
              "sent",
              "delivered",
              "failed",
              "expired",
              "cancelled",
              "unknown"
            ]
          },
          "sequence": {
            "type": "integer",
            "minimum": 0
          },
          "deliveryReport": {
            "enum": [
              "not_sent",
              "pending",
              "confirmed",
              "unconfirmed",
              "unknown"
            ]
          }
        },
        "required": [
          "phase",
          "sequence",
          "deliveryReport"
        ],
        "additionalProperties": false,
        "description": "Monotonic per-message sequence for callback ordering. Submitted means hand-off began, not modem success. Sent is not delivered. No delivery report after 24 hours is unconfirmed, never an automatic retry."
      },
      "SimBillingBudget": {
        "type": "object",
        "properties": {
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "limitSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000000
          },
          "resetDay": {
            "type": "integer",
            "minimum": 1,
            "maximum": 31
          },
          "timezone": {
            "type": "string",
            "maxLength": 100,
            "description": "Valid IANA timezone; reset is the first real local minute of this calendar day. Short months clamp to their last day."
          },
          "externalSegments": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000000,
            "default": 0
          },
          "externalObservedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Required for nonzero externalSegments; at most 30 seconds in the future. External spend is used only in the cycle containing this observation. It supplements application spend, never refunds it."
          }
        },
        "required": [
          "simNumber",
          "limitSegments",
          "resetDay",
          "timezone"
        ],
        "additionalProperties": false
      },
      "SimBillingUsage": {
        "type": "object",
        "properties": {
          "limitSegments": {
            "type": "integer",
            "minimum": 0
          },
          "usedSegments": {
            "type": "integer",
            "minimum": 0
          },
          "remainingSegments": {
            "type": "integer",
            "minimum": 0
          },
          "appSegments": {
            "type": "integer",
            "minimum": 0
          },
          "externalSegments": {
            "type": "integer",
            "minimum": 0
          },
          "externalObservedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "externalUsageCurrent": {
            "type": "boolean"
          },
          "cycleStartsAt": {
            "type": "string",
            "format": "date-time"
          },
          "cycleEndsAt": {
            "type": "string",
            "format": "date-time"
          },
          "resetDay": {
            "type": "integer",
            "minimum": 1,
            "maximum": 31
          },
          "timezone": {
            "type": "string"
          },
          "source": {
            "const": "sendharbor_estimate"
          }
        },
        "required": [
          "limitSegments",
          "usedSegments",
          "remainingSegments",
          "appSegments",
          "externalSegments",
          "externalObservedAt",
          "externalUsageCurrent",
          "cycleStartsAt",
          "cycleEndsAt",
          "resetDay",
          "timezone",
          "source"
        ],
        "additionalProperties": false,
        "description": "Independent monthly estimate of reserved SMS parts plus dated external usage, not a live carrier balance. Rolling limits remain in force. Stale external usage is not silently carried into a new cycle."
      },
      "MfaChallenge": {
        "type": "object",
        "properties": {
          "mfaRequired": {
            "const": true
          },
          "challenge": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "mfaRequired",
          "challenge",
          "expiresAt"
        ],
        "additionalProperties": false
      },
      "AccountSecurity": {
        "type": "object",
        "properties": {
          "mfaEnabled": {
            "type": "boolean"
          },
          "enabledAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "recoveryCodesRemaining": {
            "type": "integer",
            "minimum": 0
          },
          "required": {
            "type": "boolean"
          }
        },
        "required": [
          "mfaEnabled",
          "enabledAt",
          "recoveryCodesRemaining",
          "required"
        ],
        "additionalProperties": false
      },
      "AccountSession": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "current": {
            "type": "boolean"
          },
          "createdAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastSeenAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "userAgent": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "current",
          "createdAt",
          "lastSeenAt",
          "expiresAt",
          "userAgent"
        ],
        "additionalProperties": false
      },
      "RecoveryCodes": {
        "type": "object",
        "properties": {
          "recoveryCodes": {
            "type": "array",
            "minItems": 10,
            "maxItems": 10,
            "items": {
              "type": "string"
            },
            "description": "Shown once. Every code is single-use; keep offline. Regeneration invalidates the previous set."
          }
        },
        "required": [
          "recoveryCodes"
        ],
        "additionalProperties": false
      },
      "AndroidReleaseMetadata": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string"
          },
          "versionName": {
            "type": "string"
          },
          "versionCode": {
            "type": "integer",
            "minimum": 1
          },
          "packageName": {
            "type": "string"
          },
          "minSdk": {
            "type": "integer",
            "minimum": 21
          },
          "targetSdk": {
            "type": "integer",
            "minimum": 21
          },
          "release": {
            "type": "boolean"
          },
          "channel": {
            "enum": [
              "pilot",
              "stable"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "signerSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "publishedAt": {
            "type": "string",
            "format": "date-time"
          },
          "releaseNotes": {
            "type": "string",
            "maxLength": 4000
          },
          "rollout": {
            "type": "string",
            "enum": [
              "pilot",
              "all",
              "paused"
            ],
            "description": "Optional initial distribution policy, independent of the signing channel. Publisher defaults new artifacts to pilot. The saved per-sha256 admin policy overrides this value. Legacy omission falls back to channel pilot=>pilot, stable=>all."
          }
        },
        "required": [
          "version",
          "minSdk",
          "release",
          "sha256"
        ]
      },
      "AndroidRolloutPolicy": {
        "type": "object",
        "properties": {
          "mode": {
            "enum": [
              "paused",
              "pilot",
              "all",
              "unavailable"
            ]
          },
          "deviceIds": {
            "type": "array",
            "maxItems": 1000,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "mode",
          "deviceIds",
          "updatedAt"
        ],
        "additionalProperties": false
      },
      "AndroidRolloutDevice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "tenant_id": {
            "type": "string"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "tenant_name": {
            "type": "string"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_seen": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "app_version": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "tenant_id",
          "revoked_at",
          "tenant_name",
          "name",
          "last_seen",
          "app_version"
        ],
        "additionalProperties": false
      },
      "AndroidRollout": {
        "type": "object",
        "properties": {
          "release": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/AndroidReleaseMetadata"
              },
              {
                "type": "null"
              }
            ]
          },
          "policy": {
            "$ref": "#/components/schemas/AndroidRolloutPolicy"
          },
          "devices": {
            "type": "array",
            "maxItems": 1000,
            "items": {
              "$ref": "#/components/schemas/AndroidRolloutDevice"
            }
          },
          "hasMore": {
            "type": "boolean"
          }
        },
        "required": [
          "release",
          "policy",
          "devices",
          "hasMore"
        ],
        "additionalProperties": false
      },
      "VerificationTest": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "deviceId": {
            "type": "string"
          },
          "messageId": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "replyCode": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8
          },
          "replySimNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8
          },
          "explicitSim": {
            "type": "boolean"
          },
          "current": {
            "type": "boolean"
          },
          "currentReason": {
            "type": [
              "string",
              "null"
            ]
          },
          "state": {
            "type": "string"
          },
          "queueReason": {
            "type": [
              "string",
              "null"
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "handedToPhone": {
            "type": "boolean"
          },
          "receivedConfirmedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "replyReceivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "integrationAccepted": {
            "type": "boolean"
          },
          "magendaAccepted": {
            "type": "boolean",
            "deprecated": true
          },
          "webhook": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string"
                  },
                  "attempts": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "nextAttemptAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "acceptedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  }
                },
                "required": [
                  "status",
                  "attempts",
                  "nextAttemptAt",
                  "acceptedAt"
                ],
                "additionalProperties": false
              },
              {
                "type": "null"
              }
            ]
          },
          "verifiedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expired": {
            "type": "boolean"
          },
          "webhookRequired": {
            "type": "boolean",
            "default": true,
            "description": "False only when this account project explicitly disables outgoing webhook events. The SIM loop can then complete without a webhook ACK; it does not prove delivery to an external integration. Missing fields retain the legacy true behavior."
          }
        },
        "required": [
          "id",
          "deviceId",
          "messageId",
          "phone",
          "replyCode",
          "createdAt",
          "expiresAt",
          "simNumber",
          "replySimNumber",
          "explicitSim",
          "current",
          "currentReason",
          "state",
          "queueReason",
          "error",
          "handedToPhone",
          "receivedConfirmedAt",
          "replyReceivedAt",
          "integrationAccepted",
          "magendaAccepted",
          "webhook",
          "verifiedAt",
          "expired"
        ],
        "additionalProperties": false,
        "description": "A test expires in 15 minutes and spends normal queue/SIM budgets. Current proof requires fresh diagnostics, the same accepted SIM verificationTag, unchanged sending policy and current channel configuration. A matching reply must arrive from the consenting test number on the tested SIM after modem hand-off. When webhookRequired is true, integration revision and HTTP callback acceptance are required, followed by user confirmation of visibility in the external project. When explicitly false, verification covers only SMS sending and the matching incoming reply, with no claim of external-project delivery; integrationAccepted stays false without an accepted webhook. The manual RCS assertion remains part of the configuration fingerprint. Missing webhookRequired means true. With an active Live SIM test, the first fixed connection challenge proves the exact trial recipient only through its real matching reply. A manual receipt checkbox does not unlock it; until proof, an ambiguous retry must preserve the same verification run ID."
      },
      "VerificationSim": {
        "type": "object",
        "properties": {
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "phoneNumber": {
            "type": [
              "string",
              "null"
            ]
          },
          "carrierName": {
            "type": [
              "string",
              "null"
            ]
          },
          "available": {
            "type": "boolean"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "lastVerifiedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "latest": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/VerificationTest"
              },
              {
                "type": "null"
              }
            ]
          },
          "rcsConfirmationSupported": {
            "type": "boolean",
            "description": "False means the APK did not report the optional manual RCS confirmation field."
          },
          "rcsDisabledConfirmedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "User assertion only; null when diagnostics/identity are stale or the phone is revoked."
          },
          "rcsConfirmation": {
            "enum": [
              "user_confirmed_off",
              "unconfirmed",
              "stale"
            ]
          },
          "incomingSmsVerifiedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Actual matching incoming SMS on this SIM under current configuration. Requires challenge, sender and post-dispatch time match. Does not imply webhook acceptance or external-project visibility."
          },
          "webhookRequired": {
            "type": "boolean",
            "default": true,
            "description": "False only when this account project explicitly disables outgoing webhook events. The SIM loop can then complete without a webhook ACK; it does not prove delivery to an external integration. Missing fields retain the legacy true behavior."
          },
          "liveTest": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/LiveSimTest"
              },
              {
                "type": "null"
              }
            ],
            "description": "Optional ordinary Live SIM test state. Does not establish tariff permission or prove carrier delivery; older servers omit it."
          }
        },
        "required": [
          "simNumber",
          "phoneNumber",
          "carrierName",
          "available",
          "reason",
          "lastVerifiedAt",
          "latest",
          "rcsConfirmationSupported",
          "rcsDisabledConfirmedAt",
          "rcsConfirmation",
          "incomingSmsVerifiedAt"
        ],
        "additionalProperties": false
      },
      "VerificationOverview": {
        "type": "object",
        "properties": {
          "latest": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/VerificationTest"
              },
              {
                "type": "null"
              }
            ]
          },
          "sims": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/VerificationSim"
            }
          },
          "diagnosticsFresh": {
            "type": "boolean"
          },
          "diagnosticsValidUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastCurrentVerifiedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastVerifiedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Historical aggregate only; never marks any current SIM verified."
          },
          "webhookRequired": {
            "type": "boolean",
            "default": true,
            "description": "False only when this account project explicitly disables outgoing webhook events. The SIM loop can then complete without a webhook ACK; it does not prove delivery to an external integration. Missing fields retain the legacy true behavior."
          }
        },
        "required": [
          "latest",
          "sims",
          "diagnosticsFresh",
          "diagnosticsValidUntil",
          "lastCurrentVerifiedAt",
          "lastVerifiedAt"
        ],
        "additionalProperties": false
      },
      "RcsSetup": {
        "type": "object",
        "description": "Safe current active-SIM summary for diagnostics and support. Contains no phone numbers, SMS contents, challenges or identity tags. This app cannot detect RCS settings.",
        "properties": {
          "automaticallyDetected": {
            "const": false
          },
          "diagnosticsFresh": {
            "type": "boolean"
          },
          "diagnosticsValidUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "sims": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "object",
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "current": {
                  "type": "boolean"
                },
                "reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "rcsConfirmationSupported": {
                  "type": "boolean",
                  "description": "False means the APK did not report the optional manual RCS confirmation field."
                },
                "rcsDisabledConfirmedAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time",
                  "description": "User assertion only; null when diagnostics/identity are stale or the phone is revoked."
                },
                "rcsConfirmation": {
                  "enum": [
                    "user_confirmed_off",
                    "unconfirmed",
                    "stale"
                  ]
                },
                "incomingSmsVerifiedAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time",
                  "description": "Actual matching incoming SMS on this SIM under current configuration. Requires challenge, sender and post-dispatch time match. Does not imply webhook acceptance or external-project visibility."
                },
                "lastVerifiedAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "webhookRequired": {
                  "type": "boolean",
                  "default": true,
                  "description": "False only when this account project explicitly disables outgoing webhook events. The SIM loop can then complete without a webhook ACK; it does not prove delivery to an external integration. Missing fields retain the legacy true behavior."
                }
              },
              "required": [
                "simNumber",
                "current",
                "reason",
                "rcsConfirmationSupported",
                "rcsDisabledConfirmedAt",
                "rcsConfirmation",
                "incomingSmsVerifiedAt",
                "lastVerifiedAt"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "automaticallyDetected",
          "diagnosticsFresh",
          "diagnosticsValidUntil",
          "sims"
        ],
        "additionalProperties": false
      },
      "UsMessagingSummary": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "market": {
            "enum": [
              "unknown",
              "US",
              "other"
            ],
            "description": "Manual market classification. Never inferred from +1, GPS, physical device location, carrier name or phone settings."
          },
          "status": {
            "enum": [
              "unknown",
              "not_registered",
              "pending",
              "reported_registered",
              "rejected",
              "not_applicable"
            ],
            "description": "An operator statement, not a carrier lookup. reported_registered requires US, senderNumber, provider, brandId, campaignId and a current accepted SIM identity. not_applicable means the named provider reported registration is not required for this sender/route; it still does not assert carrier permission."
          },
          "carrierPermission": {
            "enum": [
              "unknown",
              "reported_allowed",
              "reported_denied"
            ],
            "description": "Separate manual record of the carrier/provider permission to use this SIM/route for automated business messages. reported_allowed needs provider, senderNumber and current accepted SIM identity."
          },
          "current": {
            "type": "boolean",
            "description": "The manual record matches fresh accepted SIM identity and the observed sender when available. This is not a registration, delivery, legal or carrier-authorization check."
          },
          "reason": {
            "enum": [
              null,
              "device_revoked",
              "diagnostics_stale",
              "sim_missing",
              "sim_changed",
              "identity_unavailable",
              "sender_number_changed"
            ]
          },
          "needsAttention": {
            "type": "boolean",
            "description": "Informational for explicitly selected US market only. Does not block sending, change routing, alter limits or mark the phone ready."
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "source": {
            "const": "manual"
          },
          "providerVerified": {
            "const": false
          }
        },
        "required": [
          "simNumber",
          "market",
          "status",
          "carrierPermission",
          "current",
          "reason",
          "needsAttention",
          "updatedAt",
          "source",
          "providerVerified"
        ],
        "description": "Compact per-SIM manual US A2P record; includes no sender, provider, Brand/Campaign IDs or SIM verification tag."
      },
      "UsMessagingInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "market": {
            "enum": [
              "unknown",
              "US",
              "other"
            ],
            "description": "Manual market classification. Never inferred from +1, GPS, physical device location, carrier name or phone settings."
          },
          "status": {
            "enum": [
              "unknown",
              "not_registered",
              "pending",
              "reported_registered",
              "rejected",
              "not_applicable"
            ],
            "description": "An operator statement, not a carrier lookup. reported_registered requires US, senderNumber, provider, brandId, campaignId and a current accepted SIM identity. not_applicable means the named provider reported registration is not required for this sender/route; it still does not assert carrier permission."
          },
          "senderNumber": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 16,
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "provider": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 120
          },
          "brandId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 64
          },
          "campaignId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 64
          },
          "carrierPermission": {
            "enum": [
              "unknown",
              "reported_allowed",
              "reported_denied"
            ],
            "description": "Separate manual record of the carrier/provider permission to use this SIM/route for automated business messages. reported_allowed needs provider, senderNumber and current accepted SIM identity."
          },
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991,
            "description": "0 for a new SIM record; otherwise the exact revision returned by GET. A stale update returns 409 without changing the record."
          },
          "expectedVerificationTag": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 36,
            "pattern": "^[a-fA-F0-9-]{36}$",
            "description": "Exact current tag returned by GET, or null when no fresh accepted SIM identity exists. Stale identity returns 409. Positive registration/exemption/permission claims require a current non-null tag."
          }
        },
        "required": [
          "market",
          "status",
          "senderNumber",
          "provider",
          "brandId",
          "campaignId",
          "carrierPermission",
          "revision",
          "expectedVerificationTag"
        ],
        "description": "Full replacement of the manual record. Non-US/unknown market requires status=unknown, carrierPermission=unknown, provider/brandId/campaignId=null. Explicit sender may be retained. Other strings cannot contain control characters. reported_registered requires all four sender/provider/brand/campaign fields. not_applicable and reported_allowed require provider and sender. This endpoint never submits any carrier or TCR registration."
      },
      "UsMessagingSim": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "market": {
            "enum": [
              "unknown",
              "US",
              "other"
            ],
            "description": "Manual market classification. Never inferred from +1, GPS, physical device location, carrier name or phone settings."
          },
          "status": {
            "enum": [
              "unknown",
              "not_registered",
              "pending",
              "reported_registered",
              "rejected",
              "not_applicable"
            ],
            "description": "An operator statement, not a carrier lookup. reported_registered requires US, senderNumber, provider, brandId, campaignId and a current accepted SIM identity. not_applicable means the named provider reported registration is not required for this sender/route; it still does not assert carrier permission."
          },
          "carrierPermission": {
            "enum": [
              "unknown",
              "reported_allowed",
              "reported_denied"
            ],
            "description": "Separate manual record of the carrier/provider permission to use this SIM/route for automated business messages. reported_allowed needs provider, senderNumber and current accepted SIM identity."
          },
          "current": {
            "type": "boolean",
            "description": "The manual record matches fresh accepted SIM identity and the observed sender when available. This is not a registration, delivery, legal or carrier-authorization check."
          },
          "reason": {
            "enum": [
              null,
              "device_revoked",
              "diagnostics_stale",
              "sim_missing",
              "sim_changed",
              "identity_unavailable",
              "sender_number_changed"
            ]
          },
          "needsAttention": {
            "type": "boolean",
            "description": "Informational for explicitly selected US market only. Does not block sending, change routing, alter limits or mark the phone ready."
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "source": {
            "const": "manual"
          },
          "providerVerified": {
            "const": false
          },
          "senderNumber": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 16,
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "provider": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 120
          },
          "brandId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 64
          },
          "campaignId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 64
          },
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991,
            "description": "0 for a new SIM record; otherwise the exact revision returned by GET. A stale update returns 409 without changing the record."
          },
          "expectedVerificationTag": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 36,
            "pattern": "^[a-fA-F0-9-]{36}$",
            "description": "Exact current tag returned by GET, or null when no fresh accepted SIM identity exists. Stale identity returns 409. Positive registration/exemption/permission claims require a current non-null tag."
          },
          "observedSenderNumber": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 16,
            "pattern": "^\\+[1-9]\\d{6,14}$"
          }
        },
        "required": [
          "simNumber",
          "market",
          "status",
          "carrierPermission",
          "current",
          "reason",
          "needsAttention",
          "updatedAt",
          "source",
          "providerVerified",
          "senderNumber",
          "provider",
          "brandId",
          "campaignId",
          "revision",
          "expectedVerificationTag",
          "observedSenderNumber"
        ],
        "description": "Historical statements remain visible when current=false; do not render an old/replaced SIM as approved. A new record defaults to unknown even for US-looking numbers. Android may not expose its own number, so observedSenderNumber can be null."
      },
      "UsMessagingOverview": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "deviceId": {
            "type": "string"
          },
          "source": {
            "const": "manual"
          },
          "providerVerified": {
            "const": false
          },
          "diagnosticsFresh": {
            "type": "boolean"
          },
          "diagnosticsValidUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "sims": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/UsMessagingSim"
            }
          }
        },
        "required": [
          "deviceId",
          "source",
          "providerVerified",
          "diagnosticsFresh",
          "diagnosticsValidUntil",
          "sims"
        ]
      },
      "UsMessagingCompactOverview": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "deviceId": {
            "type": "string"
          },
          "source": {
            "const": "manual"
          },
          "providerVerified": {
            "const": false
          },
          "diagnosticsFresh": {
            "type": "boolean"
          },
          "diagnosticsValidUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "sims": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/UsMessagingSummary"
            }
          }
        },
        "required": [
          "deviceId",
          "source",
          "providerVerified",
          "diagnosticsFresh",
          "diagnosticsValidUntil",
          "sims"
        ]
      },
      "UsLaunchCaps": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "second": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000
          },
          "minute": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000
          },
          "hour": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000
          },
          "day": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000
          },
          "month": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000000
          }
        },
        "required": [
          "second",
          "minute",
          "hour",
          "day",
          "month"
        ],
        "description": "Retired document-review schema, retained for historical contract compatibility. Current sending does not use document reviews or their caps; current mobile route projections omit usLaunch.",
        "deprecated": true
      },
      "UsLaunchSubmission": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "expectedVerificationTag": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-fA-F0-9-]{36}$"
          },
          "senderNumber": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$",
            "maxLength": 16
          },
          "carrier": {
            "enum": [
              "att",
              "tmobile",
              "verizon",
              "mvno",
              "other"
            ]
          },
          "carrierName": {
            "type": "string",
            "maxLength": 120
          },
          "planName": {
            "type": "string",
            "maxLength": 160
          },
          "evidenceReference": {
            "type": "string",
            "maxLength": 2000,
            "description": "Private document/ticket reference for a human reviewer. No automatic URL fetch or verification; do not put credentials or SMS bodies here."
          },
          "permissionScope": {
            "const": "automated_business_sms"
          },
          "usageScope": {
            "enum": [
              "transactional",
              "marketing",
              "mixed"
            ]
          }
        },
        "required": [
          "revision",
          "expectedVerificationTag",
          "senderNumber",
          "carrier",
          "carrierName",
          "planName",
          "evidenceReference",
          "permissionScope",
          "usageScope"
        ],
        "description": "Retired document-review schema, retained for historical contract compatibility. Current sending does not use document reviews or their caps; current mobile route projections omit usLaunch.",
        "deprecated": true
      },
      "UsLaunchReview": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "expectedVerificationTag": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-fA-F0-9-]{36}$"
          },
          "decision": {
            "enum": [
              "approve",
              "deny",
              "revoke"
            ]
          },
          "reviewExpiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "automatedSmsConfirmed": {
            "type": "boolean"
          },
          "allUsRecipientNetworksConfirmed": {
            "type": "boolean"
          },
          "caps": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/UsLaunchCaps"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "revision",
          "expectedVerificationTag",
          "decision",
          "reviewExpiresAt",
          "automatedSmsConfirmed",
          "allUsRecipientNetworksConfirmed",
          "caps"
        ],
        "description": "Retired document-review schema, retained for historical contract compatibility. Current sending does not use document reviews or their caps; current mobile route projections omit usLaunch.",
        "deprecated": true
      },
      "UsLaunchSummary": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "status": {
            "const": "not_required"
          },
          "current": {
            "type": "boolean",
            "description": "Current accepted technical SIM identity is available. Does not mean a carrier reviewed or approved this SIM."
          },
          "allowed": {
            "const": true,
            "description": "Document review is not required. This is not a carrier approval or a technical permission to send."
          },
          "reason": {
            "type": "null"
          },
          "reviewExpiresAt": {
            "type": "null"
          },
          "source": {
            "const": "user_managed_sim"
          },
          "providerVerified": {
            "const": false
          }
        },
        "required": [
          "simNumber",
          "status",
          "current",
          "allowed",
          "reason",
          "reviewExpiresAt",
          "source",
          "providerVerified"
        ],
        "description": "Neutral compatibility projection. SIM document review is retired; historical review state does not authorize, cap or block sending."
      },
      "UsLaunchSim": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "status": {
            "const": "not_required"
          },
          "current": {
            "type": "boolean",
            "description": "Current accepted technical SIM identity is available. Does not mean a carrier reviewed or approved this SIM."
          },
          "allowed": {
            "const": true,
            "description": "Document review is not required. This is not a carrier approval or a technical permission to send."
          },
          "reason": {
            "type": "null"
          },
          "reviewExpiresAt": {
            "type": "null"
          },
          "source": {
            "const": "user_managed_sim"
          },
          "providerVerified": {
            "const": false
          },
          "revision": {
            "const": 0
          },
          "expectedVerificationTag": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-fA-F0-9-]{36}$"
          },
          "senderNumber": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "carrier": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "carrierName": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "planName": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "evidenceReference": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "permissionScope": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "usageScope": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "submittedAt": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "reviewedAt": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "automatedSmsConfirmed": {
            "const": false
          },
          "allUsRecipientNetworksConfirmed": {
            "const": false
          },
          "caps": {
            "type": "null",
            "description": "Retired document-review field; current responses do not disclose historical submissions."
          },
          "observedSenderNumber": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^\\+[1-9]\\d{6,14}$"
          }
        },
        "required": [
          "simNumber",
          "status",
          "current",
          "allowed",
          "reason",
          "reviewExpiresAt",
          "source",
          "providerVerified",
          "revision",
          "expectedVerificationTag",
          "senderNumber",
          "carrier",
          "carrierName",
          "planName",
          "evidenceReference",
          "permissionScope",
          "usageScope",
          "submittedAt",
          "reviewedAt",
          "automatedSmsConfirmed",
          "allUsRecipientNetworksConfirmed",
          "caps",
          "observedSenderNumber"
        ],
        "description": "Neutral compatibility projection. SIM document review is retired; historical review state does not authorize, cap or block sending."
      },
      "UsLaunchOverview": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "deviceId": {
            "type": "string"
          },
          "required": {
            "const": false,
            "description": "SIM document moderation is no longer required, regardless of the legacy US_SIM_LAUNCH_REQUIRED setting."
          },
          "source": {
            "const": "user_managed_sim"
          },
          "providerVerified": {
            "const": false
          },
          "diagnosticsFresh": {
            "type": "boolean"
          },
          "diagnosticsValidUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "sims": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/UsLaunchSim"
            }
          }
        },
        "required": [
          "deviceId",
          "required",
          "source",
          "providerVerified",
          "diagnosticsFresh",
          "diagnosticsValidUntil",
          "sims"
        ],
        "description": "Compatibility read projection for older clients. No administrator clearance is needed; independent technical, sender, recipient and queue conditions still apply."
      },
      "UsLaunchCompactOverview": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "deviceId": {
            "type": "string"
          },
          "required": {
            "const": false,
            "description": "SIM document moderation is no longer required, regardless of the legacy US_SIM_LAUNCH_REQUIRED setting."
          },
          "source": {
            "const": "user_managed_sim"
          },
          "providerVerified": {
            "const": false
          },
          "diagnosticsFresh": {
            "type": "boolean"
          },
          "diagnosticsValidUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "sims": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/UsLaunchSummary"
            }
          }
        },
        "required": [
          "deviceId",
          "required",
          "source",
          "providerVerified",
          "diagnosticsFresh",
          "diagnosticsValidUntil",
          "sims"
        ],
        "description": "Compatibility read projection for older clients. No administrator clearance is needed; independent technical, sender, recipient and queue conditions still apply."
      },
      "UsLaunchGate": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "required": {
            "type": "boolean",
            "description": "Technical identity guard under the legacy US profile; not document moderation."
          },
          "allowed": {
            "type": "boolean",
            "description": "Whether the current technical SIM identity permits this attempt; independent of historical operator documents."
          },
          "reason": {
            "enum": [
              null,
              "diagnostics_stale",
              "sim_missing",
              "sim_identity_unavailable",
              "sim_identity_changed",
              "app_upgrade_required",
              "device_revoked"
            ]
          },
          "next": {
            "type": "null"
          },
          "reviewRevision": {
            "const": 0
          },
          "reviewExpiresAt": {
            "type": "null"
          },
          "caps": {
            "type": "null"
          },
          "usageScope": {
            "type": "null"
          },
          "status": {
            "const": "not_required"
          },
          "current": {
            "type": "boolean",
            "description": "Current technical SIM evidence and observed identity match."
          },
          "source": {
            "const": "sim_identity_check"
          },
          "providerVerified": {
            "const": false
          },
          "identityTag": {
            "type": [
              "string",
              "null"
            ],
            "description": "Internal current diagnostic SIM generation. Captured with a reservation and compared again immediately before modem hand-off; never an operator review ID."
          }
        },
        "required": [
          "required",
          "allowed",
          "reason",
          "next",
          "reviewRevision",
          "reviewExpiresAt",
          "caps",
          "usageScope",
          "status",
          "current",
          "source",
          "providerVerified"
        ],
        "description": "Internal technical gate shape. No document approval, review cap or reviewed purpose is evaluated."
      },
      "UsLaunchMobileSummary": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "required": {
            "const": true
          },
          "allowed": {
            "type": "boolean",
            "description": "Effective launch gate; if deployment requirement is disabled this may be true with status=missing. Always inspect required/source/status."
          },
          "status": {
            "enum": [
              "missing",
              "pending",
              "approved",
              "denied",
              "revoked"
            ]
          },
          "reason": {
            "enum": [
              null,
              "us_permission_missing",
              "us_permission_pending",
              "us_permission_denied",
              "us_permission_revoked",
              "us_permission_expired",
              "us_permission_stale",
              "us_identity_unavailable",
              "us_sender_mismatch",
              "us_permission_app_upgrade_required",
              "device_revoked",
              "us_permission_purpose_not_allowed"
            ]
          },
          "reviewExpiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "source": {
            "const": "internal_document_review"
          },
          "providerVerified": {
            "const": false
          }
        },
        "required": [
          "required",
          "allowed",
          "status",
          "reason",
          "reviewExpiresAt",
          "source",
          "providerVerified"
        ],
        "description": "Retired document-review schema, retained for historical contract compatibility. Current sending does not use document reviews or their caps; current mobile route projections omit usLaunch.",
        "deprecated": true
      },
      "MessagePurpose": {
        "type": "string",
        "enum": [
          "transactional",
          "marketing"
        ],
        "default": "transactional",
        "description": "Declared message purpose. Default/legacy messages are transactional. Marketing requires its own recipient consent and a SIM review permitting marketing or mixed use. Purpose does not create consent or carrier permission. Changing purpose for the same idempotency key conflicts."
      },
      "UsConsentInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740990,
            "description": "Compare-and-swap revision returned by GET; use 0 for a missing record. Reload after 409 rather than blindly retrying."
          },
          "purposes": {
            "type": "array",
            "minItems": 1,
            "maxItems": 2,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "enum": [
                "transactional",
                "marketing"
              ]
            }
          },
          "source": {
            "type": "string",
            "enum": [
              "web_form",
              "paper",
              "verbal",
              "import"
            ]
          },
          "evidenceReference": {
            "type": "string",
            "minLength": 1,
            "maxLength": 240,
            "description": "Nonblank, non-secret internal reference to customer-reported evidence. No control characters; no SMS bodies, patient data, tokens or signed document URLs."
          },
          "obtainedAt": {
            "type": "string",
            "format": "date-time",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?(?:Z|[+-]\\d{2}:\\d{2})$",
            "description": "Actual time consent was obtained; must not be in the future. After STOP and subsequent START it must be later than the latest STOP."
          },
          "expiresAt": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?(?:Z|[+-]\\d{2}:\\d{2})$"
              },
              {
                "type": "null"
              }
            ],
            "description": "Null or an absolute future deadline strictly later than obtainedAt."
          },
          "timezone": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "description": "Valid IANA region/name, such as America/New_York, or UTC. Explicit recipient timezone; never inferred from phone prefix or device location."
          },
          "windowStart": {
            "type": "string",
            "pattern": "^(?:09|1[0-9]):[0-5][0-9]$",
            "default": "09:00",
            "description": "Local start, inclusive; must be at least 09:00 and strictly before windowEnd. Optional only when omitted; null is invalid."
          },
          "windowEnd": {
            "type": "string",
            "pattern": "^(?:(?:09|1[0-9]):[0-5][0-9]|20:00)$",
            "default": "20:00",
            "description": "Local end, exclusive; must be later than windowStart and no later than 20:00. Server validates the combined window. This conservative product window does not claim to satisfy every applicable rule."
          }
        },
        "required": [
          "revision",
          "purposes",
          "source",
          "evidenceReference",
          "obtainedAt",
          "expiresAt",
          "timezone"
        ],
        "description": "Full customer-reported consent replacement. No verified, verification, suppression override or other additional flags. START alone does not recreate consent."
      },
      "UsConsent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "purposes": {
            "type": "array",
            "maxItems": 2,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "enum": [
                "transactional",
                "marketing"
              ]
            }
          },
          "source": {
            "enum": [
              "web_form",
              "paper",
              "verbal",
              "import",
              null
            ]
          },
          "evidenceReference": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 240
          },
          "obtainedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "timezone": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "windowStart": {
            "type": "string",
            "default": "09:00"
          },
          "windowEnd": {
            "type": "string",
            "default": "20:00"
          },
          "status": {
            "enum": [
              "missing",
              "active",
              "expired",
              "revoked"
            ],
            "description": "Active describes this record, not current dispatch permission. Quiet hours, purpose, STOP, SIM permission and other gates are checked separately."
          },
          "suppressed": {
            "type": "boolean"
          },
          "revokedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Latest recorded STOP timestamp, including a STOP predating newly obtained consent. Inspect status and suppressed as well."
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "recordType": {
            "const": "customer_reported"
          },
          "verified": {
            "const": false
          },
          "required": {
            "const": false,
            "description": "Keeping consent evidence in SendHarbor is optional. Active STOP and saved recipient sending windows remain enforced."
          }
        },
        "required": [
          "phone",
          "revision",
          "purposes",
          "source",
          "evidenceReference",
          "obtainedAt",
          "expiresAt",
          "timezone",
          "windowStart",
          "windowEnd",
          "status",
          "suppressed",
          "revokedAt",
          "updatedAt",
          "recordType",
          "verified",
          "required"
        ],
        "description": "Optional customer-reported evidence; missing/expired records here do not hold ordinary SMS. This never establishes actual consent or cancels STOP. An explicitly saved sending window still delays delivery until its next opening."
      },
      "UsMessagingSettingsInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740990,
            "description": "Compare-and-swap revision returned by GET; use 0 for a missing record. Reload after 409 rather than blindly retrying."
          },
          "brandName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60,
            "description": "Sender display name, for an individual or organization; trimmed. No control or bidirectional override characters."
          },
          "supportContact": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160,
            "description": "Plain email, E.164 phone or HTTPS URL. URL rules match privacyUrl. No arbitrary reply template or credentials."
          },
          "privacyUrl": {
            "type": "string",
            "format": "uri",
            "maxLength": 500,
            "pattern": "^https://",
            "description": "HTTPS URL without credentials, query string, fragment, whitespace or control/bidirectional override characters. The server does not fetch or certify this page."
          },
          "termsUrl": {
            "type": "string",
            "format": "uri",
            "maxLength": 500,
            "pattern": "^https://",
            "description": "HTTPS URL without credentials, query string, fragment, whitespace or control/bidirectional override characters. The server does not fetch or certify this page."
          }
        },
        "required": [
          "revision",
          "brandName",
          "supportContact",
          "privacyUrl",
          "termsUrl"
        ],
        "description": "Optional customer-reported sender settings for automatic HELP and service replies. Ordinary SMS require no profile. Input validation does not verify identities, linked pages or consent."
      },
      "UsMessagingSettings": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "brandName": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 60
          },
          "supportContact": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 160
          },
          "privacyUrl": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 500
          },
          "termsUrl": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 500
          },
          "complete": {
            "type": "boolean"
          },
          "required": {
            "const": false,
            "description": "Sender profile is optional for ordinary SMS."
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "recordType": {
            "const": "customer_reported"
          },
          "verified": {
            "const": false
          },
          "autoRepliesEnabled": {
            "type": "boolean",
            "description": "True when the configured command responder has a complete profile for fixed HELP/service replies. This does not authorize or block ordinary SMS."
          }
        },
        "required": [
          "revision",
          "brandName",
          "supportContact",
          "privacyUrl",
          "termsUrl",
          "complete",
          "required",
          "updatedAt",
          "recordType",
          "verified",
          "autoRepliesEnabled"
        ]
      },
      "UsSetupStep": {
        "type": "object",
        "required": [
          "id",
          "state",
          "owner",
          "reason",
          "blocking"
        ],
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "phone",
              "rcs",
              "clearance",
              "test",
              "business",
              "consent",
              "first_sms"
            ]
          },
          "state": {
            "type": "string",
            "enum": [
              "ready",
              "action_required",
              "pending",
              "blocked",
              "stale",
              "not_selected"
            ]
          },
          "owner": {
            "type": "string",
            "enum": [
              "client",
              "device",
              "admin",
              "system"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "blocking": {
            "type": "boolean",
            "description": "Whether this current issue actually prevents ordinary sending. False for recommendations and optional tests; inspect state separately for evidence."
          }
        }
      },
      "UsSetupOverview": {
        "type": "object",
        "required": [
          "version",
          "deviceId",
          "generatedAt",
          "validUntil",
          "required",
          "selectedSimNumber",
          "device",
          "business",
          "integration",
          "sims",
          "consent",
          "firstMessage",
          "steps",
          "nextStep",
          "mode",
          "readyForSending",
          "recommendations",
          "accountId"
        ],
        "description": "Read-only, expiring snapshot of technical sending readiness and nonblocking recommendations. The self_service guide completes after technical setup without RCS acknowledgement, tests, sender profile or stored consent evidence. This is not carrier permission or a promise of delivery. Existing seven wire steps retain truthful evidence; clearance is neutral and omitted in current UIs.",
        "properties": {
          "version": {
            "type": "integer",
            "const": 1
          },
          "deviceId": {
            "type": "string"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "validUntil": {
            "type": "string",
            "format": "date-time"
          },
          "required": {
            "const": false,
            "description": "No SIM document moderation. Ordinary sending does not require a business profile or consent evidence stored here."
          },
          "selectedSimNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8
          },
          "device": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "linked": {
                "type": "boolean"
              },
              "revoked": {
                "type": "boolean"
              },
              "lastSeen": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "business": {
            "type": "object",
            "properties": {
              "complete": {
                "type": "boolean"
              },
              "required": {
                "const": false
              },
              "verified": {
                "type": "boolean",
                "const": false
              },
              "autoRepliesEnabled": {
                "type": "boolean"
              }
            }
          },
          "integration": {
            "type": "object",
            "description": "Current integration transport only. No endpoint or secret. HTTP acknowledgement does not prove project UI visibility.",
            "properties": {
              "configured": {
                "type": "boolean"
              },
              "enabled": {
                "type": "boolean"
              },
              "pending": {
                "type": "integer"
              },
              "failed": {
                "type": "integer"
              },
              "lastAcceptedAt": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "webhookRequired": {
                "type": "boolean",
                "default": true,
                "description": "False only when this account project explicitly disables outgoing webhook events. The SIM loop can then complete without a webhook ACK; it does not prove delivery to an external integration. Missing fields retain the legacy true behavior."
              }
            }
          },
          "sims": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "simNumber",
                "clearance",
                "rcsConfirmation",
                "verificationCurrent"
              ],
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "clearance": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "description": "Compact canonical US launch state: status/current/allowed/reason/reviewExpiresAt/source/providerVerified, no document reference or sender number."
                },
                "rcsConfirmation": {
                  "type": "string",
                  "enum": [
                    "stale",
                    "unconfirmed",
                    "user_confirmed_off"
                  ]
                },
                "rcsDisabledConfirmedAt": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "incomingSmsVerifiedAt": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "lastVerifiedAt": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "verificationCurrent": {
                  "type": "boolean"
                },
                "verificationReason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "liveTest": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/LiveSimTest"
                    },
                    {
                      "type": "null"
                    }
                  ],
                  "description": "Optional ordinary Live SIM test state. Does not establish tariff permission or prove carrier delivery; older servers omit it."
                }
              }
            }
          },
          "consent": {
            "type": "object",
            "description": "State for the selected recipient only. Missing/expired evidence is advisory; actual STOP and a saved sending window are blocking.",
            "properties": {
              "phone": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "purpose": {
                "type": "string",
                "enum": [
                  "transactional",
                  "marketing"
                ]
              },
              "selected": {
                "type": "boolean"
              },
              "status": {
                "type": "string",
                "enum": [
                  "not_selected",
                  "missing",
                  "active",
                  "expired",
                  "revoked"
                ]
              },
              "allowed": {
                "type": [
                  "boolean",
                  "null"
                ]
              },
              "reason": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "next": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "warningReason": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "firstMessage": {
            "type": [
              "object",
              "null"
            ],
            "description": "Latest ordinary SMS for the selected SIM, recipient and purpose, excluding actual verification/control records. Null in web without a recipient or messages:read. Device view has only its own recent ordinary state. No message ID, text or phone is returned.",
            "properties": {
              "state": {
                "type": "string"
              },
              "simNumber": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "updatedAt": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "queueReason": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UsSetupStep"
            }
          },
          "nextStep": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/UsSetupStep"
              },
              {
                "type": "null"
              }
            ]
          },
          "actor": {
            "type": "object",
            "description": "Web only. No mobile/admin self-approval. Actions use their existing mutation scope and CSRF checks.",
            "properties": {
              "canEdit": {
                "type": "boolean"
              },
              "canSubmitSim": {
                "type": "boolean"
              },
              "canSend": {
                "type": "boolean"
              },
              "canEditBusiness": {
                "type": "boolean"
              },
              "canEditConsent": {
                "type": "boolean"
              },
              "canReview": {
                "type": "boolean"
              }
            }
          },
          "readiness": {
            "type": "object",
            "description": "Web only: canonical diagnostics readiness."
          },
          "usLaunch": {
            "type": "object",
            "description": "Web only: compact canonical per-SIM review overview."
          },
          "accountId": {
            "type": "string",
            "description": "Exact scoped customer account for this snapshot; UI consumers must reject a different account."
          },
          "mode": {
            "const": "self_service"
          },
          "readyForSending": {
            "type": "boolean",
            "description": "Current technical checks for the selected route allow ordinary sending. Freshness, real SMS failures, active STOP and configured limits/schedule still apply at dispatch. Not proof of receiving, delivery or consent."
          },
          "recommendations": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "reason"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                }
              }
            }
          }
        }
      },
      "MessageMetrics": {
        "type": "object",
        "additionalProperties": false,
        "description": "Read-only server database snapshot of ordinary outbound SMS counts, not segments. Excludes verification and private control traffic. last24h uses creation time and current stored state; UI must label it as SMS created in the last 24 hours. It does not claim carrier delivery rate, event throughput, phone connectivity, or balance. Missing, invalid or expired metrics are unavailable, not zero.",
        "required": [
          "version",
          "generatedAt",
          "validUntil",
          "unit",
          "source",
          "scope",
          "current",
          "last24h"
        ],
        "properties": {
          "version": {
            "const": 1
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "validUntil": {
            "type": "string",
            "format": "date-time",
            "description": "At most 30 seconds after generatedAt, shortened for an approaching queued-message expiry or creation-cohort boundary. Refresh after expiry."
          },
          "unit": {
            "const": "messages"
          },
          "source": {
            "const": "server_message_status"
          },
          "scope": {
            "type": "string",
            "enum": [
              "workspace",
              "device"
            ]
          },
          "current": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "queued",
              "processing",
              "unknownUnresolved"
            ],
            "properties": {
              "queued": {
                "type": "integer",
                "minimum": 0,
                "description": "Ordinary messages currently Queued with expires_at later than generatedAt. Excludes elapsed queued rows without mutating them."
              },
              "processing": {
                "type": "integer",
                "minimum": 0,
                "description": "Current submitting, Pending or Processed messages, regardless of creation time."
              },
              "unknownUnresolved": {
                "type": "integer",
                "minimum": 0,
                "description": "Current unknown messages with no recorded resolution, regardless of creation time. Not part of the Failed/rejected cohort count."
              }
            }
          },
          "last24h": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "basis",
              "from",
              "to",
              "created",
              "sent",
              "delivered",
              "failed",
              "rejected",
              "expired",
              "cancelled"
            ],
            "properties": {
              "basis": {
                "const": "created_at"
              },
              "from": {
                "type": "string",
                "format": "date-time"
              },
              "to": {
                "type": "string",
                "format": "date-time"
              },
              "created": {
                "type": "integer",
                "minimum": 0,
                "description": "Ordinary messages created in the inclusive [from,to] window. Other counters are selected current outcomes, not a partition of this total."
              },
              "sent": {
                "type": "integer",
                "minimum": 0,
                "description": "Current Sent or Delivered state within the creation cohort. Includes delivered; not an event count from sent_at."
              },
              "delivered": {
                "type": "integer",
                "minimum": 0,
                "description": "Current Delivered state within the creation cohort; a subset of sent, not a delivery percentage."
              },
              "failed": {
                "type": "integer",
                "minimum": 0
              },
              "rejected": {
                "type": "integer",
                "minimum": 0
              },
              "expired": {
                "type": "integer",
                "minimum": 0,
                "description": "Current expired state or Queued with elapsed TTL in the creation cohort."
              },
              "cancelled": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "queue": {
            "type": "object",
            "additionalProperties": false,
            "description": "Optional queue evidence for the same authorized scope and ordinary-message exclusions as current. Valid only while the snapshot is fresh. These timestamps are not a promised send time.",
            "required": [
              "oldestCreatedAt",
              "nextExpiryAt"
            ],
            "properties": {
              "oldestCreatedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "Creation time of the oldest unexpired ordinary queued SMS. Null if none or no valid creation timestamp."
              },
              "nextExpiryAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "Earliest original expiry among the queued SMS. Does not extend the message deadline."
              },
              "scheduled": {
                "type": "integer",
                "minimum": 0,
                "description": "Current queued messages with sendAt in the future; included in current.queued, not additional messages. Snapshot freshness ends at the next scheduled instant."
              }
            }
          },
          "estimatedSegments": {
            "type": "object",
            "description": "Stored segment estimates over exactly the same business-message scope and creation cohort. Separate from message counts, actual modem segment reports and carrier billing. Sent includes Delivered.",
            "required": [
              "unit",
              "basis",
              "current",
              "last24h"
            ],
            "properties": {
              "unit": {
                "const": "sms_segments"
              },
              "basis": {
                "const": "stored_estimate"
              },
              "current": {
                "type": "object",
                "properties": {
                  "queued": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "processing": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "unknownUnresolved": {
                    "type": "integer",
                    "minimum": 0
                  }
                }
              },
              "last24h": {
                "type": "object",
                "properties": {
                  "created": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "sent": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "delivered": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "failed": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "rejected": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "expired": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "cancelled": {
                    "type": "integer",
                    "minimum": 0
                  }
                }
              }
            }
          },
          "incoming": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "received",
              "from",
              "to",
              "basis"
            ],
            "properties": {
              "received": {
                "type": "integer",
                "minimum": 0
              },
              "from": {
                "type": "string",
                "format": "date-time"
              },
              "to": {
                "type": "string",
                "format": "date-time"
              },
              "basis": {
                "type": "string",
                "const": "stored_at"
              }
            },
            "description": "Optional mobile-only count of incoming receipts for this exact account and device, stored by the server in the inclusive rolling 24-hour window. Independent of outgoing last24h creation cohort and phone receivedAt. Retries do not add receipts; redacted receipts still count. Absence on an older server means unavailable, not zero. validUntil also reflects receipt-window boundaries."
          },
          "history": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "basis",
              "from",
              "to",
              "created",
              "sent",
              "delivered",
              "failed",
              "rejected",
              "expired",
              "cancelled",
              "period"
            ],
            "properties": {
              "basis": {
                "const": "created_at"
              },
              "from": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "to": {
                "type": "string",
                "format": "date-time"
              },
              "created": {
                "type": "integer",
                "minimum": 0,
                "description": "Ordinary messages created in the inclusive [from,to] window. Other counters are selected current outcomes, not a partition of this total."
              },
              "sent": {
                "type": "integer",
                "minimum": 0,
                "description": "Current Sent or Delivered state within the creation cohort. Includes delivered; not an event count from sent_at."
              },
              "delivered": {
                "type": "integer",
                "minimum": 0,
                "description": "Current Delivered state within the creation cohort; a subset of sent, not a delivery percentage."
              },
              "failed": {
                "type": "integer",
                "minimum": 0
              },
              "rejected": {
                "type": "integer",
                "minimum": 0
              },
              "expired": {
                "type": "integer",
                "minimum": 0,
                "description": "Current expired state or Queued with elapsed TTL in the creation cohort."
              },
              "cancelled": {
                "type": "integer",
                "minimum": 0
              },
              "period": {
                "type": "string",
                "enum": [
                  "1h",
                  "24h",
                  "7d",
                  "30d",
                  "all",
                  "custom"
                ]
              },
              "timeZone": {
                "type": "string",
                "enum": [
                  "UTC"
                ]
              }
            },
            "description": "Selected web creation cohort. from is null for all time; custom UTC calendar dates include both endpoint days, with to capped at generatedAt. Current and legacy last24h metrics remain independent."
          }
        }
      },
      "DeviceSending": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version",
          "source",
          "status",
          "reason",
          "collectedAt",
          "validUntil",
          "workerEnabled",
          "queued",
          "unknownUnresolved",
          "automaticQueue",
          "routing",
          "routes"
        ],
        "properties": {
          "version": {
            "const": 1
          },
          "source": {
            "const": "server_sending_status"
          },
          "status": {
            "enum": [
              "available",
              "unavailable"
            ]
          },
          "reason": {
            "enum": [
              null,
              "gateway_unavailable",
              "details_required",
              "device_unavailable",
              "invalid_runtime"
            ]
          },
          "collectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "validUntil": {
            "type": "string",
            "format": "date-time"
          },
          "workerEnabled": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether background processing is enabled in server configuration. When present, workerAvailable separately reports a recent connected worker heartbeat."
          },
          "queued": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "unknownUnresolved": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "automaticQueue": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "properties": {
              "queued": {
                "type": "integer",
                "minimum": 0
              },
              "reason": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "blockedByLimit": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "nextAttemptAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            },
            "required": [
              "queued",
              "reason",
              "blockedByLimit",
              "nextAttemptAt"
            ]
          },
          "routing": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "fixed",
                  "failover",
                  "round_robin"
                ]
              },
              "allowedSimNumbers": {
                "type": "array",
                "items": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                }
              },
              "preferredSimNumber": {
                "type": "integer",
                "minimum": 1,
                "maximum": 8
              },
              "stickyRecipient": {
                "type": "boolean"
              }
            },
            "required": [
              "mode",
              "allowedSimNumbers",
              "preferredSimNumber",
              "stickyRecipient"
            ]
          },
          "routes": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "availability": {
                  "type": "string",
                  "enum": [
                    "ready",
                    "stale",
                    "unknown",
                    "missing",
                    "changed",
                    "unavailable"
                  ]
                },
                "selected": {
                  "type": "boolean"
                },
                "queued": {
                  "type": "integer",
                  "minimum": 0
                },
                "reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "blockedByLimit": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "nextAttemptAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "eligibilityReason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "eligibleNow": {
                  "type": "boolean"
                },
                "eligibleAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "eligibilityLimit": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "lastSentAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                }
              },
              "required": [
                "simNumber",
                "availability",
                "selected",
                "queued",
                "reason",
                "blockedByLimit",
                "nextAttemptAt",
                "eligibilityReason",
                "eligibleNow",
                "eligibleAt",
                "eligibilityLimit",
                "lastSentAt"
              ]
            }
          },
          "workerAvailable": {
            "type": "boolean",
            "description": "Optional on the distributed runtime. True only while a worker has a fresh connected RabbitMQ heartbeat; absence retains the legacy runtime contract."
          },
          "workers": {
            "type": "object",
            "properties": {
              "lastSeenAt": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              },
              "validUntil": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              }
            },
            "required": [
              "lastSeenAt",
              "validUntil"
            ],
            "description": "Worker heartbeat freshness; not proof of SMS submission or delivery."
          }
        },
        "description": "Read-only, bounded projection of the canonical mobile sending snapshot. Operational queued and unresolved unknown counts include verification and private control jobs; ordinary business counts remain in MessageMetrics. No message IDs, bodies, recipient/sender numbers, SIM identity tags or document evidence. eligibleNow is current capacity for eligibilityReason, never a modem dispatch/delivery guarantee. lastSentAt is historical server evidence. Valid until at most 30 seconds after collection, shortened by observed queue TTL, capacity deadline, review expiry and diagnostic freshness. Clients must reject expired/invalid data and must not infer phone connectivity from this snapshot. Work bounds: at most 20 evaluated devices, 50 stored Queued jobs/device, 1000 reservations in the last 32 days/device, 1000 unresolved unknowns/device, and a shared request work budget. Larger workloads return unavailable/details_required; the complete device list and existing details endpoint remain available.",
        "allOf": [
          {
            "if": {
              "properties": {
                "status": {
                  "const": "unavailable"
                }
              }
            },
            "then": {
              "properties": {
                "workerEnabled": {
                  "type": "null",
                  "description": "Whether background processing is enabled in server configuration. When present, workerAvailable separately reports a recent connected worker heartbeat."
                },
                "queued": {
                  "type": "null"
                },
                "unknownUnresolved": {
                  "type": "null"
                },
                "automaticQueue": {
                  "type": "null"
                },
                "routing": {
                  "type": "null"
                },
                "routes": {
                  "maxItems": 0
                },
                "workerAvailable": {
                  "type": "boolean",
                  "description": "Optional on the distributed runtime. True only while a worker has a fresh connected RabbitMQ heartbeat; absence retains the legacy runtime contract."
                },
                "workers": {
                  "type": "object",
                  "properties": {
                    "lastSeenAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "validUntil": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    }
                  },
                  "required": [
                    "lastSeenAt",
                    "validUntil"
                  ],
                  "description": "Worker heartbeat freshness; not proof of SMS submission or delivery."
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "status": {
                  "const": "available"
                }
              }
            },
            "then": {
              "properties": {
                "reason": {
                  "type": "null"
                },
                "workerEnabled": {
                  "type": "boolean",
                  "description": "Whether background processing is enabled in server configuration. When present, workerAvailable separately reports a recent connected worker heartbeat."
                },
                "queued": {
                  "type": "integer"
                },
                "unknownUnresolved": {
                  "type": "integer"
                },
                "automaticQueue": {
                  "type": "object"
                },
                "routing": {
                  "type": "object"
                },
                "workerAvailable": {
                  "type": "boolean",
                  "description": "Optional on the distributed runtime. True only while a worker has a fresh connected RabbitMQ heartbeat; absence retains the legacy runtime contract."
                },
                "workers": {
                  "type": "object",
                  "properties": {
                    "lastSeenAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "validUntil": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    }
                  },
                  "required": [
                    "lastSeenAt",
                    "validUntil"
                  ],
                  "description": "Worker heartbeat freshness; not proof of SMS submission or delivery."
                }
              }
            }
          }
        ]
      },
      "Project": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "role": {
            "enum": [
              "owner",
              "operator",
              "viewer"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "paused": {
            "type": "boolean"
          },
          "archivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "accountId": {
            "type": "string",
            "description": "Isolated client account ID; same physical tenant boundary as id."
          },
          "platformId": {
            "type": "string",
            "description": "Parent platform project ID."
          },
          "platformName": {
            "type": "string"
          },
          "platformPaused": {
            "type": "boolean",
            "description": "Inherited parent sending hold; does not overwrite account paused."
          },
          "platformArchivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Inherited parent archive, separate from account archivedAt."
          },
          "workspaceName": {
            "type": [
              "string",
              "null"
            ],
            "description": "Name of the workspace that owns this project or account."
          },
          "workspaceEmail": {
            "type": [
              "string",
              "null"
            ],
            "description": "Workspace owner contact email. Returned to administrators only."
          },
          "externalAccountId": {
            "type": "string",
            "description": "The account's externalId inside its parent platform project. Returned to owners only; retry setup with POST /api/platforms/{platformId}/accounts and this ID."
          },
          "review": {
            "$ref": "#/components/schemas/RiskReview",
            "description": "Present only while SendHarbor holds this account's sending for review (status open or kept); see GET /api/risk-review."
          }
        },
        "required": [
          "id",
          "workspaceId",
          "name",
          "status",
          "role"
        ],
        "additionalProperties": false
      },
      "ProjectInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          }
        },
        "required": [
          "name",
          "externalId"
        ],
        "additionalProperties": false
      },
      "PoolInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "deviceIds": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "maxItems": 50,
            "uniqueItems": true
          },
          "enabled": {
            "type": "boolean",
            "default": true
          },
          "stickyRecipient": {
            "type": "boolean",
            "default": true
          }
        },
        "required": [
          "name",
          "deviceIds"
        ],
        "additionalProperties": false
      },
      "Pool": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "stickyRecipient": {
            "type": "boolean"
          },
          "queued": {
            "type": "integer"
          },
          "devices": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "InvitationInput": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "projectId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "role": {
            "enum": [
              "owner",
              "operator",
              "viewer"
            ]
          }
        },
        "required": [
          "email",
          "name"
        ],
        "additionalProperties": false
      },
      "InvitationAccept": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          },
          "password": {
            "type": "string",
            "minLength": 12,
            "maxLength": 256
          },
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "preview": {
            "const": true,
            "description": "Send only token and preview:true to check the link without accepting it. Returns 200 {invitation:{email,role,projectName,workspaceName,existingAccount,expiresAt}} or 410."
          }
        },
        "required": [
          "token"
        ],
        "additionalProperties": false
      },
      "PortalAccessInput": {
        "type": "object",
        "properties": {
          "externalUserId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "projectId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          }
        },
        "required": [
          "externalUserId",
          "email"
        ],
        "additionalProperties": false
      },
      "AccountEmailRequest": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "language": {
            "type": "string",
            "enum": [
              "en",
              "ru"
            ],
            "description": "Email language. If omitted, negotiated from Accept-Language, with English as fallback."
          }
        },
        "required": [
          "email",
          "name"
        ],
        "additionalProperties": false
      },
      "AccountAccessComplete": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          },
          "password": {
            "type": "string",
            "format": "password",
            "minLength": 12,
            "maxLength": 256
          },
          "code": {
            "type": "string",
            "maxLength": 64
          }
        },
        "required": [
          "token",
          "password"
        ],
        "additionalProperties": false
      },
      "AccountAccessCheck": {
        "type": "object",
        "description": "Checks an opened email link without using it: 204 while it still works, 410 when it expired, was replaced or was already used.",
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          },
          "check": {
            "type": "boolean",
            "const": true
          }
        },
        "required": [
          "token",
          "check"
        ],
        "additionalProperties": false
      },
      "RoutePreview": {
        "type": "object",
        "properties": {
          "projectId": {
            "type": "string"
          },
          "poolId": {
            "type": "string"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "validUntil": {
            "type": "string",
            "format": "date-time"
          },
          "mode": {
            "const": "read_only"
          },
          "messageCreated": {
            "const": false
          },
          "capacityReserved": {
            "const": false
          },
          "stickyRecipient": {
            "type": "boolean"
          },
          "segments": {
            "type": "integer"
          },
          "encoding": {
            "type": "string"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "routes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "deviceId": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "simNumber": {
                  "type": "integer"
                },
                "eligible": {
                  "type": "boolean"
                },
                "reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "nextAttemptAt": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "reservedSegmentsLastHour": {
                  "type": "integer"
                }
              },
              "required": [
                "deviceId",
                "simNumber",
                "eligible",
                "reason"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "poolId",
          "mode",
          "messageCreated",
          "capacityReserved",
          "routes"
        ],
        "additionalProperties": false
      },
      "RouterStatus": {
        "type": "object",
        "properties": {
          "projectId": {
            "type": "string"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "validUntil": {
            "type": "string",
            "format": "date-time"
          },
          "project": {
            "type": "object"
          },
          "metrics": {
            "type": "object"
          },
          "devices": {
            "type": "object"
          },
          "queue": {
            "type": "object"
          },
          "webhooks": {
            "type": "object"
          },
          "usage": {
            "type": "object",
            "description": "Calendar month UTC, cohort by created_at. Counts admitted ordinary messages and segments, not a carrier bill."
          },
          "latency": {
            "type": "object",
            "description": "24h creation cohort with known sent_at; missing timestamps excluded, zero samples means null latency."
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "projectId",
          "generatedAt",
          "validUntil",
          "queue",
          "webhooks",
          "usage",
          "issues"
        ]
      },
      "PlatformInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "externalId": {
            "type": "string",
            "maxLength": 128
          },
          "kind": {
            "type": "string",
            "enum": [
              "platform",
              "standalone"
            ],
            "default": "platform"
          }
        },
        "required": [
          "name",
          "externalId"
        ],
        "additionalProperties": false
      },
      "PlatformSettings": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "paused": {
            "type": "boolean"
          },
          "archived": {
            "type": "boolean"
          },
          "channels": {
            "$ref": "#/components/schemas/IntegrationChannels"
          }
        },
        "required": [],
        "additionalProperties": false
      },
      "PlatformAccountInput": {
        "type": "object",
        "properties": {
          "externalId": {
            "type": "string",
            "maxLength": 128
          },
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "email": {
            "type": "string",
            "format": "email"
          }
        },
        "required": [
          "externalId",
          "name",
          "email"
        ],
        "additionalProperties": false
      },
      "PlatformKeyInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "scopes": {
            "type": "array",
            "uniqueItems": true,
            "minItems": 1,
            "items": {
              "type": "string",
              "enum": [
                "accounts:read",
                "accounts:write",
                "devices:read",
                "devices:write",
                "messages:read",
                "messages:send",
                "integrations:write",
                "usage:read"
              ]
            }
          }
        },
        "required": [
          "name",
          "scopes"
        ],
        "additionalProperties": false
      },
      "PlatformWebhookInput": {
        "type": "object",
        "properties": {
          "endpoint": {
            "type": "string",
            "format": "uri",
            "maxLength": 2000
          },
          "enabled": {
            "type": "boolean"
          }
        },
        "required": [
          "endpoint",
          "enabled"
        ],
        "additionalProperties": false
      },
      "IntegrationChannels": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "httpApi",
          "webhookCommands",
          "webhookEvents",
          "websocket"
        ],
        "properties": {
          "httpApi": {
            "type": "boolean",
            "default": true
          },
          "webhookCommands": {
            "type": "boolean",
            "default": true
          },
          "webhookEvents": {
            "type": "boolean",
            "default": true
          },
          "websocket": {
            "type": "boolean",
            "default": false
          }
        },
        "description": "Select integration command ingress independently of event delivery. At least one command channel must stay enabled. HTTP control-plane setup, QR and reads remain available. Accepted work retains its original TTL."
      },
      "NamedBatchItem": {
        "type": "object",
        "required": [
          "phone",
          "text"
        ],
        "properties": {
          "deviceId": {
            "type": "string"
          },
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000,
            "description": "The exact SMS text is stored without trimming. At most 5000 UTF-16 code units; text that is empty or only whitespace is rejected."
          },
          "idempotencyKey": {
            "type": "string",
            "minLength": 8,
            "maxLength": 128,
            "description": "One key per intent to send. A repeat with the same content returns the same message. Changed content returns 409. An unknown outcome is never retried automatically. The us-control: prefix is reserved for internal, payload-bound replies and is rejected for public message admission."
          },
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8,
            "description": "1-based SIM slot. Explicit slot never automatically falls back. If omitted: fixed mode pins the preferred SIM at admission; automatic mode selects an eligible SIM at hand-off. Android 5.0 supports only SIM1/system default. The default US profile requires API 22+ accepted SIM identity; API 21 cannot qualify for that profile."
          },
          "ttlSeconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 604800,
            "description": "How long the message may wait before sending. Defaults to the policy value (86400). With sendAt, TTL starts at max(server admission, sendAt); expiresAt remains an earlier hard deadline and must be after sendAt."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "description": "Absolute ISO 8601 deadline with timezone, fixed at business-event creation. Effective expiry is the earlier of expiresAt and TTL; expired input remains idempotently expired and is never dispatched."
          },
          "priority": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2,
            "default": 0,
            "description": "0 normal, 1 high, 2 urgent. Only undispatched messages are reordered. Same recipient on the same route remains FIFO; explicit different SIM routes remain independent. Waiting increases effective priority every 10 minutes, preventing normal traffic starvation. Priority does not bypass quotas, quiet hours, STOP, sender affinity or expiry. Changing priority on a nonzero-priority idempotent request conflicts; omitted and 0 preserve the legacy hash. An unassigned automatic request preserves recipient order with every earlier explicit/automatic request; a later explicit request cannot jump across it."
          },
          "purpose": {
            "$ref": "#/components/schemas/MessagePurpose"
          },
          "poolId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "replaceKey": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
            "description": "Account-scoped business notification key. Requires replaceVersion. Only the previous queued, undispatched SMS can be superseded."
          },
          "replaceVersion": {
            "type": "integer",
            "minimum": 1,
            "maximum": 2147483647,
            "description": "Strictly increasing business revision. Old/equal versions reject with 409; exact idempotency replays return their original (possibly superseded) message."
          },
          "sendAt": {
            "type": "string",
            "format": "date-time",
            "description": "Send no earlier than this absolute ISO 8601 instant with timezone. At most 30 days after server admission. Past times are immediately due. Durable server-side scheduling; future jobs do not block due conversations or reserve SIM capacity. TTL starts at max(admission time, sendAt). All limits, STOP, consent, carrier permission and quiet-hour checks run again at dispatch. This is not a delivery-time guarantee."
          },
          "maxSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "Optional safety cap on estimated SMS parts per message. A larger payload is rejected before admission (message_segment_limit); a batch is atomic. No silent truncation, transliteration or rewriting. Omitted preserves legacy behavior; the web composer pins the reviewed estimate by default. Not a carrier bill or delivery guarantee. Changing the cap on an idempotent retry conflicts."
          }
        },
        "oneOf": [
          {
            "required": [
              "deviceId"
            ],
            "not": {
              "required": [
                "poolId"
              ]
            }
          },
          {
            "required": [
              "poolId"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "deviceId"
                  ]
                },
                {
                  "required": [
                    "simNumber"
                  ]
                }
              ]
            }
          }
        ],
        "description": "Choose deviceId or poolId. An empty/unavailable pool retains the job until TTL. externalId is unique within this project; retries use the same idempotencyKey. Pool routing never repeats an already dispatched or unknown attempt on another device. replaceKey and replaceVersion must be supplied together. Unknown/submitted/sent outcomes cannot be replaced; changing recipient/sender never permits a second attempt of an uncertain SMS.",
        "additionalProperties": false
      },
      "NamedBatchInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "batchId",
          "items"
        ],
        "properties": {
          "batchId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/NamedBatchItem"
            }
          }
        },
        "description": "Stable account-scoped batchId. Missing item idempotencyKey is derived from batchId and position. The same batchId/body returns the same batch; a changed body returns409. Admission is atomic; dispatch and delivery are per item. JSON request <=256KiB. Per-item requireValidation is not accepted in named batches; use signed sms.send for that validation workflow."
      },
      "MessageBatch": {
        "type": "object",
        "required": [
          "id",
          "externalId",
          "accountId",
          "total",
          "state",
          "counts",
          "deliveryConfirmed"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "externalId": {
            "type": "string"
          },
          "accountId": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "total": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "state": {
            "type": "string",
            "enum": [
              "in_progress",
              "needs_review",
              "completed",
              "completed_with_issues"
            ]
          },
          "deliveryConfirmed": {
            "type": "boolean"
          },
          "counts": {
            "type": "object",
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            }
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          }
        }
      },
      "SmsBatchCommand": {
        "type": "object",
        "required": [
          "version",
          "id",
          "type",
          "createdAt",
          "data"
        ],
        "properties": {
          "version": {
            "const": 1
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "const": "sms.batch"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "projectId": {
            "type": "string"
          },
          "accountId": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "required": [
              "batchId",
              "items"
            ],
            "additionalProperties": false,
            "properties": {
              "batchId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
              },
              "items": {
                "type": "array",
                "minItems": 1,
                "maxItems": 100,
                "items": {
                  "$ref": "#/components/schemas/NamedBatchItem"
                }
              },
              "projectId": {
                "type": "string"
              },
              "accountId": {
                "type": "string"
              }
            }
          }
        }
      },
      "RealtimeCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "type"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "type": {
            "enum": [
              "subscribe",
              "ping",
              "message.send",
              "message.get",
              "message.cancel",
              "batch.send",
              "batch.get"
            ]
          },
          "after": {
            "type": "integer",
            "minimum": 0
          },
          "body": {
            "type": "object"
          }
        },
        "description": "WebSocket send JSON <=256KiB, one in-flight command/connection. request id correlates results but is not an SMS idempotency key. message.send requires persistent body.idempotencyKey; batch.send requires NamedBatchInput. Writes require messages:send. The ticket account cannot be changed by frames."
      },
      "RealtimeTicket": {
        "type": "object",
        "properties": {
          "ticket": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "protocols": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "singleUse": {
            "const": true
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SandboxMessageInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phone",
          "text",
          "idempotencyKey"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000
          },
          "idempotencyKey": {
            "type": "string",
            "minLength": 8,
            "maxLength": 128
          },
          "deviceId": {
            "const": "sandbox-phone"
          },
          "scenario": {
            "type": "string",
            "enum": [
              "delivered",
              "failed",
              "offline",
              "limit",
              "unknown"
            ],
            "default": "delivered"
          },
          "simNumber": {
            "type": "integer",
            "enum": [
              1,
              2
            ],
            "default": 1
          },
          "emitWebhook": {
            "type": "boolean",
            "default": false
          },
          "maxSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "Optional safety cap on estimated SMS parts per message. A larger payload is rejected before admission (message_segment_limit); a batch is atomic. No silent truncation, transliteration or rewriting. Omitted preserves legacy behavior; the web composer pins the reviewed estimate by default. Not a carrier bill or delivery guarantee. Changing the cap on an idempotent retry conflicts."
          },
          "sendAt": {
            "type": "string",
            "format": "date-time",
            "description": "Absolute ISO 8601 not-before time with timezone, within 30 days of server admission. A future job stays queued with one scheduled event until the sandbox worker runs it. Past time runs immediately. Does not contact a handset. Replays keep the original schedule; changed time conflicts."
          }
        }
      },
      "OnboardingInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "idempotencyKey"
        ],
        "properties": {
          "idempotencyKey": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{1,128}$"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "principalId": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{1,128}$"
          },
          "ttlSeconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 3600,
            "default": 1200
          },
          "allowedOrigin": {
            "type": "string",
            "format": "uri",
            "description": "One exact HTTPS embedding origin, no path/query/credentials. Loopback HTTP allowed for development."
          },
          "webhook": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "endpoint",
              "secret"
            ],
            "properties": {
              "endpoint": {
                "type": "string",
                "format": "uri"
              },
              "secret": {
                "type": "string",
                "minLength": 43,
                "maxLength": 128
              }
            }
          }
        }
      },
      "SandboxBatchItem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phone",
          "text"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000
          },
          "idempotencyKey": {
            "type": "string",
            "minLength": 8,
            "maxLength": 128
          },
          "deviceId": {
            "const": "sandbox-phone"
          },
          "scenario": {
            "type": "string",
            "enum": [
              "delivered",
              "failed",
              "offline",
              "limit",
              "unknown"
            ],
            "default": "delivered"
          },
          "simNumber": {
            "type": "integer",
            "enum": [
              1,
              2
            ],
            "default": 1
          },
          "emitWebhook": {
            "type": "boolean",
            "default": false
          },
          "maxSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "Optional safety cap on estimated SMS parts per message. A larger payload is rejected before admission (message_segment_limit); a batch is atomic. No silent truncation, transliteration or rewriting. Omitted preserves legacy behavior; the web composer pins the reviewed estimate by default. Not a carrier bill or delivery guarantee. Changing the cap on an idempotent retry conflicts."
          },
          "sendAt": {
            "type": "string",
            "format": "date-time",
            "description": "Absolute ISO 8601 not-before time with timezone, within 30 days of server admission. A future job stays queued with one scheduled event until the sandbox worker runs it. Past time runs immediately. Does not contact a handset. Replays keep the original schedule; changed time conflicts."
          }
        }
      },
      "SandboxIncomingInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phone",
          "text",
          "idempotencyKey"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000
          },
          "idempotencyKey": {
            "type": "string",
            "minLength": 8,
            "maxLength": 128
          },
          "simNumber": {
            "type": "integer",
            "enum": [
              1,
              2
            ],
            "default": 1
          },
          "emitWebhook": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "OnboardingStatus": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sessionId",
          "expiresAt",
          "allowedOrigin",
          "stage",
          "pairing",
          "device",
          "checks",
          "diagnosticsFresh",
          "sims",
          "ready",
          "cellularAttempted"
        ],
        "properties": {
          "sessionId": {
            "type": "string",
            "format": "uuid"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "allowedOrigin": {
            "type": [
              "string",
              "null"
            ]
          },
          "stage": {
            "type": "string",
            "enum": [
              "agreement",
              "connect",
              "connecting",
              "checks",
              "sims",
              "ready"
            ]
          },
          "pairing": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "status",
              "qrDataUrl"
            ],
            "properties": {
              "status": {
                "type": "string"
              },
              "qrDataUrl": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "device": {
            "type": [
              "object",
              "null"
            ],
            "description": "Only the one bound phone: id, name, lastSeen, online; no account-wide list."
          },
          "checks": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "diagnosticsFresh": {
            "type": "boolean"
          },
          "sims": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "ready": {
                  "type": "boolean"
                },
                "steps": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              }
            }
          },
          "ready": {
            "type": "boolean"
          },
          "cellularAttempted": {
            "const": false
          },
          "legal": {
            "$ref": "#/components/schemas/SenderTermsStatus"
          }
        },
        "description": "Pending agreements return stage agreement. An unexpired setup session can expose a QR for acceptance in the native Android app, with legal.acceptInApp and the current acceptance mode. The required contracting owner or individual customer accepts through its own restricted proof flow; a QR or API flag never acts as a signature. Company coverage does not fabricate customer receipts. The original session continues after acceptance."
      },
      "SandboxEvent": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "version",
          "type",
          "createdAt",
          "sandbox",
          "accountId",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "const": 1
          },
          "type": {
            "enum": [
              "sandbox.message.status",
              "sandbox.sms.received"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "sandbox": {
            "const": true
          },
          "accountId": {
            "type": "string"
          },
          "projectId": {
            "type": "string"
          },
          "externalAccountId": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "additionalProperties": true,
            "required": [
              "sandbox",
              "accountId",
              "messageId"
            ],
            "properties": {
              "sandbox": {
                "const": true
              },
              "accountId": {
                "type": "string"
              },
              "messageId": {
                "type": "string"
              },
              "deviceId": {
                "const": "sandbox-phone"
              },
              "simNumber": {
                "enum": [
                  1,
                  2
                ]
              },
              "status": {
                "type": "object",
                "properties": {
                  "phase": {
                    "enum": [
                      "queued",
                      "submitted",
                      "sent",
                      "delivered",
                      "failed",
                      "unknown"
                    ]
                  },
                  "sequence": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        }
      },
      "SmsPreflightInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "text"
        ],
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000,
            "description": "The exact SMS text is stored without trimming. At most 5000 UTF-16 code units; text that is empty or only whitespace is rejected."
          },
          "maxSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "Optional safety cap on estimated SMS parts per message. A larger payload is rejected before admission (message_segment_limit); a batch is atomic. No silent truncation, transliteration or rewriting. Omitted preserves legacy behavior; the web composer pins the reviewed estimate by default. Not a carrier bill or delivery guarantee. Changing the cap on an idempotent retry conflicts."
          }
        }
      },
      "SmsPreflight": {
        "type": "object",
        "required": [
          "encoding",
          "segments",
          "units",
          "characters",
          "withinLimit",
          "unicodeCharacters",
          "warnings",
          "suggestion",
          "messageCreated",
          "capacityReserved"
        ],
        "properties": {
          "encoding": {
            "enum": [
              "GSM-7",
              "UCS-2"
            ]
          },
          "segments": {
            "type": "integer",
            "minimum": 1
          },
          "units": {
            "type": "integer",
            "minimum": 1
          },
          "characters": {
            "type": "integer",
            "minimum": 1
          },
          "withinLimit": {
            "type": "boolean"
          },
          "unicodeCharacters": {
            "type": "array",
            "maxItems": 8,
            "description": "First eight distinct non-GSM characters; no text is stored by this endpoint.",
            "items": {
              "type": "object",
              "required": [
                "character",
                "codePoint"
              ],
              "properties": {
                "character": {
                  "type": "string"
                },
                "codePoint": {
                  "type": "string"
                }
              },
              "additionalProperties": false
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "enum": [
                "unicode_encoding",
                "multipart"
              ]
            }
          },
          "suggestion": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "required": [
                  "text",
                  "encoding",
                  "segments",
                  "units"
                ],
                "properties": {
                  "text": {
                    "type": "string"
                  },
                  "encoding": {
                    "enum": [
                      "GSM-7",
                      "UCS-2"
                    ]
                  },
                  "segments": {
                    "type": "integer"
                  },
                  "units": {
                    "type": "integer"
                  }
                },
                "description": "Optional plain punctuation candidate, only when it saves parts. Never automatically applied."
              }
            ]
          },
          "messageCreated": {
            "const": false
          },
          "capacityReserved": {
            "const": false
          },
          "text": {
            "type": "string",
            "description": "Only for a templateId request: the final SMS text after substitution, which is what was analysed."
          }
        },
        "additionalProperties": false
      },
      "SandboxMessage": {
        "type": "object",
        "required": [
          "id",
          "accountId",
          "sandbox",
          "state",
          "virtualDevice",
          "cellularAttempted"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "accountId": {
            "type": "string"
          },
          "sandbox": {
            "const": true
          },
          "state": {
            "enum": [
              "queued",
              "delivered",
              "failed",
              "unknown",
              "received",
              "cancelled"
            ]
          },
          "virtualDevice": {
            "const": true
          },
          "cellularAttempted": {
            "const": false
          },
          "phone": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "simNumber": {
            "type": "integer"
          },
          "sendAt": {
            "type": "string",
            "format": "date-time"
          },
          "schedulePending": {
            "type": "boolean",
            "description": "True until the not-before gate has been processed; false after release or cancellation."
          },
          "nextAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "queueReason": {
            "type": [
              "string",
              "null"
            ],
            "description": "For any queued test: simulated minute_limit/device_offline, scheduled until release, or an active project/account hold. Null for terminal outcomes. sandbox_webhook_unavailable may prevent scheduled processing."
          },
          "status": {
            "type": "object",
            "properties": {
              "phase": {
                "type": "string"
              },
              "sequence": {
                "type": "integer",
                "minimum": 1
              }
            }
          }
        },
        "description": "Sandbox only. Scheduled transitions and status sequences are durable and atomic with the callback outbox. No real message/usage/reservation records are created."
      },
      "SandboxMessageResult": {
        "type": "object",
        "required": [
          "sandbox",
          "message"
        ],
        "properties": {
          "sandbox": {
            "const": true
          },
          "message": {
            "$ref": "#/components/schemas/SandboxMessage"
          }
        }
      },
      "SenderTermsInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "version": {
            "type": "string"
          },
          "language": {
            "enum": [
              "en",
              "ru"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "accepted": {
            "const": true
          },
          "authority": {
            "const": true
          },
          "clientResponsibility": {
            "const": true
          },
          "customerName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160,
            "description": "Business legal name required for business. For individual, omit or repeat signatoryName; normalized to full name."
          },
          "signatoryName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160
          },
          "projectAuthorization": {
            "const": true
          },
          "partyType": {
            "enum": [
              "individual",
              "business"
            ],
            "description": "Declared personal capacity or authorized company/sole proprietor. Actual statutory consumer status depends on law and use."
          }
        },
        "required": [
          "version",
          "language",
          "sha256",
          "accepted",
          "authority",
          "clientResponsibility",
          "signatoryName",
          "projectAuthorization",
          "partyType"
        ],
        "description": "Explicit individual or authorized business representative assent and authorization of the server-selected project. Supplied account/project/actor IDs or acceptance timestamps are forbidden. The business/name/email declarations are not KYC. Individual acts for themselves; business representative must be authorized. One explicit unchecked human declaration may attest to the linked terms and these duties; sender declaration also expressly authorizes the named project. Not marketing consent, KYC or a waiver of mandatory consumer rights.",
        "allOf": [
          {
            "if": {
              "properties": {
                "partyType": {
                  "const": "business"
                }
              },
              "required": [
                "partyType"
              ]
            },
            "then": {
              "required": [
                "customerName"
              ]
            }
          }
        ]
      },
      "SenderTermsReceipt": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "accountId": {
            "type": "string"
          },
          "projectId": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "actorId": {
            "type": "string"
          },
          "actorEmail": {
            "type": "string"
          },
          "customerName": {
            "type": "string"
          },
          "signatoryName": {
            "type": "string"
          },
          "projectName": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "language": {
            "type": "string"
          },
          "sha256": {
            "type": "string"
          },
          "acceptedAt": {
            "type": "string",
            "format": "date-time"
          },
          "verifiedAt": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "type": "string"
          },
          "partyType": {
            "enum": [
              "individual",
              "business"
            ]
          }
        },
        "required": [
          "id",
          "accountId",
          "projectId",
          "version",
          "language",
          "sha256",
          "acceptedAt",
          "verifiedAt",
          "partyType"
        ],
        "description": "Immutable account/project-bound receipt. Restricted onboarding and API keys receive only id/accountId/projectId/version/language/sha256/partyType/acceptedAt/verifiedAt. Authorized owner/admin audit adds declared names, verified email and original project/account name snapshots. Verification proves mailbox control, not business authority."
      },
      "SenderTermsStatus": {
        "type": "object",
        "required": [
          "required",
          "kind",
          "version",
          "documents",
          "accountId",
          "projectId",
          "accepted",
          "mailAvailable"
        ],
        "properties": {
          "required": {
            "type": "boolean"
          },
          "kind": {
            "const": "sender"
          },
          "version": {
            "type": "string"
          },
          "documents": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "sha256",
                "url"
              ],
              "properties": {
                "sha256": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              }
            }
          },
          "preview": {
            "type": "boolean"
          },
          "accountId": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "projectId": {
            "type": "string"
          },
          "projectName": {
            "type": "string"
          },
          "accepted": {
            "type": "boolean"
          },
          "mailAvailable": {
            "type": "boolean"
          },
          "receipt": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/SenderTermsReceipt"
              },
              {
                "$ref": "#/components/schemas/CompanySenderReceipt"
              },
              {
                "type": "null"
              }
            ]
          },
          "history": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SenderTermsReceipt"
            },
            "description": "Only authorized full owner/admin account sessions; omitted for API keys, managed sessions and onboarding."
          },
          "acceptanceMode": {
            "enum": [
              "company",
              "customer"
            ]
          },
          "acceptanceSource": {
            "enum": [
              "company",
              "customer",
              null
            ]
          },
          "companyReceipt": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/CompanySenderReceipt"
              },
              {
                "type": "null"
              }
            ]
          },
          "policyRevision": {
            "type": "integer",
            "minimum": 0
          },
          "canAccept": {
            "type": "boolean"
          },
          "integratorAccepted": {
            "type": "boolean"
          },
          "acceptInApp": {
            "type": "boolean"
          },
          "ownerAcceptance": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "available": {
                "type": "boolean"
              },
              "required": {
                "type": "boolean"
              },
              "mfaRequired": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "SenderTermsChallenge": {
        "type": "object",
        "required": [
          "challengeId",
          "expiresAt",
          "maskedEmail",
          "delivery",
          "alreadyAccepted",
          "language",
          "version",
          "nextAttemptAt"
        ],
        "properties": {
          "challengeId": {
            "type": "string",
            "format": "uuid"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "maskedEmail": {
            "type": "string"
          },
          "delivery": {
            "enum": [
              "pending",
              "sending",
              "sent",
              "failed",
              "expired"
            ]
          },
          "alreadyAccepted": {
            "type": "boolean"
          },
          "language": {
            "enum": [
              "en",
              "ru"
            ]
          },
          "version": {
            "type": "string"
          },
          "nextAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Next scheduled mail attempt, not an inbox-delivery guarantee."
          }
        },
        "description": "No code is returned. One stable request ID/body reuses one challenge. Explicit resend/new ID supersedes previous pending proof in this session. Ten-minute lifetime and five code guesses. delivery=sent means the configured mail transport accepted the message, not that it reached the inbox. A status refresh returns the same challenge without sending another email."
      },
      "ServiceTermsInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version",
          "language",
          "sha256",
          "accepted",
          "authority",
          "clientResponsibility",
          "signatoryName",
          "partyType"
        ],
        "properties": {
          "version": {
            "type": "string"
          },
          "language": {
            "enum": [
              "en",
              "ru"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "accepted": {
            "const": true
          },
          "authority": {
            "const": true
          },
          "clientResponsibility": {
            "const": true
          },
          "customerName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160,
            "description": "Business legal name required for business. For individual, omit or repeat signatoryName; normalized to full name."
          },
          "signatoryName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160
          },
          "partyType": {
            "enum": [
              "individual",
              "business"
            ],
            "description": "Declared personal capacity or authorized company/sole proprietor. Actual statutory consumer status depends on law and use."
          },
          "senderAcceptanceMode": {
            "enum": [
              "company",
              "customer"
            ]
          },
          "senderPolicyRevision": {
            "type": "integer",
            "minimum": 0
          },
          "senderTerms": {
            "$ref": "#/components/schemas/SenderTermsInput"
          }
        },
        "description": "Optional mode chooses who accepts sender obligations. If supplied, senderPolicyRevision is required (0 for a new workspace). company also requires current senderTerms with the identical contracting identity. customer must omit senderTerms. Omission preserves existing policy for legacy clients.",
        "allOf": [
          {
            "if": {
              "properties": {
                "partyType": {
                  "const": "business"
                }
              },
              "required": [
                "partyType"
              ]
            },
            "then": {
              "required": [
                "customerName"
              ]
            }
          },
          {
            "if": {
              "required": [
                "senderAcceptanceMode"
              ]
            },
            "then": {
              "required": [
                "senderPolicyRevision"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "senderAcceptanceMode": {
                  "const": "company"
                }
              },
              "required": [
                "senderAcceptanceMode"
              ]
            },
            "then": {
              "required": [
                "senderTerms"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "senderAcceptanceMode": {
                  "const": "customer"
                }
              },
              "required": [
                "senderAcceptanceMode"
              ]
            },
            "then": {
              "not": {
                "required": [
                  "senderTerms"
                ]
              }
            }
          }
        ]
      },
      "ServiceTermsDescriptor": {
        "type": "object",
        "required": [
          "required",
          "version",
          "documents"
        ],
        "properties": {
          "required": {
            "type": "boolean"
          },
          "version": {
            "type": "string"
          },
          "preview": {
            "type": "boolean"
          },
          "documents": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "sha256",
                "url"
              ],
              "properties": {
                "sha256": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              }
            }
          },
          "workspaceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "accepted": {
            "type": "boolean"
          },
          "canAccept": {
            "type": "boolean"
          },
          "receipt": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ServiceTermsReceipt"
              },
              {
                "type": "null"
              }
            ]
          },
          "kind": {
            "enum": [
              "integrator",
              "sender"
            ]
          },
          "senderAcceptanceMode": {
            "enum": [
              "company",
              "customer"
            ]
          },
          "senderTerms": {
            "$ref": "#/components/schemas/ServiceTermsDescriptor"
          },
          "senderPolicy": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/SenderPolicy"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "ServiceTermsReceipt": {
        "type": "object",
        "required": [
          "id",
          "version",
          "language",
          "sha256",
          "acceptedAt",
          "partyType"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "actorId": {
            "type": "string"
          },
          "actorEmail": {
            "type": "string"
          },
          "actorName": {
            "type": "string"
          },
          "customerName": {
            "type": "string"
          },
          "signatoryName": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "language": {
            "type": "string"
          },
          "sha256": {
            "type": "string"
          },
          "acceptedAt": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "type": "string"
          },
          "authority": {
            "const": 1
          },
          "clientResponsibility": {
            "const": 1
          },
          "partyType": {
            "enum": [
              "individual",
              "business"
            ]
          }
        },
        "description": "Receipt fields in a session are minimized (id, version, language, sha256, acceptedAt, actorId, workspaceId). Owner audit/export adds identity snapshots and source. Admin scoped history adds customer/signer/email/source. Authority and clientResponsibility in owner history are stored integer attestations (1)."
      },
      "ServiceTermsAudit": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ServiceTermsDescriptor"
          },
          {
            "type": "object",
            "properties": {
              "history": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ServiceTermsReceipt"
                }
              },
              "companySenderHistory": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/CompanySenderReceipt"
                }
              },
              "senderPolicyHistory": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "ownerMobileEvidence": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/OwnerMobileEvidence"
                }
              }
            }
          }
        ]
      },
      "OutgoingHold": {
        "type": "object",
        "additionalProperties": false,
        "description": "Current ordinary outgoing work is delayed locally before modem hand-off. Informational: does not authorize sends, assert an unknown outcome, or block onboarding. Expedited messages may proceed. Timestamp is the latest applicable local gate; server rules and message TTL still apply.",
        "properties": {
          "reason": {
            "type": "string",
            "enum": [
              "phone_rate_limit",
              "phone_work_hours",
              "phone_interval"
            ]
          },
          "collectedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Must equal DiagnosticReport.collectedAt."
          },
          "nextEligibleAt": {
            "type": "string",
            "format": "date-time",
            "description": "Strictly after collectedAt, at most 366 days later. Earliest local eligibility, not a delivery promise."
          }
        },
        "required": [
          "reason",
          "collectedAt",
          "nextEligibleAt"
        ]
      },
      "MailHealth": {
        "type": "object",
        "description": "Administrator-only aggregate. pending excludes expired/used/superseded messages; failed covers unresolved failures created in the last 24 hours. Contains no email addresses, tokens or message contents. Transport acceptance is not proof of inbox delivery. Aggregate pending/failed totals include sender, owner-confirmation and accountAccess email queues.",
        "required": [
          "configured",
          "generatedAt",
          "periodHours",
          "sender",
          "accountAccess",
          "pending",
          "failed",
          "owner"
        ],
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "periodHours": {
            "const": 24
          },
          "sender": {
            "type": "object",
            "required": [
              "pending",
              "failed",
              "oldestPendingAt"
            ],
            "properties": {
              "pending": {
                "type": "integer",
                "minimum": 0
              },
              "failed": {
                "type": "integer",
                "minimum": 0
              },
              "oldestPendingAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "accountAccess": {
            "type": "object",
            "required": [
              "pending",
              "failed",
              "oldestPendingAt"
            ],
            "properties": {
              "pending": {
                "type": "integer",
                "minimum": 0
              },
              "failed": {
                "type": "integer",
                "minimum": 0
              },
              "oldestPendingAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "pending": {
            "type": "integer",
            "minimum": 0
          },
          "failed": {
            "type": "integer",
            "minimum": 0
          },
          "owner": {
            "type": "object",
            "required": [
              "pending",
              "failed",
              "oldestPendingAt"
            ],
            "properties": {
              "pending": {
                "type": "integer",
                "minimum": 0
              },
              "failed": {
                "type": "integer",
                "minimum": 0
              },
              "oldestPendingAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          }
        }
      },
      "LiveSimTestLimits": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "sim": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "minute": {
                "type": "integer",
                "const": 2
              },
              "hour": {
                "type": "integer",
                "const": 6
              },
              "day": {
                "type": "integer",
                "const": 12
              }
            },
            "required": [
              "minute",
              "hour",
              "day"
            ]
          },
          "project": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "minute": {
                "type": "integer",
                "const": 2
              },
              "hour": {
                "type": "integer",
                "const": 12
              },
              "day": {
                "type": "integer",
                "const": 24
              }
            },
            "required": [
              "minute",
              "hour",
              "day"
            ]
          },
          "maxSegments": {
            "type": "integer",
            "const": 2
          }
        },
        "required": [
          "sim",
          "project",
          "maxSegments"
        ],
        "description": "SMS segments in rolling windows. Includes the connection challenge. Budgets survive session renewal and phone restart; limits do not grant carrier approval."
      },
      "LiveSimTest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "status": {
            "type": "string",
            "enum": [
              "awaiting_reply",
              "ready",
              "expired",
              "revoked",
              "blocked"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "recipientVerifiedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "limits": {
            "$ref": "#/components/schemas/LiveSimTestLimits"
          },
          "remainingSegments": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "simHour": {
                "type": "integer",
                "minimum": 0,
                "maximum": 6
              },
              "simDay": {
                "type": "integer",
                "minimum": 0,
                "maximum": 12
              },
              "projectHour": {
                "type": "integer",
                "minimum": 0,
                "maximum": 12
              },
              "projectDay": {
                "type": "integer",
                "minimum": 0,
                "maximum": 24
              }
            },
            "required": [
              "simHour",
              "simDay",
              "projectHour",
              "projectDay"
            ]
          }
        },
        "required": [
          "id",
          "simNumber",
          "phone",
          "status",
          "reason",
          "createdAt",
          "expiresAt",
          "recipientVerifiedAt",
          "limits",
          "remainingSegments"
        ],
        "description": "One ordinary, user-initiated 60-minute test bound to this phone, current SIM identity/configuration and controlled recipient. ready requires an actual matching SMS reply. The sender remains responsible for their chosen tariff; SendHarbor does not review operator documents. Current state is rechecked before dispatch; this read model is not authorization."
      },
      "LiveSimTestInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "expectedVerificationTag": {
            "type": "string",
            "format": "uuid",
            "description": "Current privacy-preserving SIM identity tag from device setup, not a hardware identifier."
          },
          "ownsSim": {
            "type": "boolean",
            "const": true
          },
          "permittedTest": {
            "type": "boolean",
            "const": true
          },
          "recipientConsent": {
            "type": "boolean",
            "const": true
          }
        },
        "required": [
          "id",
          "simNumber",
          "phone",
          "expectedVerificationTag",
          "ownsSim",
          "permittedTest",
          "recipientConsent"
        ],
        "description": "Explicit human confirmation of SIM control, a plan permitting these controlled tests, and control/consent of the recipient. Preserve id and the exact body on retry. No prechecked or inferred assent; no commercial carrier/10DLC approval is created."
      },
      "LiveSimTestOverview": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "source": {
            "type": "string",
            "const": "user_initiated_live_test"
          },
          "productionApproved": {
            "type": "boolean",
            "const": false
          },
          "liveTests": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/LiveSimTest"
            }
          }
        },
        "required": [
          "source",
          "productionApproved",
          "liveTests"
        ],
        "description": "Latest test for each SIM, including expired/revoked sessions. No trial is started or renewed by reading."
      },
      "TestWebhookReceipt": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "eventId": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
          },
          "type": {
            "type": "string",
            "enum": [
              "integration.test",
              "message.received",
              "message.status",
              "device.status",
              "sandbox.message.status",
              "sandbox.sms.received"
            ]
          },
          "sandbox": {
            "type": "boolean"
          },
          "eventAt": {
            "type": "string",
            "format": "date-time"
          },
          "receivedAt": {
            "type": "string",
            "format": "date-time"
          },
          "lastReceivedAt": {
            "type": "string",
            "format": "date-time"
          },
          "deliveries": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000000
          },
          "messageId": {
            "type": [
              "string",
              "null"
            ]
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "phase": {
            "type": [
              "string",
              "null"
            ]
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8
          },
          "signatureValid": {
            "type": "boolean",
            "const": true
          },
          "httpStatus": {
            "type": "integer",
            "const": 204
          }
        },
        "required": [
          "eventId",
          "type",
          "sandbox",
          "eventAt",
          "receivedAt",
          "lastReceivedAt",
          "deliveries",
          "messageId",
          "deviceId",
          "phase",
          "simNumber",
          "signatureValid",
          "httpStatus"
        ],
        "description": "Metadata-only durable receipt from the configured first-party test endpoint. SMS text, phone numbers, raw signatures and secrets are not stored in this receipt. It proves endpoint acceptance, not SMS delivery or external application processing."
      },
      "TestWebhookInboxOverview": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "available": {
            "type": "boolean"
          },
          "configured": {
            "type": "boolean"
          },
          "enabled": {
            "type": "boolean"
          },
          "hasExternalIntegration": {
            "type": "boolean"
          },
          "endpointTemplate": {
            "type": [
              "string",
              "null"
            ]
          },
          "retentionDays": {
            "type": "integer",
            "const": 7
          },
          "capacity": {
            "type": "integer",
            "const": 1000
          },
          "used": {
            "type": "integer",
            "minimum": 0
          },
          "receipts": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/TestWebhookReceipt"
            }
          }
        },
        "required": [
          "available",
          "configured",
          "enabled",
          "hasExternalIntegration",
          "endpointTemplate",
          "retentionDays",
          "capacity",
          "used",
          "receipts"
        ],
        "description": "Opt-in test receiver configured through the normal integration API; HTTPS PUBLIC_URL is required. Reading does not create or replace an integration. Never replace an existing external endpoint silently."
      },
      "TestWebhookInboxEvent": {
        "type": "object",
        "properties": {
          "version": {
            "type": "integer",
            "const": 1
          },
          "id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
          },
          "type": {
            "type": "string",
            "enum": [
              "integration.test",
              "message.received",
              "message.status",
              "device.status",
              "sandbox.message.status",
              "sandbox.sms.received"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "sandbox": {
            "type": "boolean"
          },
          "accountId": {
            "type": "string"
          },
          "projectId": {
            "type": "string"
          },
          "externalAccountId": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "description": "The original signed event data. Account/project identity, if supplied, must match this integration. Sandbox events require sandbox:true both here and at the envelope level. Only receipt metadata is retained."
          }
        },
        "required": [
          "version",
          "id",
          "type",
          "createdAt",
          "data"
        ],
        "description": "Normal signed notification; message.validate is rejected and cannot be approved by this inbox. HMAC covers the exact raw UTF-8 body, maximum 256 KiB. Preserve event ID and body on retry; re-sign with a fresh timestamp."
      },
      "IncomingMessage": {
        "type": "object",
        "required": [
          "id",
          "messageId",
          "deviceId",
          "deviceName",
          "from",
          "text",
          "to",
          "simNumber",
          "receivedAt",
          "storedAt",
          "redactedAt",
          "contentAvailable"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "History ID; use this value in GET /api/incoming-messages/{id}."
          },
          "messageId": {
            "type": "string",
            "description": "Original mobile event ID, also exposed by message.received. This is not the history detail path ID."
          },
          "deviceId": {
            "type": "string"
          },
          "deviceName": {
            "type": [
              "string",
              "null"
            ],
            "description": "Phone name captured at receipt; unavailable or redacted names are null."
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "description": "Sender as reported by the phone; null for unavailable or redacted content."
          },
          "text": {
            "type": [
              "string",
              "null"
            ],
            "description": "Full text when contentAvailable is true. An empty string is a valid empty SMS, not unavailable content.",
            "maxLength": 20000
          },
          "to": {
            "type": [
              "string",
              "null"
            ],
            "description": "Receiving SIM phone number when available. Null does not mean reception failed."
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8,
            "description": "Receiving SIM slot, when recorded."
          },
          "receivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Phone-reported SMS reception time. Null for legacy receipt-only rows; do not substitute storedAt as a phone timestamp."
          },
          "storedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Server receipt time; ordering uses storedAt then id descending."
          },
          "redactedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Content removal time under retention or deletion rules. Null with unavailable content can indicate a legacy receipt whose plaintext was never stored."
          },
          "contentAvailable": {
            "type": "boolean",
            "description": "True when text is stored, including an empty string. False for legacy receipt-only records or removed content."
          },
          "handledAt": {
            "type": "string",
            "format": "date-time",
            "description": "Present when a user or integration marked this incoming message handled. This workflow marker does not send SMS or alter webhook delivery."
          },
          "handledBy": {
            "type": [
              "string",
              "null"
            ],
            "description": "Actor user/key identifier that marked the message handled; present with handledAt. Omitted after marking unhandled."
          }
        },
        "description": "Account-isolated incoming text SMS history. Independent of webhook/WebSocket enablement and subject to retention/deletion. Legacy receipts do not restore prior plaintext. This is neither RCS nor an outgoing delivery report."
      },
      "IncomingMessagePagination": {
        "type": "object",
        "required": [
          "limit",
          "total",
          "nextCursor"
        ],
        "properties": {
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "total": {
            "type": "integer",
            "minimum": 0,
            "description": "All rows matching the filters, before cursor pagination."
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ],
            "description": "Opaque cursor for the same selected account, q and deviceId; null means no more pages."
          }
        }
      },
      "AutoReply": {
        "type": "object",
        "required": [
          "id",
          "keyword",
          "reply",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "keyword": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50,
            "description": "The keyword as the owner wrote it, without surrounding spaces. An incoming SMS matches when the whole message equals the keyword after the same normalization as opt-out words: case, surrounding spaces and punctuation and diacritics are ignored. null is the reply to any incoming SMS that matches no keyword."
          },
          "reply": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000,
            "description": "Text of the SMS sent in reply, without surrounding spaces."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "description": "A keyword auto-reply rule of one account. An account has at most 100 rules and at most one with keyword null."
      },
      "AutoReplyInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "keyword",
          "reply"
        ],
        "properties": {
          "keyword": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50,
            "description": "Keyword with at least one letter or digit, or null for the reply to any other message. Opt-out and opt-in words (STOP, START and their equivalents in the supported languages) return 400 auto_reply_keyword_reserved. Keywords that normalize to the same text, or a second null keyword, return 409 auto_reply_exists."
          },
          "reply": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000,
            "description": "Reply text. Surrounding spaces are removed."
          }
        }
      },
      "RiskSignal": {
        "type": "object",
        "required": [
          "code",
          "count",
          "total",
          "value",
          "threshold"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "failure_rate: failed among the last 100 finished sends, only with all 100 (count failed, total 100). stop_rate: opt-outs among SMS accepted in the last 24 hours and handed to a phone, from 500 such SMS (count opt-outs, total those SMS). new_recipients: SMS of the last 24 hours to recipients this account never messaged before, when the day has more than 200 SMS (count those SMS, total the day's SMS). volume_spike: the day's SMS against the average day of the previous 7 days, above 200 SMS (count the day's SMS, total the 7 days' SMS). otp_pumping: verification codes of the last 24 hours that were never entered, from 20 finished codes (count never entered, total finished). Treat an unknown code as unusual sending."
          },
          "count": {
            "type": "integer",
            "minimum": 0
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "value": {
            "type": [
              "number",
              "null"
            ],
            "description": "count/total, rounded to 4 decimals. For volume_spike the multiple of the average day; null when the previous 7 days had no SMS."
          },
          "threshold": {
            "type": "number",
            "description": "The limit that value exceeded: a share for rates, a multiple for volume_spike. Thresholds are a proposal and may change."
          }
        },
        "description": "A tripped risk signal with the numbers that explain it."
      },
      "RiskReview": {
        "type": "object",
        "required": [
          "id",
          "status",
          "signals",
          "pausedAt",
          "appealedAt",
          "appealPending",
          "decidedAt",
          "liftedAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "enum": [
              "open",
              "kept",
              "lifted"
            ],
            "description": "open: paused and waiting for review. kept: an administrator kept the pause. lifted: sending resumed."
          },
          "signals": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RiskSignal"
            },
            "description": "Signals that tripped when the account was paused."
          },
          "pausedAt": {
            "type": "string",
            "format": "date-time"
          },
          "appealedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Latest review request by the owner."
          },
          "appealPending": {
            "type": "boolean",
            "description": "A review request waits for a decision."
          },
          "decidedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Latest administrator decision."
          },
          "liftedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "description": "A risk pause of one account. While status is open or kept, its SMS wait with queueReason risk_review."
      },
      "AdminRiskReview": {
        "allOf": [
          {
            "$ref": "#/components/schemas/RiskReview"
          },
          {
            "type": "object",
            "required": [
              "accountId",
              "accountName",
              "queued",
              "mail",
              "events"
            ],
            "properties": {
              "accountId": {
                "type": "string"
              },
              "accountName": {
                "type": "string"
              },
              "queued": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0,
                "description": "SMS of the account waiting in the queue now; null for a lifted pause."
              },
              "mail": {
                "type": "object",
                "required": [
                  "sent",
                  "pending",
                  "failed"
                ],
                "properties": {
                  "sent": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "pending": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "failed": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "description": "Pause emails to the account owners, one per owner per pause. All zero: no active owner."
              },
              "events": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/RiskReviewEvent"
                },
                "description": "Decision log, oldest first."
              }
            }
          }
        ]
      },
      "RiskReviewEvent": {
        "type": "object",
        "required": [
          "kind",
          "actorId",
          "actorName",
          "actorEmail",
          "note",
          "occurredAt"
        ],
        "properties": {
          "kind": {
            "enum": [
              "paused",
              "appealed",
              "kept",
              "lifted"
            ]
          },
          "actorId": {
            "type": [
              "string",
              "null"
            ],
            "description": "null for the automatic pause."
          },
          "actorName": {
            "type": [
              "string",
              "null"
            ]
          },
          "actorEmail": {
            "type": [
              "string",
              "null"
            ]
          },
          "note": {
            "type": [
              "string",
              "null"
            ],
            "description": "The owner's note for appealed; the administrator's reason for kept and lifted."
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ContentFinding": {
        "type": "object",
        "required": [
          "code",
          "fragment"
        ],
        "properties": {
          "code": {
            "enum": [
              "url_shortener",
              "ip_address_link",
              "punycode_domain",
              "mixed_script_domain",
              "credential_phishing",
              "code_forwarding"
            ],
            "description": "Stable rule code (server/content-check.mjs)."
          },
          "fragment": {
            "type": [
              "string",
              "null"
            ],
            "description": "The matched part of the SMS text; null after the text is redacted."
          }
        }
      },
      "ContentReview": {
        "type": "object",
        "required": [
          "status",
          "heldAt",
          "decidedAt",
          "findings"
        ],
        "description": "Why the text and link check held this SMS. The reviewer and the reason are never returned to the account. An account cannot allow its own domains.",
        "properties": {
          "status": {
            "enum": [
              "open",
              "released",
              "cancelled"
            ],
            "description": "open: waiting for review with queueReason content_review. released: continues through the usual queue checks. cancelled: cancelled with error CONTENT_REVIEW_CANCELLED."
          },
          "heldAt": {
            "type": "string",
            "format": "date-time"
          },
          "decidedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "findings": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/ContentFinding"
            }
          }
        }
      },
      "AdminContentReview": {
        "type": "object",
        "required": [
          "messageId",
          "accountId",
          "accountName",
          "status",
          "heldAt",
          "messageState",
          "expiresAt",
          "text",
          "findings",
          "domains",
          "decidedAt",
          "decidedBy",
          "reason",
          "allowedDomain"
        ],
        "description": "A held SMS in the Sending review queue. The recipient number is not included.",
        "properties": {
          "messageId": {
            "type": "string"
          },
          "accountId": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "status": {
            "enum": [
              "open",
              "released",
              "cancelled"
            ]
          },
          "heldAt": {
            "type": "string",
            "format": "date-time"
          },
          "messageState": {
            "type": "string",
            "description": "Current state of the SMS."
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "The SMS still expires on its own deadline while held."
          },
          "text": {
            "type": [
              "string",
              "null"
            ],
            "description": "The SMS text; null after redaction."
          },
          "findings": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/ContentFinding"
                },
                {
                  "type": "object",
                  "required": [
                    "start",
                    "end"
                  ],
                  "properties": {
                    "start": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "end": {
                      "type": "integer",
                      "minimum": 0
                    }
                  },
                  "description": "start and end are UTF-16 offsets of the fragment in text."
                }
              ]
            }
          },
          "domains": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Hosts of the links in this SMS (xn-- form, without www.): the only values allowDomain accepts for it."
          },
          "decidedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "decidedBy": {
            "type": [
              "object",
              "null"
            ],
            "required": [
              "id",
              "name",
              "email"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "email": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "The administrator's reason; never shown to the account."
          },
          "allowedDomain": {
            "type": [
              "string",
              "null"
            ],
            "description": "The domain allowed for the account with this decision."
          }
        }
      },
      "VerificationInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phone"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "deviceId": {
            "type": "string",
            "maxLength": 100,
            "description": "The phone that sends the SMS. With neither deviceId nor poolId, the only connected phone of the account."
          },
          "poolId": {
            "type": "string",
            "maxLength": 100
          },
          "locale": {
            "type": "string",
            "enum": [
              "en",
              "ru",
              "uk"
            ],
            "default": "en"
          },
          "codeLength": {
            "type": "integer",
            "minimum": 4,
            "maximum": 8,
            "default": 6
          }
        },
        "not": {
          "required": [
            "deviceId",
            "poolId"
          ]
        }
      },
      "Verification": {
        "type": "object",
        "required": [
          "id",
          "status",
          "phone",
          "codeLength",
          "locale",
          "attempts",
          "attemptsLeft",
          "createdAt",
          "expiresAt",
          "messageId"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "expired",
              "max_attempts",
              "canceled",
              "failed"
            ]
          },
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "codeLength": {
            "type": "integer",
            "minimum": 4,
            "maximum": 8
          },
          "locale": {
            "type": "string",
            "enum": [
              "en",
              "ru",
              "uk"
            ]
          },
          "attempts": {
            "type": "integer",
            "minimum": 0,
            "maximum": 5
          },
          "attemptsLeft": {
            "type": "integer",
            "minimum": 0,
            "maximum": 5
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "messageId": {
            "type": [
              "string",
              "null"
            ],
            "description": "The queued SMS; its text is masked. null in sandbox."
          },
          "sandbox": {
            "type": "boolean"
          }
        },
        "description": "Never contains the code outside the sandbox."
      },
      "VerificationCreated": {
        "type": "object",
        "required": [
          "verification"
        ],
        "properties": {
          "verification": {
            "$ref": "#/components/schemas/Verification"
          }
        }
      },
      "VerificationCheckInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^\\d{4,8}$"
          }
        }
      },
      "VerificationCheckResult": {
        "type": "object",
        "required": [
          "status",
          "attemptsLeft",
          "verification"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "approved",
              "denied",
              "expired",
              "max_attempts"
            ]
          },
          "attemptsLeft": {
            "type": "integer",
            "minimum": 0,
            "maximum": 5
          },
          "verification": {
            "$ref": "#/components/schemas/Verification"
          }
        }
      },
      "VerificationSettingsInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "countryCodes"
        ],
        "properties": {
          "countryCodes": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 50,
            "items": {
              "type": "string",
              "pattern": "^\\+[1-9]\\d{0,2}$"
            }
          }
        }
      },
      "VerificationSettings": {
        "type": "object",
        "required": [
          "settings",
          "activity",
          "limits"
        ],
        "properties": {
          "settings": {
            "type": "object",
            "required": [
              "countryCodes",
              "mode",
              "defaultCountryCodes",
              "defaultSource",
              "updatedAt"
            ],
            "properties": {
              "countryCodes": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "mode": {
                "type": "string",
                "enum": [
                  "default",
                  "custom"
                ]
              },
              "defaultCountryCodes": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "defaultSource": {
                "type": "string",
                "enum": [
                  "sim",
                  "sent",
                  "none"
                ]
              },
              "updatedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "activity": {
            "type": "object",
            "required": [
              "24h",
              "7d"
            ],
            "properties": {
              "24h": {
                "type": "object",
                "required": [
                  "created",
                  "approved",
                  "unchecked",
                  "pending",
                  "failed",
                  "uncheckedShare",
                  "pumpingSuspected"
                ],
                "properties": {
                  "created": {
                    "type": "integer"
                  },
                  "approved": {
                    "type": "integer"
                  },
                  "unchecked": {
                    "type": "integer",
                    "description": "Expired or replaced without a single check attempt"
                  },
                  "pending": {
                    "type": "integer"
                  },
                  "failed": {
                    "type": "integer",
                    "description": "The SMS could not be queued"
                  },
                  "uncheckedShare": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "pumpingSuspected": {
                    "type": "boolean"
                  }
                }
              },
              "7d": {
                "type": "object",
                "required": [
                  "created",
                  "approved",
                  "unchecked",
                  "pending",
                  "failed",
                  "uncheckedShare",
                  "pumpingSuspected"
                ],
                "properties": {
                  "created": {
                    "type": "integer"
                  },
                  "approved": {
                    "type": "integer"
                  },
                  "unchecked": {
                    "type": "integer",
                    "description": "Expired or replaced without a single check attempt"
                  },
                  "pending": {
                    "type": "integer"
                  },
                  "failed": {
                    "type": "integer",
                    "description": "The SMS could not be queued"
                  },
                  "uncheckedShare": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "pumpingSuspected": {
                    "type": "boolean"
                  }
                }
              }
            }
          },
          "limits": {
            "type": "object",
            "properties": {
              "codeTtlSeconds": {
                "type": "integer"
              },
              "maxCheckAttempts": {
                "type": "integer"
              },
              "perPhone": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "seconds": {
                      "type": "integer"
                    }
                  }
                }
              },
              "perAccount": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "seconds": {
                      "type": "integer"
                    }
                  }
                }
              },
              "pumpingSignal": {
                "type": "object",
                "properties": {
                  "minimumFinished": {
                    "type": "integer"
                  },
                  "uncheckedShare": {
                    "type": "number"
                  }
                }
              }
            }
          }
        }
      },
      "SandboxVerificationInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phone"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "deviceId": {
            "type": "string",
            "enum": [
              "sandbox-phone"
            ]
          },
          "locale": {
            "type": "string",
            "enum": [
              "en",
              "ru",
              "uk"
            ],
            "default": "en"
          },
          "codeLength": {
            "type": "integer",
            "minimum": 4,
            "maximum": 8,
            "default": 6
          }
        }
      },
      "SandboxVerificationCreated": {
        "type": "object",
        "required": [
          "sandbox",
          "verification"
        ],
        "properties": {
          "sandbox": {
            "const": true
          },
          "verification": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Verification"
              },
              {
                "type": "object",
                "required": [
                  "code"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "pattern": "^\\d{4,8}$",
                    "description": "Sandbox only."
                  }
                }
              }
            ]
          }
        }
      },
      "SandboxVerificationCheckResult": {
        "allOf": [
          {
            "$ref": "#/components/schemas/VerificationCheckResult"
          },
          {
            "type": "object",
            "required": [
              "sandbox"
            ],
            "properties": {
              "sandbox": {
                "const": true
              }
            }
          }
        ]
      },
      "Suppression": {
        "type": "object",
        "required": [
          "phone",
          "optedOutAt",
          "keyword"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "description": "Recipient number in E.164 that opted out of SMS from this account."
          },
          "optedOutAt": {
            "type": "string",
            "format": "date-time",
            "description": "When the opt-out took effect: the phone's reception time of the reply, never later than its arrival at SendHarbor."
          },
          "keyword": {
            "type": [
              "string",
              "null"
            ],
            "description": "The recipient's opt-out word as received, without surrounding spaces and punctuation: a reply \"Stop!\" is shown as \"Stop\". null when the reply is no longer stored (retention or deletion) or the opt-out was not recorded from a stored incoming SMS."
          }
        },
        "description": "An active opt-out. Sending to this number from the account is cancelled with RECIPIENT_OPTED_OUT until the recipient replies with an opt-in word such as START. It cannot be removed through the API."
      },
      "Appointment": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "externalId",
          "phone",
          "name",
          "startsAt",
          "timeZone",
          "service",
          "place",
          "staff",
          "status",
          "reply",
          "revision",
          "reminders",
          "createdAt",
          "updatedAt",
          "cancelledAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 128
          },
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "startsAt": {
            "type": "string",
            "format": "date-time",
            "description": "The start instant in UTC."
          },
          "timeZone": {
            "type": "string",
            "description": "IANA zone; {{date}} and {{time}} and \"the day before\" use it."
          },
          "service": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "place": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "staff": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "status": {
            "enum": [
              "scheduled",
              "confirmed",
              "reschedule_requested",
              "cancelled"
            ],
            "description": "confirmed after a reply 1, reschedule_requested after a reply 2; the latest answer wins. A reschedule returns it to scheduled."
          },
          "reply": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "required": [
              "answer",
              "receivedAt"
            ],
            "properties": {
              "answer": {
                "enum": [
                  "confirm",
                  "reschedule"
                ]
              },
              "receivedAt": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "revision": {
            "type": "integer",
            "minimum": 1,
            "description": "Grows with every change; reminder messages use it as replaceVersion."
          },
          "reminders": {
            "type": "array",
            "maxItems": 3,
            "items": {
              "$ref": "#/components/schemas/AppointmentReminder"
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "cancelledAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "AppointmentReminder": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind",
          "sendAt",
          "status",
          "reason",
          "messageId"
        ],
        "properties": {
          "kind": {
            "enum": [
              "confirmation",
              "reminder24h",
              "reminder2h"
            ]
          },
          "sendAt": {
            "type": "string",
            "format": "date-time",
            "description": "Planned time: now for a confirmation, the same local time the day before (23 or 25 hours across a daylight saving change), or 2 hours before."
          },
          "status": {
            "enum": [
              "planned",
              "scheduled",
              "sending",
              "sent",
              "delivered",
              "failed",
              "unknown",
              "skipped",
              "cancelled"
            ],
            "description": "planned: no message yet (more than 29 days ahead, or retried). The others follow the message; skipped and failed carry a reason."
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Why a reminder waits or is not sent: time_passed, disabled, quiet_hours (the phone's quiet hours would hold it past the start), not_sent_before_start, expired, opted_out, template_variables_missing, phone_not_selected (two or more phones and none chosen), or an admission error code such as device_not_found while it is retried every minute until the start."
          },
          "messageId": {
            "type": [
              "string",
              "null"
            ],
            "description": "The queued message, readable with GET /api/messages/{id}."
          }
        }
      },
      "AppointmentInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phone",
          "name",
          "startsAt",
          "timeZone"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "startsAt": {
            "type": "string",
            "description": "2026-11-12T14:30 (local time in timeZone) or 2026-11-12T14:30:00+02:00 / ...Z. Must be in the future and at most two years ahead."
          },
          "timeZone": {
            "type": "string",
            "maxLength": 64,
            "description": "IANA zone such as Europe/Kyiv; raw offsets are not accepted."
          },
          "service": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "place": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "staff": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 128,
            "description": "Your ID, unique in the account; makes a repeated create idempotent."
          }
        }
      },
      "AppointmentUpdate": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "startsAt": {
            "type": "string",
            "description": "A local time is read in the timeZone that applies after this change."
          },
          "timeZone": {
            "type": "string",
            "maxLength": 64,
            "description": "Alone it keeps the start instant and changes how the time reads."
          },
          "service": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "place": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "staff": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          }
        }
      },
      "AppointmentSettingsInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "confirmation",
          "reminder24h",
          "reminder2h",
          "language"
        ],
        "properties": {
          "confirmation": {
            "type": "boolean"
          },
          "reminder24h": {
            "type": "boolean"
          },
          "reminder2h": {
            "type": "boolean"
          },
          "language": {
            "enum": [
              "en",
              "ru"
            ]
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Sending phone; null uses the account's only connected phone."
          },
          "templates": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "confirmation": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Account template ID; null uses the built-in text."
              },
              "reminder24h": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Account template ID; null uses the built-in text."
              },
              "reminder2h": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Account template ID; null uses the built-in text."
              }
            }
          }
        }
      },
      "AppointmentSettings": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "confirmation",
          "reminder24h",
          "reminder2h",
          "language",
          "deviceId",
          "templates",
          "updatedAt"
        ],
        "properties": {
          "confirmation": {
            "type": "boolean"
          },
          "reminder24h": {
            "type": "boolean"
          },
          "reminder2h": {
            "type": "boolean"
          },
          "language": {
            "enum": [
              "en",
              "ru"
            ]
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "templates": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "confirmation": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Account template ID; null uses the built-in text."
              },
              "reminder24h": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Account template ID; null uses the built-in text."
              },
              "reminder2h": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Account template ID; null uses the built-in text."
              }
            },
            "required": [
              "confirmation",
              "reminder24h",
              "reminder2h"
            ]
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "null until the settings are first saved; the defaults apply."
          }
        }
      },
      "AppointmentSettingsView": {
        "type": "object",
        "required": [
          "settings",
          "defaultTexts",
          "variables"
        ],
        "properties": {
          "settings": {
            "$ref": "#/components/schemas/AppointmentSettings"
          },
          "defaultTexts": {
            "type": "object",
            "description": "Built-in texts per language and SMS.",
            "properties": {
              "en": {
                "type": "object",
                "properties": {
                  "confirmation": {
                    "type": "string"
                  },
                  "reminder24h": {
                    "type": "string"
                  },
                  "reminder2h": {
                    "type": "string"
                  }
                }
              },
              "ru": {
                "type": "object",
                "properties": {
                  "confirmation": {
                    "type": "string"
                  },
                  "reminder24h": {
                    "type": "string"
                  },
                  "reminder2h": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "variables": {
            "type": "array",
            "items": {
              "enum": [
                "name",
                "date",
                "weekday",
                "time",
                "service",
                "place",
                "staff"
              ]
            }
          }
        }
      },
      "MessageTemplate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "name",
          "text",
          "variables",
          "quickReply",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000,
            "description": "Exactly as saved. Variables are written as {{name}}: a lowercase Latin letter followed by up to 31 lowercase Latin letters, digits or _. There is no escape syntax."
          },
          "variables": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,31}$"
            },
            "description": "Variable names in order of first appearance, each once."
          },
          "quickReply": {
            "type": "boolean",
            "description": "Offered as a quick reply when answering an incoming SMS in the dashboard."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "MessageTemplateInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "text"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "description": "Trimmed; unique in the account."
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000,
            "description": "Stored exactly as written; text that is empty or only whitespace is rejected. Variables are written as {{name}}: a lowercase Latin letter followed by up to 31 lowercase Latin letters, digits or _. There is no escape syntax."
          },
          "quickReply": {
            "type": "boolean",
            "default": false,
            "description": "Offer it as a quick reply when answering an incoming SMS."
          }
        }
      },
      "TemplateNiche": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "name",
          "description",
          "quietHours",
          "templates"
        ],
        "properties": {
          "id": {
            "enum": [
              "clinic",
              "beauty_salon",
              "repair",
              "delivery"
            ]
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "quietHours": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "start",
              "end"
            ],
            "description": "Suggested quiet hours in the phone sending policy; never applied automatically.",
            "properties": {
              "start": {
                "type": "string",
                "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
              },
              "end": {
                "type": "string",
                "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
              }
            }
          },
          "templates": {
            "type": "array",
            "minItems": 3,
            "maxItems": 5,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "name",
                "text",
                "quickReply"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "text": {
                  "type": "string"
                },
                "quickReply": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "Contact": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "phone",
          "name",
          "fields",
          "groupIds",
          "optedOut",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "phone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$"
          },
          "name": {
            "type": "string",
            "maxLength": 100,
            "description": "Empty when not known."
          },
          "fields": {
            "type": "object",
            "maxProperties": 10,
            "propertyNames": {
              "pattern": "^[a-z][a-z0-9_]{0,31}$",
              "not": {
                "enum": [
                  "name",
                  "phone"
                ]
              }
            },
            "additionalProperties": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Custom fields that become template variables: {{key}}. Keys follow the template variable rule; name and phone are built in."
          },
          "groupIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "optedOut": {
            "type": "boolean",
            "description": "The number has an active STOP for this account; sends skip it."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ContactInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phone"
        ],
        "properties": {
          "phone": {
            "type": "string",
            "maxLength": 32,
            "description": "International number; spaces, brackets, dots and dashes are removed and a leading 00 becomes +."
          },
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "fields": {
            "type": "object",
            "maxProperties": 10,
            "propertyNames": {
              "pattern": "^[a-z][a-z0-9_]{0,31}$",
              "not": {
                "enum": [
                  "name",
                  "phone"
                ]
              }
            },
            "additionalProperties": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Custom fields that become template variables: {{key}}. Keys follow the template variable rule; name and phone are built in."
          },
          "groupIds": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "string"
            }
          }
        }
      },
      "ContactGroup": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "name",
          "contacts",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "contacts": {
            "type": "integer",
            "minimum": 0
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ContactGroupInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          }
        }
      },
      "ContactImportMapping": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phone"
        ],
        "properties": {
          "phone": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "description": "Column number from 0; null only in a preview."
          },
          "name": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "fields": {
            "type": "object",
            "maxProperties": 10,
            "propertyNames": {
              "pattern": "^[a-z][a-z0-9_]{0,31}$"
            },
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "description": "Each column is used for one value at most."
      },
      "ContactImportPreview": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "delimiter",
          "header",
          "columns",
          "mapping",
          "counts",
          "issues",
          "issuesTruncated",
          "contacts",
          "fingerprint"
        ],
        "properties": {
          "delimiter": {
            "type": "string",
            "enum": [
              ",",
              ";"
            ]
          },
          "header": {
            "type": "boolean",
            "description": "The first line is titles: none of its values is a phone number."
          },
          "columns": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "index",
                "header",
                "samples"
              ],
              "properties": {
                "index": {
                  "type": "integer",
                  "minimum": 0
                },
                "header": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "samples": {
                  "type": "array",
                  "maxItems": 3,
                  "items": {
                    "type": "string",
                    "maxLength": 60
                  }
                }
              }
            }
          },
          "mapping": {
            "$ref": "#/components/schemas/ContactImportMapping"
          },
          "counts": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "rows",
              "new",
              "updated",
              "unchanged",
              "duplicate",
              "invalid",
              "optedOut"
            ],
            "properties": {
              "rows": {
                "type": "integer",
                "minimum": 0
              },
              "new": {
                "type": "integer",
                "minimum": 0
              },
              "updated": {
                "type": "integer",
                "minimum": 0
              },
              "unchanged": {
                "type": "integer",
                "minimum": 0
              },
              "duplicate": {
                "type": "integer",
                "minimum": 0
              },
              "invalid": {
                "type": "integer",
                "minimum": 0
              },
              "optedOut": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "issues": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "line",
                "reason"
              ],
              "properties": {
                "line": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Line of the file where the row starts."
                },
                "reason": {
                  "type": "string",
                  "enum": [
                    "phone_missing",
                    "phone_invalid",
                    "name_too_long",
                    "field_too_long",
                    "too_many_fields",
                    "duplicate",
                    "opted_out"
                  ],
                  "description": "opted_out rows are imported; the others are skipped."
                },
                "phone": {
                  "type": "string"
                },
                "value": {
                  "type": "string",
                  "maxLength": 32,
                  "description": "The invalid number as written."
                },
                "field": {
                  "type": "string"
                },
                "firstLine": {
                  "type": "integer",
                  "description": "Line with the first row of the same number."
                }
              }
            }
          },
          "issuesTruncated": {
            "type": "boolean"
          },
          "contacts": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "existing",
              "limit"
            ],
            "properties": {
              "existing": {
                "type": "integer",
                "minimum": 0
              },
              "limit": {
                "type": "integer"
              }
            }
          },
          "fingerprint": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-f0-9]{64}$"
          }
        }
      },
      "ContactImportResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "counts",
          "issues",
          "issuesTruncated",
          "groupId"
        ],
        "properties": {
          "counts": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "rows",
              "new",
              "updated",
              "unchanged",
              "duplicate",
              "invalid",
              "optedOut"
            ],
            "properties": {
              "rows": {
                "type": "integer",
                "minimum": 0
              },
              "new": {
                "type": "integer",
                "minimum": 0
              },
              "updated": {
                "type": "integer",
                "minimum": 0
              },
              "unchanged": {
                "type": "integer",
                "minimum": 0
              },
              "duplicate": {
                "type": "integer",
                "minimum": 0
              },
              "invalid": {
                "type": "integer",
                "minimum": 0
              },
              "optedOut": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "issues": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "line",
                "reason"
              ],
              "properties": {
                "line": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Line of the file where the row starts."
                },
                "reason": {
                  "type": "string",
                  "enum": [
                    "phone_missing",
                    "phone_invalid",
                    "name_too_long",
                    "field_too_long",
                    "too_many_fields",
                    "duplicate",
                    "opted_out"
                  ],
                  "description": "opted_out rows are imported; the others are skipped."
                },
                "phone": {
                  "type": "string"
                },
                "value": {
                  "type": "string",
                  "maxLength": 32,
                  "description": "The invalid number as written."
                },
                "field": {
                  "type": "string"
                },
                "firstLine": {
                  "type": "integer",
                  "description": "Line with the first row of the same number."
                }
              }
            }
          },
          "issuesTruncated": {
            "type": "boolean"
          },
          "groupId": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ContactMessageSelection": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "templateId": {
            "type": "string",
            "maxLength": 100,
            "description": "A saved template; or text."
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000,
            "description": "Text with {{name}} variables; or templateId."
          },
          "groupId": {
            "type": "string",
            "maxLength": 100,
            "description": "All contacts of a group; or contactIds."
          },
          "contactIds": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1000,
            "items": {
              "type": "string"
            },
            "description": "Chosen contacts; repeated ids count once."
          },
          "maxSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "A final text with more parts is skipped as too_long."
          }
        },
        "description": "Exactly one of templateId and text, and exactly one of groupId and contactIds."
      },
      "ContactMessageInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "batchId"
        ],
        "properties": {
          "batchId": {
            "type": "string",
            "maxLength": 100,
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$",
            "description": "Names the send; parts are queued as batchId:1, batchId:2…"
          },
          "templateId": {
            "type": "string",
            "maxLength": 100,
            "description": "A saved template; or text."
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000,
            "description": "Text with {{name}} variables; or templateId."
          },
          "groupId": {
            "type": "string",
            "maxLength": 100,
            "description": "All contacts of a group; or contactIds."
          },
          "contactIds": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1000,
            "items": {
              "type": "string"
            },
            "description": "Chosen contacts; repeated ids count once."
          },
          "maxSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "A final text with more parts is skipped as too_long."
          },
          "deviceId": {
            "type": "string"
          },
          "poolId": {
            "type": "string"
          },
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "purpose": {
            "type": "string",
            "enum": [
              "transactional",
              "marketing"
            ],
            "default": "transactional"
          },
          "ttlSeconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 604800
          },
          "sendAt": {
            "type": "string",
            "format": "date-time"
          },
          "priority": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2
          }
        },
        "description": "The selection of ContactMessageSelection plus the batchId and the sending options of a batch item, applied to every message. Choose deviceId or poolId."
      },
      "ContactMessagePreview": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "selected",
          "sendable",
          "limit",
          "batches",
          "segments",
          "variables",
          "samples",
          "skipped",
          "skippedTotal",
          "counts",
          "messageCreated"
        ],
        "properties": {
          "selected": {
            "type": "integer",
            "minimum": 0
          },
          "sendable": {
            "type": "integer",
            "minimum": 0
          },
          "limit": {
            "type": "integer",
            "description": "Most sendable contacts per request."
          },
          "batches": {
            "type": "integer",
            "minimum": 0,
            "description": "Batches of at most 100 that a send would queue."
          },
          "segments": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "required": [
              "min",
              "max",
              "total"
            ],
            "properties": {
              "min": {
                "type": "integer"
              },
              "max": {
                "type": "integer"
              },
              "total": {
                "type": "integer"
              }
            },
            "description": "SMS parts per final text and in total; null when nothing is sendable."
          },
          "variables": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "samples": {
            "type": "array",
            "maxItems": 3,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "contactId",
                "name",
                "phone",
                "text",
                "segments",
                "encoding"
              ],
              "properties": {
                "contactId": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "phone": {
                  "type": "string"
                },
                "text": {
                  "type": "string"
                },
                "segments": {
                  "type": "integer"
                },
                "encoding": {
                  "type": "string",
                  "enum": [
                    "GSM-7",
                    "UCS-2"
                  ]
                }
              }
            }
          },
          "skipped": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "contactId",
                "reason"
              ],
              "properties": {
                "contactId": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "phone": {
                  "type": "string"
                },
                "reason": {
                  "type": "string",
                  "enum": [
                    "opted_out",
                    "missing_variables",
                    "too_long",
                    "not_found"
                  ]
                },
                "missingVariables": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "segments": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          },
          "skippedTotal": {
            "type": "integer",
            "minimum": 0
          },
          "counts": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "optedOut",
              "missingVariables",
              "tooLong",
              "notFound"
            ],
            "properties": {
              "optedOut": {
                "type": "integer",
                "minimum": 0
              },
              "missingVariables": {
                "type": "integer",
                "minimum": 0
              },
              "tooLong": {
                "type": "integer",
                "minimum": 0
              },
              "notFound": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "messageCreated": {
            "type": "boolean",
            "const": false
          }
        }
      },
      "ContactMessageResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "batchId",
          "queued",
          "batches",
          "skipped",
          "skippedTotal",
          "counts"
        ],
        "properties": {
          "batchId": {
            "type": "string"
          },
          "queued": {
            "type": "integer",
            "minimum": 1
          },
          "batches": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "id",
                "externalId",
                "total",
                "state",
                "counts"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "externalId": {
                  "type": "string"
                },
                "total": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 100
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "in_progress",
                    "needs_review",
                    "completed",
                    "completed_with_issues"
                  ]
                },
                "counts": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "integer",
                    "minimum": 0
                  }
                }
              }
            }
          },
          "skipped": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "contactId",
                "reason"
              ],
              "properties": {
                "contactId": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "phone": {
                  "type": "string"
                },
                "reason": {
                  "type": "string",
                  "enum": [
                    "opted_out",
                    "missing_variables",
                    "too_long",
                    "not_found"
                  ]
                },
                "missingVariables": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "segments": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          },
          "skippedTotal": {
            "type": "integer",
            "minimum": 0
          },
          "counts": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "optedOut",
              "missingVariables",
              "tooLong",
              "notFound"
            ],
            "properties": {
              "optedOut": {
                "type": "integer",
                "minimum": 0
              },
              "missingVariables": {
                "type": "integer",
                "minimum": 0
              },
              "tooLong": {
                "type": "integer",
                "minimum": 0
              },
              "notFound": {
                "type": "integer",
                "minimum": 0
              }
            }
          }
        }
      },
      "MessagePreviewInput": {
        "type": "object",
        "additionalProperties": false,
        "description": "Provide text, or templateId with variables.",
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000,
            "description": "The exact SMS text is stored without trimming. At most 5000 UTF-16 code units; text that is empty or only whitespace is rejected. Analysed literally: braces are not variables. Not allowed with templateId."
          },
          "templateId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "description": "A template of the selected account. Its text is rendered with variables and then analysed."
          },
          "variables": {
            "type": "object",
            "maxProperties": 50,
            "propertyNames": {
              "pattern": "^[a-z][a-z0-9_]{0,31}$"
            },
            "additionalProperties": {
              "type": "string",
              "maxLength": 1000
            },
            "description": "Values for the template variables, only with templateId. Extra names are ignored. A missing, empty or blank value is reported in error.missingVariables and never substituted."
          },
          "maxSegments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "Optional safety cap on estimated SMS parts per message. A larger payload is rejected before admission (message_segment_limit); a batch is atomic. No silent truncation, transliteration or rewriting. Omitted preserves legacy behavior; the web composer pins the reviewed estimate by default. Not a carrier bill or delivery guarantee. Changing the cap on an idempotent retry conflicts."
          }
        }
      },
      "SuppressionPagination": {
        "type": "object",
        "required": [
          "limit",
          "total",
          "nextCursor"
        ],
        "properties": {
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "total": {
            "type": "integer",
            "minimum": 0,
            "description": "All active opt-outs matching q, before cursor pagination."
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ],
            "description": "Opaque cursor for the same selected account and q; null means no more pages."
          }
        }
      },
      "AdminActivityRow": {
        "type": "object",
        "required": [
          "key",
          "id",
          "messageId",
          "externalId",
          "direction",
          "accountId",
          "accountName",
          "accountArchived",
          "deviceId",
          "deviceName",
          "deviceArchived",
          "ownerEmail",
          "from",
          "to",
          "text",
          "simNumber",
          "status",
          "state",
          "occurredAt",
          "createdAt",
          "updatedAt",
          "sentAt",
          "deliveredAt",
          "receivedAt",
          "queueReason",
          "nextAttemptAt",
          "sendAt",
          "expiresAt",
          "error",
          "attention",
          "attentionReason",
          "resolved",
          "contentAvailable",
          "redactedAt",
          "accountStatus",
          "accountPaused",
          "deviceLastSeenAt",
          "operations"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Globally unique row key: outgoing:<id> or incoming:<id>; IDs can collide across the two stores."
          },
          "id": {
            "type": "string"
          },
          "messageId": {
            "type": "string",
            "description": "Outgoing message ID or incoming mobile event ID; incoming id is the separate history record ID."
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ]
          },
          "direction": {
            "type": "string",
            "enum": [
              "outgoing",
              "incoming"
            ]
          },
          "accountId": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "accountArchived": {
            "type": "boolean"
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Null until an unbound phone pool has selected a phone."
          },
          "deviceName": {
            "type": [
              "string",
              "null"
            ],
            "description": "Historical name when recorded; otherwise the current local directory label. Null for redacted content."
          },
          "deviceArchived": {
            "type": "boolean"
          },
          "ownerEmail": {
            "type": [
              "string",
              "null"
            ],
            "description": "Historical outgoing identity snapshot only. Incoming rows and missing snapshots return null; the current phone owner never substitutes for a historical sender."
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "description": "Stored sender number or incoming sender; outgoing numbers are never reconstructed from the current SIM."
          },
          "to": {
            "type": [
              "string",
              "null"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8,
            "description": "Stored SIM slot; null while automatic routing has not selected one or when unavailable."
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "processing",
              "sent",
              "delivered",
              "received",
              "failed",
              "expired",
              "cancelled",
              "unknown"
            ]
          },
          "state": {
            "type": "string",
            "description": "Original stored state. Failed and rejected map to status failed; submitting/Pending/Processed map to processing."
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time",
            "description": "Outgoing updated_at or incoming stored_at. This is the last stored server event, not an inferred delivery time."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "receivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Phone-reported reception time, null for legacy metadata-only receipts."
          },
          "queueReason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Stored queue reason; future sendAt is reported as scheduled. A planned wait is not an SMS failure."
          },
          "nextAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Public estimate, including sendAt and bounded by expiry; internal retry wake markers are not an ETA."
          },
          "sendAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "attention": {
            "type": "boolean"
          },
          "attentionReason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "unknown_outcome",
              "expired_queue",
              "send_failed",
              "expired",
              "processing_delayed",
              "queue_delayed",
              null
            ]
          },
          "resolved": {
            "type": "boolean",
            "description": "True only for unknown messages with an existing acknowledgement; does not reinterpret the result as sent and exposes no resolution note."
          },
          "contentAvailable": {
            "type": "boolean",
            "description": "False for redacted or legacy metadata-only content. Empty stored SMS text is still available."
          },
          "redactedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "accountStatus": {
            "type": "string"
          },
          "accountPaused": {
            "type": "boolean"
          },
          "deviceLastSeenAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Local phone-contact evidence only. Stale contact does not establish an SMS failure, SIM balance, or carrier problem."
          },
          "retryOf": {
            "type": "string",
            "description": "Original message ID for an administrator-confirmed retry in the same account. The retry is a separate message; follow retryOf to recover the original externalId. Present from its first queued status event."
          },
          "retryMessageId": {
            "type": "string",
            "description": "Existing retry created for this source message in the same account. Its presence does not change or hide the original failure."
          },
          "operations": {
            "$ref": "#/components/schemas/ActivityRowOperations"
          }
        },
        "description": "One stored business SMS. Retention/privacy markers mask text, from, to, externalId, error, deviceName and ownerEmail even if plaintext cleanup has not yet run. Verification and system-control outgoing SMS are excluded. Archived accounts and revoked phones remain visible."
      },
      "AdminActivityPage": {
        "type": "object",
        "required": [
          "generatedAt",
          "snapshotAt",
          "validUntil",
          "counts",
          "countsBasis",
          "rows",
          "filters",
          "pagination",
          "operations"
        ],
        "properties": {
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "snapshotAt": {
            "type": "string",
            "format": "date-time",
            "description": "First page anchor retained by the cursor; no historical database snapshot is materialized."
          },
          "validUntil": {
            "type": "string",
            "format": "date-time"
          },
          "counts": {
            "type": "object",
            "required": [
              "queued",
              "processing",
              "attention",
              "sent",
              "received"
            ],
            "properties": {
              "queued": {
                "type": "integer",
                "minimum": 0
              },
              "processing": {
                "type": "integer",
                "minimum": 0
              },
              "attention": {
                "type": "integer",
                "minimum": 0
              },
              "sent": {
                "type": "integer",
                "minimum": 0
              },
              "received": {
                "type": "integer",
                "minimum": 0
              }
            },
            "description": "Respect q/accountId/deviceId/simNumber, but ignore direction, status and pagination so the summary always covers both directions. queued and processing include all ages. attention includes current unresolved unknown, expired queue and delayed processing/queue at any age, plus Failed/rejected/expired terminal events in the selected period. sent counts Sent or Delivered by actual sent_at for bounded periods. All-time also includes confirmed states without a usable sent_at; countsTiming.sentWithoutTimestamp identifies these records, excluded from bounded periods. No send timestamp is inferred. received uses server stored_at."
          },
          "countsBasis": {
            "type": "object",
            "required": [
              "sent",
              "received"
            ],
            "properties": {
              "sent": {
                "type": "string",
                "enum": [
                  "sent_at",
                  "confirmed_state"
                ]
              },
              "received": {
                "type": "string",
                "enum": [
                  "stored_at"
                ]
              }
            }
          },
          "rows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminActivityRow"
            }
          },
          "filters": {
            "type": "object",
            "required": [
              "accounts",
              "devices"
            ],
            "properties": {
              "accounts": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "name",
                    "archived"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "archived": {
                      "type": "boolean"
                    }
                  }
                }
              },
              "devices": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "accountId",
                    "name",
                    "ownerEmail",
                    "archived"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "accountId": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "ownerEmail": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Current directory owner; separate from historical row sender identity."
                    },
                    "archived": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "pagination": {
            "type": "object",
            "required": [
              "limit",
              "total",
              "nextCursor"
            ],
            "properties": {
              "limit": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100
              },
              "total": {
                "type": "integer",
                "minimum": 0,
                "description": "All currently matching anchored rows before this page cursor; may shrink when rows change after the anchor."
              },
              "nextCursor": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Opaque cursor tied to every normalized filter including limit, expiring after 30 minutes. Null means no further page."
              }
            }
          },
          "emptyReason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "no_messages",
              "filtered",
              null
            ],
            "description": "For an empty list, no_messages means no stored ordinary messages in the authorized scope; filtered means messages exist outside this filter/period. Customer feeds never inspect another account for this value."
          },
          "operations": {
            "$ref": "#/components/schemas/AdminActivityOperations"
          },
          "range": {
            "$ref": "#/components/schemas/HistoryRange"
          },
          "countsTiming": {
            "type": "object",
            "required": [
              "sentWithoutTimestamp"
            ],
            "properties": {
              "sentWithoutTimestamp": {
                "type": "integer",
                "minimum": 0
              }
            },
            "description": "Confirmed Sent/Delivered records with no usable send timestamp in the same company/phone/SIM/search scope, independently of the history range. Included in all-time Sent only; excluded from bounded periods. Not an unknown sending outcome."
          }
        }
      },
      "MessageFeedRow": {
        "type": "object",
        "required": [
          "key",
          "id",
          "messageId",
          "externalId",
          "direction",
          "accountId",
          "accountName",
          "accountArchived",
          "deviceId",
          "deviceName",
          "deviceArchived",
          "ownerEmail",
          "from",
          "to",
          "text",
          "simNumber",
          "status",
          "state",
          "occurredAt",
          "createdAt",
          "updatedAt",
          "sentAt",
          "deliveredAt",
          "receivedAt",
          "queueReason",
          "nextAttemptAt",
          "sendAt",
          "expiresAt",
          "error",
          "attention",
          "attentionReason",
          "resolved",
          "contentAvailable",
          "redactedAt",
          "accountStatus",
          "accountPaused",
          "deviceLastSeenAt",
          "storedAt",
          "replacement"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Globally unique row key: outgoing:<id> or incoming:<id>; IDs can collide across the two stores."
          },
          "id": {
            "type": "string"
          },
          "messageId": {
            "type": "string",
            "description": "Outgoing message ID or incoming mobile event ID; incoming id is the separate history record ID."
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ]
          },
          "direction": {
            "type": "string",
            "enum": [
              "outgoing",
              "incoming"
            ]
          },
          "accountId": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "accountArchived": {
            "type": "boolean"
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Null until an unbound phone pool has selected a phone."
          },
          "deviceName": {
            "type": [
              "string",
              "null"
            ],
            "description": "Historical name when recorded; otherwise the current local directory label. Null for redacted content."
          },
          "deviceArchived": {
            "type": "boolean"
          },
          "ownerEmail": {
            "type": [
              "string",
              "null"
            ],
            "description": "Historical outgoing identity snapshot only. Incoming rows and missing snapshots return null; the current phone owner never substitutes for a historical sender."
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "description": "Stored sender number or incoming sender; outgoing numbers are never reconstructed from the current SIM."
          },
          "to": {
            "type": [
              "string",
              "null"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8,
            "description": "Stored SIM slot; null while automatic routing has not selected one or when unavailable."
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "processing",
              "sent",
              "delivered",
              "received",
              "failed",
              "expired",
              "cancelled",
              "unknown"
            ]
          },
          "state": {
            "type": "string",
            "description": "Original stored state. Failed and rejected map to status failed; submitting/Pending/Processed map to processing."
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time",
            "description": "Immutable feed position: outgoing createdAt or incoming storedAt, never receivedAt or updatedAt."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "receivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Phone-reported reception time, null for legacy metadata-only receipts."
          },
          "queueReason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Stored queue reason; future sendAt is reported as scheduled. A planned wait is not an SMS failure."
          },
          "nextAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Public estimate, including sendAt and bounded by expiry; internal retry wake markers are not an ETA."
          },
          "sendAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "attention": {
            "type": "boolean"
          },
          "attentionReason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "unknown_outcome",
              "expired_queue",
              "send_failed",
              "expired",
              "processing_delayed",
              "queue_delayed",
              null
            ]
          },
          "resolved": {
            "type": "boolean",
            "description": "True only for unknown messages with an existing acknowledgement; does not reinterpret the result as sent and exposes no resolution note."
          },
          "contentAvailable": {
            "type": "boolean",
            "description": "False for redacted or legacy metadata-only content. Empty stored SMS text is still available."
          },
          "redactedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "accountStatus": {
            "type": "string"
          },
          "accountPaused": {
            "type": "boolean"
          },
          "deviceLastSeenAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Local phone-contact evidence only. Stale contact does not establish an SMS failure, SIM balance, or carrier problem."
          },
          "storedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Server storage timestamp for incoming records; null for outgoing SMS."
          },
          "replacement": {
            "type": [
              "object",
              "null"
            ],
            "description": "Outgoing replacement metadata, null if absent or redacted. A cancelled SMS with replacedBy is superseded, not a manual cancellation.",
            "required": [
              "key",
              "version",
              "replacedBy"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "version": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "replacedBy": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "retryOf": {
            "type": "string",
            "description": "Original message ID for an administrator-confirmed retry in the same account. The retry is a separate message; follow retryOf to recover the original externalId. Present from its first queued status event."
          },
          "retryMessageId": {
            "type": "string",
            "description": "Existing retry created for this source message in the same account. Its presence does not change or hide the original failure."
          }
        },
        "description": "One company-feed message with its current status, ordered by original service registration time. This is not one row per status event."
      },
      "MessageFeedPage": {
        "type": "object",
        "required": [
          "generatedAt",
          "snapshotAt",
          "validUntil",
          "rows",
          "filters",
          "pagination"
        ],
        "properties": {
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "snapshotAt": {
            "type": "string",
            "format": "date-time",
            "description": "First page anchor retained by the cursor; no historical database snapshot is materialized."
          },
          "validUntil": {
            "type": "string",
            "format": "date-time"
          },
          "rows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MessageFeedRow"
            }
          },
          "filters": {
            "type": "object",
            "required": [
              "devices"
            ],
            "properties": {
              "devices": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "accountId",
                    "name",
                    "ownerEmail",
                    "archived"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "accountId": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "ownerEmail": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Current directory owner; separate from historical row sender identity."
                    },
                    "archived": {
                      "type": "boolean"
                    }
                  }
                },
                "description": "Only phones belonging to the authorized company, including retired phones needed for history filters."
              }
            }
          },
          "pagination": {
            "type": "object",
            "required": [
              "limit",
              "total",
              "nextCursor"
            ],
            "properties": {
              "limit": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100
              },
              "total": {
                "type": "integer",
                "minimum": 0,
                "description": "All currently matching anchored rows before this page cursor; may shrink when rows change after the anchor."
              },
              "nextCursor": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Opaque cursor tied to every normalized filter including limit, expiring after 30 minutes. Null means no further page."
              }
            }
          },
          "emptyReason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "no_messages",
              "filtered",
              null
            ],
            "description": "For an empty list, no_messages means no stored ordinary messages in the authorized scope; filtered means messages exist outside this filter/period. Customer feeds never inspect another account for this value."
          },
          "range": {
            "$ref": "#/components/schemas/HistoryRange"
          }
        }
      },
      "MobileSendingLimits": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version",
          "deviceId",
          "revision",
          "unit",
          "sims"
        ],
        "properties": {
          "version": {
            "type": "integer",
            "const": 1
          },
          "deviceId": {
            "type": "string"
          },
          "revision": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "unit": {
            "type": "string",
            "const": "sms_segments"
          },
          "sims": {
            "type": "array",
            "minItems": 1,
            "maxItems": 8,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "simNumber",
                "second",
                "minute",
                "hour",
                "day",
                "month",
                "intervalSeconds"
              ],
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "second": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "description": "SMS segments in a rolling second. 0 disables only this window."
                },
                "minute": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "description": "SMS segments in a rolling minute. 0 disables only this window."
                },
                "hour": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "description": "0 disables this app cap; carrier restrictions still apply."
                },
                "day": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 100000,
                  "description": "0 disables this app cap; carrier restrictions still apply."
                },
                "month": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 1000000,
                  "description": "Rolling 30 days, independent of a carrier billing cycle. 0 disables this app cap; carrier restrictions still apply."
                },
                "intervalSeconds": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 86400,
                  "description": "Additional seconds per SMS segment; 0 removes the additional pause."
                }
              }
            }
          }
        },
        "description": "Effective numerical limits for this authenticated phone. Includes configured SIM slots and fresh physical inventory; a configured absent slot is not proof that a SIM is present. Every enabled rolling window, interval, pause, quiet hours and billing budget applies together. Caps are not guaranteed throughput or carrier permission. No usage or reservation is reset when limits change."
      },
      "MobileSendingLimitsInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "revision",
          "simNumber",
          "limits"
        ],
        "properties": {
          "revision": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "simNumber": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8
          },
          "limits": {
            "type": "object",
            "additionalProperties": false,
            "minProperties": 1,
            "properties": {
              "second": {
                "type": "integer",
                "minimum": 0,
                "maximum": 10000,
                "description": "SMS segments in a rolling second. 0 disables only this window."
              },
              "minute": {
                "type": "integer",
                "minimum": 0,
                "maximum": 10000,
                "description": "SMS segments in a rolling minute. 0 disables only this window."
              },
              "hour": {
                "type": "integer",
                "minimum": 0,
                "maximum": 10000,
                "description": "0 disables this app cap; carrier restrictions still apply."
              },
              "day": {
                "type": "integer",
                "minimum": 0,
                "maximum": 100000,
                "description": "0 disables this app cap; carrier restrictions still apply."
              },
              "month": {
                "type": "integer",
                "minimum": 0,
                "maximum": 1000000,
                "description": "Rolling 30 days, independent of a carrier billing cycle. 0 disables this app cap; carrier restrictions still apply."
              },
              "intervalSeconds": {
                "type": "integer",
                "minimum": 0,
                "maximum": 86400,
                "description": "Additional seconds per SMS segment; 0 removes the additional pause."
              }
            }
          }
        },
        "description": "Partial numerical patch for one configured or freshly observed SIM. Use the last GET revision. Does not accept account/device selectors, pause, routing, circuit reset, quiet hours or billing budget changes. 409 policy_changed requires a fresh GET and explicit user retry; never silently overwrite another editor."
      },
      "AdminCompanyDeletionPreview": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "company",
          "revision",
          "canDelete",
          "affectedUsers",
          "blockers"
        ],
        "properties": {
          "company": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "revision": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$",
            "description": "Opaque snapshot hash. Reuse exactly for DELETE; changes require a fresh preview."
          },
          "canDelete": {
            "type": "boolean",
            "description": "True only for a locally archived, ready, empty leaf company with verified empty upstream phone inventory."
          },
          "affectedUsers": {
            "type": "integer",
            "minimum": 0,
            "description": "Unique company owners and members whose sessions end on deletion. User identities and other memberships remain."
          },
          "blockers": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "code",
                "count"
              ],
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "archive_required",
                    "company_unavailable",
                    "child_companies",
                    "projects",
                    "phones",
                    "messages",
                    "incoming_messages",
                    "usage",
                    "integrations",
                    "api_keys",
                    "invitations",
                    "setup_in_progress",
                    "appointments",
                    "other_data",
                    "gateway_unavailable"
                  ]
                },
                "count": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "Number of detected dependencies or obstacles; not a traffic metric."
                }
              }
            }
          }
        }
      },
      "AdminCompanyDeleteInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "confirmation",
          "revision"
        ],
        "properties": {
          "confirmation": {
            "type": "string",
            "description": "Exact company name from the current preview; no trimming or case folding."
          },
          "revision": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        }
      },
      "AdminCompanyDeleteResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "deleted",
          "companyId",
          "detachedUsers",
          "revokedSessions"
        ],
        "properties": {
          "deleted": {
            "type": "boolean",
            "const": true
          },
          "companyId": {
            "type": "string"
          },
          "detachedUsers": {
            "type": "integer",
            "minimum": 0,
            "description": "Owners whose primary tenant_id was cleared; user records are never deleted."
          },
          "revokedSessions": {
            "type": "integer",
            "minimum": 0,
            "description": "Actual number of revoked cookie sessions for company owners and members."
          }
        }
      },
      "AdminActivityFilters": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "q": {
            "type": "string",
            "maxLength": 254
          },
          "accountId": {
            "type": "string",
            "maxLength": 100
          },
          "deviceId": {
            "type": "string",
            "maxLength": 100
          },
          "simNumber": {
            "type": "string",
            "enum": [
              "",
              "1",
              "2",
              "unassigned"
            ]
          },
          "direction": {
            "type": "string",
            "enum": [
              "all",
              "outgoing",
              "incoming"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "all",
              "queued",
              "processing",
              "sent",
              "delivered",
              "received",
              "attention",
              "failed",
              "expired",
              "cancelled",
              "unknown"
            ]
          },
          "period": {
            "type": "string",
            "enum": [
              "1h",
              "24h",
              "7d",
              "30d",
              "all",
              "custom"
            ],
            "default": "all"
          },
          "view": {
            "type": "string",
            "enum": [
              "all",
              "action",
              "waiting",
              "retryable",
              "incoming",
              "webhooks"
            ]
          },
          "from": {
            "type": "string",
            "format": "date",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
            "description": "Inclusive starting calendar date in UTC, not before 1970-01-01 or after today UTC. Required with period=custom."
          },
          "to": {
            "type": "string",
            "format": "date",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
            "description": "Inclusive ending calendar date in UTC, not earlier than from. Future end dates are capped at the current snapshot. Required with period=custom."
          },
          "timeZone": {
            "type": "string",
            "enum": [
              "UTC"
            ],
            "description": "Explicit calendar timezone. Currently only UTC is supported. Required with period=custom."
          }
        },
        "description": "Applied activity filters, without cursor or limit. Empty q/accountId/deviceId/simNumber means unrestricted in a bulk-selection body. view intersects the other filters. unassigned matches only an unresolved/unknown SIM (NULL), not both numbered SIMs."
      },
      "ActivityWebhookState": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "status",
          "pending",
          "failed",
          "delivered",
          "oldestAt",
          "lastError"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "failed",
              "delivered"
            ]
          },
          "pending": {
            "type": "integer",
            "minimum": 0
          },
          "failed": {
            "type": "integer",
            "minimum": 0
          },
          "delivered": {
            "type": "integer",
            "minimum": 0
          },
          "oldestAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastError": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "description": "Delivery of events to the connected project, independent of SMS delivery. Counts aggregate this message’s canonical webhook events; they never multiply SMS rows. oldestAt concerns pending/failed events. No event payload, secret, signature or endpoint is exposed here."
      },
      "ActivityRowOperations": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "waitingKind",
          "eligibleSince",
          "queueAgeMs",
          "retryable",
          "retryReason",
          "action",
          "webhook"
        ],
        "properties": {
          "waitingKind": {
            "type": [
              "string",
              "null"
            ]
          },
          "eligibleSince": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "queueAgeMs": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "retryable": {
            "type": "boolean"
          },
          "retryReason": {
            "type": [
              "string",
              "null"
            ]
          },
          "action": {
            "type": "boolean"
          },
          "webhook": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ActivityWebhookState"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "description": "queueAgeMs measures elapsed eligible waiting from eligibleSince: waiting to send for queued SMS, waiting for the phone outcome after dispatch for processing. Planned future schedule/budget/window waits have null eligibleSince/queueAgeMs. retryable uses the same conservative predicate as bulk resend; it is rechecked when executing. action includes SMS issues and failed/delayed webhook delivery."
      },
      "ActivityReasonCount": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code",
          "count"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "count": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "ActivityCauseGroup": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "type",
          "reason",
          "affectedCount",
          "oldestAt",
          "accountId",
          "accountName",
          "deviceId",
          "simNumber",
          "integrationId",
          "endpoint",
          "filters",
          "reasons",
          "deviceName"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "route",
              "integration"
            ]
          },
          "reason": {
            "type": "string"
          },
          "affectedCount": {
            "type": "integer",
            "minimum": 0
          },
          "oldestAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "accountId": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8
          },
          "integrationId": {
            "type": [
              "string",
              "null"
            ]
          },
          "endpoint": {
            "type": [
              "string",
              "null"
            ]
          },
          "filters": {
            "$ref": "#/components/schemas/AdminActivityFilters"
          },
          "reasons": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ActivityReasonCount"
            }
          },
          "deviceName": {
            "type": [
              "string",
              "null"
            ],
            "description": "Local phone label for a route group; null for integration groups, unknown phones or redacted source metadata."
          }
        },
        "description": "Groups sharing an account/phone/SIM route or an account integration. A group can contain mixed reasons; inspect reasons, not only the headline. filters drill into the matching scope. endpoint is reduced to origin and pathname, never credentials, query or fragment. A missing/unassigned route has no phone action."
      },
      "AdminActivityOperations": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "view",
          "counts",
          "groups",
          "groupTotal",
          "oldestWaitingAt",
          "oldestWaitingAgeMs"
        ],
        "properties": {
          "view": {
            "type": "string",
            "enum": [
              "all",
              "action",
              "waiting",
              "retryable",
              "incoming",
              "webhooks"
            ]
          },
          "counts": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "all",
              "action",
              "waiting",
              "retryable",
              "incoming",
              "webhooks"
            ],
            "properties": {
              "all": {
                "type": "integer",
                "minimum": 0
              },
              "action": {
                "type": "integer",
                "minimum": 0
              },
              "waiting": {
                "type": "integer",
                "minimum": 0
              },
              "retryable": {
                "type": "integer",
                "minimum": 0
              },
              "incoming": {
                "type": "integer",
                "minimum": 0
              },
              "webhooks": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "groups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ActivityCauseGroup"
            },
            "maxItems": 20
          },
          "groupTotal": {
            "type": "integer",
            "minimum": 0
          },
          "oldestWaitingAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "oldestWaitingAgeMs": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          }
        },
        "description": "Work-queue counts respect search/account/phone/SIM and use the selected period for completed events. They ignore direction/status/view and pagination. all is the selected event window; waiting includes current queued/processing across ages. action adds SMS issues and failed or delayed webhook events; a planned wait alone is not an error. retryable is the exact current-period safe retry set. incoming is stored incoming SMS in the period; webhooks contains messages with pending/failed event delivery. groups are the 20 largest groups; groupTotal reports the full count. Oldest waiting excludes future planned waits. Already-retried original failures stay in ordinary history and legacy status counts, but no longer contribute an unresolved SMS action/cause group; their separate webhook issues may still need action."
      },
      "IncomingWebhookDelivery": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "type",
          "status",
          "attempts",
          "createdAt",
          "deliveredAt",
          "nextAttemptAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "message.received"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "delivering",
              "delivered",
              "failed"
            ]
          },
          "attempts": {
            "type": "integer",
            "minimum": 0
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "nextAttemptAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "description": "Safe metadata for the canonical incoming event matching account, device and original event ID. Does not contain event payload, endpoint, headers, signatures or secrets."
      },
      "IncomingWebhookHistory": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "configured",
          "enabled",
          "hasMore",
          "items"
        ],
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "enabled": {
            "type": "boolean"
          },
          "hasMore": {
            "type": "boolean"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/IncomingWebhookDelivery"
            }
          }
        }
      },
      "IncomingDetail": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "incomingMessage",
          "webhooks"
        ],
        "properties": {
          "incomingMessage": {
            "$ref": "#/components/schemas/IncomingMessage"
          },
          "webhooks": {
            "$ref": "#/components/schemas/IncomingWebhookHistory"
          }
        }
      },
      "ConversationContext": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "accountId",
          "accountName",
          "deviceId",
          "deviceName",
          "simNumber",
          "party",
          "replyAvailable"
        ],
        "properties": {
          "accountId": {
            "type": "string"
          },
          "accountName": {
            "type": "string"
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "deviceName": {
            "type": [
              "string",
              "null"
            ]
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8
          },
          "party": {
            "type": [
              "string",
              "null"
            ]
          },
          "replyAvailable": {
            "type": "boolean"
          }
        },
        "description": "Exact account, device, selected SIM and peer derived from the authorized source message. replyAvailable means a known live local route and E.164 peer exist; it does not guarantee send admission or delivery."
      },
      "ConversationRow": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "direction",
          "text",
          "occurredAt",
          "sentAt",
          "deliveredAt",
          "error",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "direction": {
            "type": "string",
            "enum": [
              "incoming",
              "outgoing"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "submitted",
              "sending",
              "sent",
              "delivered",
              "received",
              "failed",
              "expired",
              "cancelled",
              "unknown"
            ]
          }
        },
        "description": "An SMS in the exact conversation. occurredAt is outgoing created_at or incoming stored_at. Equal IDs in the two directions are distinct rows. Redacted rows are excluded."
      },
      "ConversationPage": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "context",
          "limited",
          "rows",
          "nextCursor"
        ],
        "properties": {
          "context": {
            "$ref": "#/components/schemas/ConversationContext"
          },
          "limited": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "redacted",
              "recipient_unknown",
              "device_unknown",
              "sim_unknown",
              null
            ]
          },
          "snapshotAt": {
            "type": "string",
            "format": "date-time"
          },
          "rows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ConversationRow"
            },
            "maxItems": 100
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "description": "limited is non-null when route identity cannot safely be established; then rows is empty, replyAvailable is false and snapshotAt is omitted. No peer, phone or SIM is guessed."
      },
      "AdminOperationSummary": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "actorId",
          "actorName",
          "createdAt",
          "startedAt",
          "completedAt",
          "state",
          "canResume",
          "total",
          "companies",
          "queued",
          "skipped",
          "failed",
          "remaining"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "actorId": {
            "type": "string"
          },
          "actorName": {
            "type": "string"
          },
          "createdAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "startedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "completedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "state": {
            "type": "string",
            "enum": [
              "processing",
              "completed"
            ]
          },
          "canResume": {
            "type": "boolean"
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "companies": {
            "type": "integer",
            "minimum": 0
          },
          "queued": {
            "type": "integer",
            "minimum": 0
          },
          "skipped": {
            "type": "integer",
            "minimum": 0
          },
          "failed": {
            "type": "integer",
            "minimum": 0
          },
          "remaining": {
            "type": "integer",
            "minimum": 0
          }
        },
        "description": "Confirmed administrator resend operation, shared for inspection across service administrators. reviewed-only previews are absent. failed counts admission_failed items; skipped counts other skip reasons. canResume is true only for the original actor on a started incomplete intent. Resume by POST /api/admin/activity/resend with this id as previewId, never by creating a new preview. queued means admitted to the SMS queue, not sent."
      },
      "AdminOperationItem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "position",
          "key",
          "id",
          "accountId",
          "accountName",
          "direction",
          "reason",
          "outcome",
          "messageId",
          "recipient",
          "text"
        ],
        "properties": {
          "position": {
            "type": "integer",
            "minimum": 0,
            "maximum": 999
          },
          "key": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "accountId": {
            "type": [
              "string",
              "null"
            ]
          },
          "accountName": {
            "type": [
              "string",
              "null"
            ]
          },
          "direction": {
            "type": "string",
            "enum": [
              "outgoing",
              "incoming"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "outcome": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "queued",
              "skipped",
              null
            ]
          },
          "messageId": {
            "type": [
              "string",
              "null"
            ]
          },
          "recipient": {
            "type": [
              "string",
              "null"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "description": "Per-message result, in immutable selection order. messageId points to the created/existing retry when available. outcome is null while pending; admission_failed is represented by skipped plus that reason and counted under failed. Recipient/text are safe, current outgoing source metadata (text truncated to 160); incoming or redacted source content is null."
      },
      "AdminOperationPage": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "operations",
          "nextCursor"
        ],
        "properties": {
          "operations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminOperationSummary"
            },
            "maxItems": 100
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "AdminOperationDetail": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "operation",
          "items",
          "nextAfter"
        ],
        "properties": {
          "operation": {
            "$ref": "#/components/schemas/AdminOperationSummary"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AdminOperationItem"
            },
            "maxItems": 100
          },
          "nextAfter": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 999
          }
        }
      },
      "BulkResendItem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "id",
          "direction",
          "accountId",
          "accountName",
          "to",
          "from",
          "text",
          "simNumber",
          "deviceId",
          "status",
          "eligible",
          "reason"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "direction": {
            "type": "string",
            "enum": [
              "outgoing",
              "incoming"
            ]
          },
          "accountId": {
            "type": [
              "string",
              "null"
            ]
          },
          "accountName": {
            "type": [
              "string",
              "null"
            ]
          },
          "to": {
            "type": [
              "string",
              "null"
            ]
          },
          "from": {
            "type": [
              "string",
              "null"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 160
          },
          "simNumber": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 8
          },
          "deviceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "submitted",
              "sending",
              "sent",
              "delivered",
              "received",
              "failed",
              "expired",
              "cancelled",
              "unknown"
            ]
          },
          "eligible": {
            "type": "boolean"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "source_missing",
              "incoming",
              "redacted",
              "already_sent",
              "unknown_outcome",
              "superseded",
              "already_retried",
              "already_active",
              "cancelled",
              "not_failed",
              "expired",
              "scheduled",
              "integration_paused",
              "validation_required",
              "service_message",
              "opted_out",
              "failure_not_confirmed",
              "invalid_message",
              "multipart_uncertain",
              "account_unavailable",
              "account_paused",
              "terms_required",
              "device_unavailable",
              "device_paused",
              "source_cancelled",
              "source_changed",
              "admission_failed",
              null
            ]
          },
          "messageId": {
            "type": "string"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "queued",
              "skipped"
            ]
          }
        },
        "description": "Immutable selection item with live safe source metadata. messageId appears for a created or previously claimed retry. outcome appears only once that item is processed. eligible reflects the preview; execution rechecks all safety conditions."
      },
      "BulkResendPreview": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "previewId",
          "expiresAt",
          "snapshotAt",
          "ttlSeconds",
          "total",
          "eligible",
          "skipped",
          "reasons",
          "accounts",
          "items"
        ],
        "properties": {
          "previewId": {
            "type": "string"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "snapshotAt": {
            "type": "string",
            "format": "date-time"
          },
          "ttlSeconds": {
            "type": "integer",
            "enum": [
              86400
            ]
          },
          "total": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000
          },
          "eligible": {
            "type": "integer",
            "minimum": 0
          },
          "skipped": {
            "type": "integer",
            "minimum": 0
          },
          "queued": {
            "type": "integer",
            "minimum": 0
          },
          "state": {
            "type": "string",
            "enum": [
              "processing",
              "completed"
            ]
          },
          "reasons": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ActivityReasonCount"
            }
          },
          "accounts": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "id",
                "name",
                "count"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "count": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            }
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BulkResendItem"
            },
            "minItems": 1,
            "maxItems": 1000
          }
        },
        "description": "Actor-owned preview and resumable result. Unstarted previews expire after ten minutes. Started/completed intent retains durable results and can be safely replayed. queued/state appear after execution starts. accounts counts preview-eligible sources by account. ttlSeconds is the new retry lifetime, not the preview lifetime."
      },
      "BulkResendSelection": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mode",
              "keys"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "const": "ids"
              },
              "keys": {
                "type": "array",
                "items": {
                  "type": "string",
                  "maxLength": 220,
                  "pattern": "^(incoming|outgoing):[^\\x00-\\x20]+$"
                },
                "minItems": 1,
                "maxItems": 1000
              },
              "snapshotAt": {
                "type": "string",
                "format": "date-time",
                "description": "Optional activity.snapshotAt; must be no more than 30 minutes old and not in the future. Freezes the selection time boundary, not the database contents."
              }
            }
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mode"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "const": "filter"
              },
              "filters": {
                "$ref": "#/components/schemas/AdminActivityFilters"
              },
              "excludeKeys": {
                "type": "array",
                "items": {
                  "type": "string",
                  "maxLength": 220,
                  "pattern": "^(incoming|outgoing):[^\\x00-\\x20]+$"
                },
                "maxItems": 1000
              },
              "snapshotAt": {
                "type": "string",
                "format": "date-time",
                "description": "Optional activity.snapshotAt; must be no more than 30 minutes old and not in the future. Freezes the selection time boundary, not the database contents."
              }
            }
          }
        ],
        "description": "Select explicit keys or all matching filters. Duplicate explicit keys collapse to one item. Selection is fixed on preview creation and never grows with later arrivals. No pagination fields are accepted in filters."
      },
      "HistoryRange": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "period"
            ],
            "properties": {
              "period": {
                "type": "string",
                "enum": [
                  "1h",
                  "24h",
                  "7d",
                  "30d",
                  "all"
                ]
              }
            }
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "period",
              "from",
              "to",
              "timeZone"
            ],
            "properties": {
              "period": {
                "const": "custom"
              },
              "from": {
                "type": "string",
                "format": "date",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                "description": "Inclusive starting calendar date in UTC, not before 1970-01-01 or after today UTC. Required with period=custom."
              },
              "to": {
                "type": "string",
                "format": "date",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                "description": "Inclusive ending calendar date in UTC, not earlier than from. Future end dates are capped at the current snapshot. Required with period=custom."
              },
              "timeZone": {
                "type": "string",
                "enum": [
                  "UTC"
                ],
                "description": "Explicit calendar timezone. Currently only UTC is supported. Required with period=custom."
              }
            }
          }
        ]
      },
      "CompanySenderReceipt": {
        "type": "object",
        "required": [
          "id",
          "version",
          "language",
          "sha256",
          "acceptedAt",
          "partyType",
          "kind",
          "scope"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "actorId": {
            "type": "string"
          },
          "actorEmail": {
            "type": "string"
          },
          "actorName": {
            "type": "string"
          },
          "customerName": {
            "type": "string"
          },
          "signatoryName": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "language": {
            "type": "string"
          },
          "sha256": {
            "type": "string"
          },
          "acceptedAt": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "type": "string"
          },
          "authority": {
            "const": 1
          },
          "clientResponsibility": {
            "const": 1
          },
          "partyType": {
            "enum": [
              "individual",
              "business"
            ]
          },
          "kind": {
            "const": "company"
          },
          "scope": {
            "const": "workspace"
          }
        },
        "description": "The actual owner’s own Sender Agreement undertaking for workspace accounts. Never a personal customer signature. Native/setup responses minimize actor and identity data."
      },
      "SenderPolicy": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "enum": [
              "company",
              "customer"
            ]
          },
          "revision": {
            "type": "integer",
            "minimum": 0
          },
          "canChange": {
            "type": "boolean"
          },
          "companyReceipt": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/CompanySenderReceipt"
              },
              {
                "type": "null"
              }
            ]
          },
          "terms": {
            "$ref": "#/components/schemas/ServiceTermsDescriptor"
          },
          "history": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "receipts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CompanySenderReceipt"
            }
          }
        },
        "required": [
          "mode",
          "revision",
          "companyReceipt"
        ]
      },
      "OwnerTermsGrant": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "signingToken",
              "expiresAt",
              "identity",
              "mode",
              "policyRevision",
              "integrator",
              "sender",
              "mfaRequired"
            ],
            "properties": {
              "signingToken": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_-]{43}$"
              },
              "expiresAt": {
                "type": "string",
                "format": "date-time",
                "description": "Original email challenge expiry; only the remaining portion of its ten-minute lifetime is available."
              },
              "identity": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "partyType": {
                    "enum": [
                      "individual",
                      "business"
                    ]
                  },
                  "customerName": {
                    "type": "string"
                  },
                  "signatoryName": {
                    "type": "string"
                  }
                },
                "required": [
                  "partyType",
                  "customerName",
                  "signatoryName"
                ]
              },
              "mode": {
                "enum": [
                  "company",
                  "customer"
                ]
              },
              "policyRevision": {
                "type": "integer",
                "minimum": 0
              },
              "integrator": {
                "$ref": "#/components/schemas/OwnerAgreementDocument"
              },
              "sender": {
                "$ref": "#/components/schemas/OwnerAgreementDocument"
              },
              "mfaRequired": {
                "type": "boolean"
              }
            }
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "accepted"
            ],
            "properties": {
              "accepted": {
                "const": true
              }
            }
          }
        ]
      },
      "OwnerAgreementDocument": {
        "type": "object",
        "required": [
          "kind",
          "version",
          "accepted",
          "documents"
        ],
        "properties": {
          "kind": {
            "enum": [
              "integrator",
              "sender"
            ]
          },
          "version": {
            "type": "string"
          },
          "accepted": {
            "type": "boolean"
          },
          "documents": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "sha256",
                "url"
              ],
              "properties": {
                "sha256": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "OwnerTermsChallenge": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "challengeId",
          "expiresAt",
          "maskedEmail",
          "delivery",
          "alreadyVerified",
          "alreadyAccepted",
          "language"
        ],
        "properties": {
          "challengeId": {
            "type": "string",
            "format": "uuid"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "maskedEmail": {
            "type": "string"
          },
          "delivery": {
            "enum": [
              "pending",
              "sending",
              "sent",
              "failed",
              "expired"
            ]
          },
          "alreadyVerified": {
            "type": "boolean"
          },
          "alreadyAccepted": {
            "type": "boolean"
          },
          "language": {
            "enum": [
              "en",
              "ru"
            ]
          }
        }
      },
      "OwnerTermsStatus": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "available",
          "required",
          "mfaRequired",
          "challenge"
        ],
        "properties": {
          "available": {
            "type": "boolean"
          },
          "required": {
            "type": "boolean"
          },
          "mfaRequired": {
            "type": "boolean"
          },
          "challenge": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/OwnerTermsChallenge"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "OwnerTermsAcceptance": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "accepted",
          "acceptanceSource",
          "verifiedAt",
          "acceptedAt",
          "policyRevision"
        ],
        "properties": {
          "accepted": {
            "const": true
          },
          "acceptanceSource": {
            "const": "owner"
          },
          "verifiedAt": {
            "type": "string",
            "format": "date-time"
          },
          "acceptedAt": {
            "type": "string",
            "format": "date-time"
          },
          "policyRevision": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "OwnerIntegratorConsent": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version",
          "language",
          "sha256",
          "accepted",
          "authority",
          "clientResponsibility",
          "signatoryName",
          "partyType"
        ],
        "properties": {
          "version": {
            "type": "string"
          },
          "language": {
            "enum": [
              "en",
              "ru"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "accepted": {
            "const": true
          },
          "authority": {
            "const": true
          },
          "clientResponsibility": {
            "const": true
          },
          "customerName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160,
            "description": "Business legal name required for business. For individual, omit or repeat signatoryName; normalized to full name."
          },
          "signatoryName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160
          },
          "partyType": {
            "enum": [
              "individual",
              "business"
            ],
            "description": "Declared personal capacity or authorized company/sole proprietor. Actual statutory consumer status depends on law and use."
          }
        },
        "description": "Restricted native owner consent for the current integrator document and existing verified identity. Responsibility mode, policy revision and nested senderTerms fields are forbidden; the owner grant fixes policy and document scope.",
        "allOf": [
          {
            "if": {
              "properties": {
                "partyType": {
                  "const": "business"
                }
              },
              "required": [
                "partyType"
              ]
            },
            "then": {
              "required": [
                "customerName"
              ]
            }
          }
        ]
      },
      "OwnerMobileEvidence": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "owner_id": {
            "type": "string"
          },
          "account_id": {
            "type": "string"
          },
          "project_id": {
            "type": "string"
          },
          "session_hash": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "verified_at": {
            "type": "string",
            "format": "date-time"
          },
          "accepted_at": {
            "type": "string",
            "format": "date-time"
          },
          "policy_mode": {
            "enum": [
              "company",
              "customer"
            ]
          },
          "documents": {
            "type": "string",
            "description": "JSON-encoded array of exact accepted document kind, version, language and sha256; the immutable audit export preserves its stored representation."
          },
          "policy_revision": {
            "type": "integer",
            "minimum": 0
          },
          "mfa_verified": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "integrator_receipt_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "company_receipt_id": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "workspace_id",
          "owner_id",
          "account_id",
          "project_id",
          "session_hash",
          "verified_at",
          "accepted_at",
          "policy_mode",
          "documents",
          "policy_revision",
          "mfa_verified",
          "integrator_receipt_id",
          "company_receipt_id"
        ],
        "description": "Owner/admin-only immutable evidence. Snake-case fields match the stored audit export. session_hash is a one-way correlation digest, never a signing capability."
      },
      "SimCatalogFact": {
        "type": "object",
        "description": "A catalog fact. value is null unless status is verified or needs_review; stale means older than its allowed age.",
        "properties": {
          "value": {},
          "status": {
            "enum": [
              "verified",
              "not_found",
              "not_applicable",
              "needs_review"
            ]
          },
          "checkedAt": {
            "type": "string",
            "format": "date"
          },
          "stale": {
            "type": "boolean"
          },
          "note": {
            "type": [
              "string",
              "null"
            ],
            "description": "Explanation in Russian."
          },
          "reviewReason": {
            "type": "string"
          },
          "evidence": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "quote": {
                  "type": "string"
                },
                "locator": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "url": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uri"
                },
                "publisher": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "title": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "quote",
                "locator",
                "url",
                "publisher",
                "title"
              ]
            }
          }
        },
        "required": [
          "value",
          "status",
          "checkedAt",
          "stale",
          "note",
          "evidence"
        ]
      },
      "DeviceSimCatalog": {
        "type": "object",
        "description": "Carrier of each SIM from the SendHarbor SIM catalog (docs/sim-catalog.md). Information from public sources only: not carrier permission, never a limit or a sending block.",
        "properties": {
          "version": {
            "const": 1
          },
          "observedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the phone collected the SIM data."
          },
          "sims": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "simNumber": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "carrierName": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "match": {
                  "enum": [
                    "carrier_id",
                    "network_code",
                    "ambiguous",
                    "not_in_catalog",
                    "no_network_data"
                  ],
                  "description": "carrier_id and network_code found one operator; ambiguous lists candidates sharing the network code; no_network_data means the phone sent neither a carrier ID nor a network code."
                },
                "candidates": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "country": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "id",
                      "name",
                      "country"
                    ]
                  }
                },
                "operator": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "localName": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "kind": {
                      "enum": [
                        "mno",
                        "mvno"
                      ]
                    },
                    "country": {
                      "type": "string"
                    },
                    "countryName": {
                      "type": "string"
                    },
                    "currency": {
                      "type": "string"
                    },
                    "host": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    },
                    "automation": {
                      "$ref": "#/components/schemas/SimCatalogFact",
                      "description": "value: prohibited, restricted, requires_agreement, allowed or unclear."
                    },
                    "business": {
                      "$ref": "#/components/schemas/SimCatalogFact"
                    },
                    "plans": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "note": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "payment": {
                            "$ref": "#/components/schemas/SimCatalogFact"
                          },
                          "fee": {
                            "$ref": "#/components/schemas/SimCatalogFact"
                          },
                          "smsIncluded": {
                            "$ref": "#/components/schemas/SimCatalogFact"
                          },
                          "smsPrice": {
                            "$ref": "#/components/schemas/SimCatalogFact"
                          },
                          "dailyLimit": {
                            "$ref": "#/components/schemas/SimCatalogFact"
                          },
                          "monthlyLimit": {
                            "$ref": "#/components/schemas/SimCatalogFact"
                          },
                          "esim": {
                            "$ref": "#/components/schemas/SimCatalogFact"
                          },
                          "registration": {
                            "$ref": "#/components/schemas/SimCatalogFact"
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "note",
                          "payment",
                          "fee",
                          "smsIncluded",
                          "smsPrice",
                          "dailyLimit",
                          "monthlyLimit",
                          "esim",
                          "registration"
                        ]
                      }
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "localName",
                    "kind",
                    "country",
                    "countryName",
                    "currency",
                    "host",
                    "automation",
                    "business",
                    "plans"
                  ]
                }
              },
              "required": [
                "simNumber",
                "carrierName",
                "match"
              ]
            }
          }
        },
        "required": [
          "version",
          "observedAt",
          "sims"
        ]
      },
      "QuickStartConfig": {
        "type": "object",
        "properties": {
          "enabled": {
            "type": "boolean",
            "description": "Self-registration is on and email works. When false, email and verify answer 403 registration_disabled."
          },
          "languages": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "en",
                "ru",
                "uk"
              ]
            }
          },
          "androidPackages": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Android application IDs allowed in the pairing intent. Default com.sendharbor.gateway; QUICK_START_ANDROID_PACKAGES overrides it."
          },
          "termsUrl": {
            "type": "string"
          },
          "privacyUrl": {
            "type": "string"
          },
          "termsVersion": {
            "type": "string",
            "description": "Current integration terms version to send back in verify."
          },
          "senderTermsVersion": {
            "type": "string",
            "description": "Current Sender Agreement version to send back in verify. A new owner accepts it for the workspace's own accounts (company mode)."
          },
          "senderTermsUrls": {
            "type": "object",
            "description": "The exact Sender Agreement document per language, only for languages that exist. There is no Ukrainian document; a Ukrainian page links and records the English one.",
            "properties": {
              "en": {
                "type": "string"
              },
              "ru": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "required": [
          "enabled",
          "languages",
          "androidPackages",
          "termsUrl",
          "privacyUrl",
          "termsVersion",
          "senderTermsVersion",
          "senderTermsUrls"
        ],
        "additionalProperties": false
      },
      "QuickStartEmailRequest": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "language": {
            "type": "string",
            "enum": [
              "en",
              "ru",
              "uk"
            ],
            "description": "Email language. Defaults to Accept-Language, then en."
          }
        },
        "required": [
          "email"
        ],
        "additionalProperties": false
      },
      "QuickStartChallenge": {
        "type": "object",
        "properties": {
          "challengeId": {
            "type": "string",
            "format": "uuid"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "description": "10 minutes after the request."
          },
          "resendAfter": {
            "type": "string",
            "format": "date-time",
            "description": "A new code for this address is refused with 429 resend_too_soon until then (60 seconds)."
          }
        },
        "required": [
          "challengeId",
          "expiresAt",
          "resendAfter"
        ],
        "additionalProperties": false
      },
      "QuickStartVerifyRequest": {
        "type": "object",
        "properties": {
          "challengeId": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string",
            "pattern": "^\\d{6}$"
          },
          "purpose": {
            "type": "string",
            "enum": [
              "personal",
              "business"
            ],
            "description": "Required for a new address. personal records the integration terms with party individual, business with party business."
          },
          "companyName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160,
            "description": "Required with purpose business; it becomes the workspace name and the contracting party."
          },
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160,
            "description": "Required for a new address (400 invalid_name otherwise): full name of the person who accepts. It is the signatory of both the integration terms and the Sender Agreement; for purpose personal it is also the contracting party and the workspace name."
          },
          "acceptTerms": {
            "type": "boolean",
            "description": "Must be true for a new address (428 terms_acceptance_required otherwise). One box accepts the integration terms and the Sender Agreement."
          },
          "termsVersion": {
            "type": "string",
            "description": "Must equal QuickStartConfig.termsVersion for a new address (409 terms_version_changed otherwise)."
          },
          "senderTermsVersion": {
            "type": "string",
            "description": "Must equal QuickStartConfig.senderTermsVersion for a new address (409 terms_version_changed otherwise)."
          }
        },
        "required": [
          "challengeId",
          "code"
        ],
        "additionalProperties": false
      },
      "QuickStartSession": {
        "type": "object",
        "properties": {
          "account": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "name"
            ],
            "additionalProperties": false
          },
          "created": {
            "type": "boolean"
          },
          "csrfToken": {
            "type": "string",
            "description": "Send as X-CSRF-Token with the session cookie set by this answer."
          }
        },
        "required": [
          "account",
          "created",
          "csrfToken"
        ],
        "additionalProperties": false
      },
      "QuickStartPairingRequest": {
        "type": "object",
        "properties": {
          "androidPackage": {
            "type": "string",
            "description": "One of QuickStartConfig.androidPackages."
          },
          "language": {
            "type": "string",
            "enum": [
              "en",
              "ru",
              "uk"
            ],
            "description": "Funnel language. Defaults to Accept-Language."
          }
        },
        "required": [
          "androidPackage"
        ],
        "additionalProperties": false
      },
      "QuickStartPairing": {
        "type": "object",
        "properties": {
          "pairingId": {
            "type": "string",
            "format": "uuid"
          },
          "enrollmentPayload": {
            "$ref": "#/components/schemas/EnrollmentPayload"
          },
          "intentUrl": {
            "type": "string",
            "description": "intent://pair#Intent;scheme=sendharbor;package=<androidPackage>;S.enrollment=<base64url(JSON enrollmentPayload)>;S.browser_fallback_url=<urlencoded PUBLIC_URL/download>;end"
          },
          "pasteCode": {
            "type": "string",
            "pattern": "^SH1:[A-Za-z0-9_-]+$",
            "description": "SH1: followed by base64url(JSON enrollmentPayload)."
          },
          "qrDataUrl": {
            "type": "string",
            "description": "PNG data URL of the same enrollment for a computer screen."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "description": "20 minutes after issue."
          }
        },
        "required": [
          "pairingId",
          "enrollmentPayload",
          "intentUrl",
          "pasteCode",
          "qrDataUrl",
          "expiresAt"
        ],
        "additionalProperties": false
      },
      "QuickStartPairingState": {
        "type": "object",
        "properties": {
          "state": {
            "type": "string",
            "enum": [
              "pending",
              "linked",
              "expired"
            ]
          },
          "deviceId": {
            "type": "string",
            "description": "Only when linked."
          },
          "phoneNumber": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$",
            "description": "Only when linked and the phone reported its own SIM number in diagnostics."
          }
        },
        "required": [
          "state"
        ],
        "additionalProperties": false
      },
      "QuickStartIntegrationRequest": {
        "type": "object",
        "properties": {
          "integration": {
            "type": "string",
            "enum": [
              "curl",
              "sheets",
              "n8n",
              "make",
              "woocommerce",
              "bitrix24",
              "node",
              "python",
              "php"
            ]
          },
          "deviceId": {
            "type": "string",
            "maxLength": 100
          },
          "testPhone": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$",
            "description": "Defaults to the phone's own SIM number; required when the phone did not report it (400 test_phone_required)."
          },
          "language": {
            "type": "string",
            "enum": [
              "en",
              "ru",
              "uk"
            ],
            "description": "Language of the test text. Defaults to Accept-Language."
          }
        },
        "required": [
          "integration",
          "deviceId"
        ],
        "additionalProperties": false
      },
      "QuickStartIntegration": {
        "type": "object",
        "properties": {
          "apiKey": {
            "type": "string",
            "pattern": "^sgk_[A-Za-z0-9_-]{43}$",
            "description": "Ordinary live key \"Quick start · <integration>\" with messages:send and messages:read. Shown only in this answer."
          },
          "baseUrl": {
            "type": "string",
            "format": "uri"
          },
          "deviceId": {
            "type": "string"
          },
          "marker": {
            "type": "string",
            "pattern": "^qs_[0-9a-f]{16}$"
          },
          "testPhone": {
            "type": "string"
          },
          "text": {
            "type": "string",
            "description": "Localized \"SendHarbor: integration works\" followed by the marker."
          },
          "checkId": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "apiKey",
          "baseUrl",
          "deviceId",
          "marker",
          "testPhone",
          "text",
          "checkId"
        ],
        "additionalProperties": false,
        "description": "Snippet body for POST {baseUrl}/api/messages with Authorization: Bearer {apiKey}: {\"deviceId\",\"phone\":testPhone,\"text\",\"idempotencyKey\":marker,\"externalId\":marker} (MessageInput)."
      },
      "QuickStartCheck": {
        "type": "object",
        "properties": {
          "keyUsed": {
            "type": "boolean"
          },
          "request": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "at": {
                "type": "string",
                "format": "date-time"
              },
              "messageId": {
                "type": "string"
              }
            },
            "required": [
              "at",
              "messageId"
            ],
            "additionalProperties": false,
            "description": "The account's message with externalId equal to the marker."
          },
          "phoneSent": {
            "type": "boolean"
          },
          "delivered": {
            "type": "boolean"
          },
          "incomingLoop": {
            "type": "boolean",
            "description": "The same phone received an SMS with the marker from testPhone after the request."
          },
          "selfTest": {
            "type": "boolean",
            "description": "testPhone is the own SIM number the test phone reported, so the phone should receive the test SMS back (incomingLoop)."
          },
          "error": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "code": {
                "type": "string",
                "pattern": "^(key_not_used|wrong_device|phone_offline|sms_permission|recipient_opted_out|message_failed:[A-Za-z0-9_]+)$"
              },
              "hint": {
                "type": "string",
                "description": "Next step in the language chosen for the integration."
              }
            },
            "required": [
              "code",
              "hint"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "keyUsed",
          "request",
          "phoneSent",
          "delivered",
          "incomingLoop",
          "selfTest",
          "error"
        ],
        "additionalProperties": false
      },
      "QuickStartEvent": {
        "type": "object",
        "properties": {
          "step": {
            "type": "string",
            "enum": [
              "start_opened",
              "email_sent",
              "email_verified",
              "purpose_personal",
              "purpose_business",
              "pairing_issued",
              "phone_linked",
              "integration_selected",
              "snippet_copied",
              "check_started",
              "first_request",
              "first_sms_sent",
              "delivered"
            ]
          },
          "src": {
            "type": "string",
            "enum": [
              "app",
              "web"
            ]
          },
          "language": {
            "type": "string",
            "enum": [
              "en",
              "ru",
              "uk"
            ]
          },
          "sid": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{8,64}$",
            "description": "Random id of the browser tab. Kept only as a keyed hash until the next day."
          }
        },
        "required": [
          "step",
          "src",
          "language",
          "sid"
        ],
        "additionalProperties": false,
        "description": "email_sent, email_verified, pairing_issued, phone_linked, first_request, first_sms_sent and delivered are counted by the server; a page report of them adds only its session."
      },
      "QuickStartFunnel": {
        "type": "object",
        "properties": {
          "days": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string",
                  "format": "date"
                },
                "steps": {
                  "type": "object",
                  "properties": {
                    "start_opened": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "email_sent": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "email_verified": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "purpose_personal": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "purpose_business": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "pairing_issued": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "phone_linked": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "integration_selected": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "snippet_copied": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "check_started": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "first_request": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "first_sms_sent": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    },
                    "delivered": {
                      "$ref": "#/components/schemas/QuickStartFunnelCount"
                    }
                  },
                  "required": [
                    "start_opened",
                    "email_sent",
                    "email_verified",
                    "purpose_personal",
                    "purpose_business",
                    "pairing_issued",
                    "phone_linked",
                    "integration_selected",
                    "snippet_copied",
                    "check_started",
                    "first_request",
                    "first_sms_sent",
                    "delivered"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "date",
                "steps"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "days"
        ],
        "additionalProperties": false
      },
      "QuickStartFunnelCount": {
        "type": "object",
        "properties": {
          "events": {
            "type": "integer",
            "minimum": 0
          },
          "sessions": {
            "type": "integer",
            "minimum": 0,
            "description": "Distinct tab sids of that day that reported the step."
          }
        },
        "required": [
          "events",
          "sessions"
        ],
        "additionalProperties": false
      },
      "QuickStartState": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "signedIn": {
                "const": false
              }
            },
            "required": [
              "signedIn"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "signedIn": {
                "const": true
              },
              "account": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "id",
                  "name"
                ],
                "additionalProperties": false
              },
              "purpose": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "personal",
                  "business",
                  null
                ],
                "description": "From the party of the account's latest integration terms receipt: individual is personal, business is business; null without a receipt."
              },
              "pairing": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "state": {
                    "type": "string",
                    "enum": [
                      "pending",
                      "linked",
                      "expired"
                    ]
                  },
                  "deviceId": {
                    "type": "string"
                  },
                  "phoneNumber": {
                    "type": "string",
                    "pattern": "^\\+[1-9]\\d{6,14}$"
                  }
                },
                "required": [
                  "id",
                  "state"
                ],
                "additionalProperties": false,
                "description": "The latest quick start pairing of this account, as GET /api/quick-start/pairing/{id} reports it."
              },
              "devices": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "phoneNumber": {
                      "type": "string",
                      "pattern": "^\\+[1-9]\\d{6,14}$",
                      "description": "Own SIM number from the phone's latest diagnostics, when reported."
                    },
                    "online": {
                      "type": "boolean",
                      "description": "Gateway poll or diagnostics upload within the last 5 minutes."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "online"
                  ],
                  "additionalProperties": false
                },
                "description": "The account's linked, not revoked phones. A page can skip pairing when one is linked."
              },
              "lastCheck": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "checkId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "integration": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "waiting",
                      "requested",
                      "sent",
                      "delivered",
                      "failed"
                    ],
                    "description": "waiting: no SMS with the marker yet; requested: accepted, not yet sent; failed: Failed, rejected, expired, cancelled or unknown."
                  },
                  "selfTest": {
                    "type": "boolean",
                    "description": "As in GET /api/quick-start/check/{checkId}: the test number is the phone's own SIM number."
                  }
                },
                "required": [
                  "checkId",
                  "integration",
                  "status",
                  "selfTest"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "signedIn",
              "account",
              "purpose",
              "pairing",
              "devices",
              "lastCheck"
            ],
            "additionalProperties": false
          }
        ]
      }
    }
  },
  "paths": {
    "/api/login": {
      "post": {
        "summary": "Войти",
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string",
                    "format": "password"
                  }
                },
                "required": [
                  "email",
                  "password"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "202": {
            "description": "Password accepted; complete MFA before any authenticated session is issued. Challenge expires in 5 minutes and allows at most 5 attempts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MfaChallenge"
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/session": {
      "get": {
        "summary": "Текущая сессия и CSRF token",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/logout": {
      "post": {
        "summary": "Выйти и отозвать сессию",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "responses": {
          "204": {
            "description": "Успешно"
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/password": {
      "post": {
        "summary": "Изменить пароль и отозвать все сессии",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "currentPassword": {
                    "type": "string",
                    "format": "password"
                  },
                  "newPassword": {
                    "type": "string",
                    "format": "password",
                    "minLength": 12,
                    "maxLength": 256
                  },
                  "code": {
                    "type": "string",
                    "description": "Required when MFA is enabled: a fresh TOTP or unused recovery code."
                  }
                },
                "required": [
                  "currentPassword",
                  "newPassword"
                ]
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Успешно"
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/tenants": {
      "get": {
        "summary": "Клиенты (только admin)",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tenants": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Tenant"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Создать клиента и его аккаунт",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string",
                    "format": "password",
                    "minLength": 12,
                    "maxLength": 256
                  }
                },
                "required": [
                  "name",
                  "email",
                  "password"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tenant": {
                      "$ref": "#/components/schemas/Tenant"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices": {
      "get": {
        "summary": "List the account's phones; devices:read",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "devices": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Device"
                      }
                    },
                    "gatewayAvailable": {
                      "type": "boolean"
                    },
                    "warning": {
                      "type": "string"
                    },
                    "metrics": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/MessageMetrics"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Whole selected-workspace ordinary message metrics, independently of gateway availability. Requires messages:read in addition to devices:read for API keys; otherwise null. The device list is not narrowed. Admin selects tenantId; customer/managed sessions remain tenant-scoped."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Returns the full selected-tenant phone list. Adds privacy-limited sending runtime and workspace message metrics when messages:read is available; never narrows the phone list for these projections. Runtime is read-only and bounded, may be unavailable, and expires within 30 seconds. Gateway outage returns cached devices with unavailable runtime. Admin chooses tenantId; customer and managed sessions can only read their own tenant."
      }
    },
    "/api/devices/{id}": {
      "delete": {
        "summary": "Revoke a phone; devices:write",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "204": {
            "description": "Успешно"
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/pairings": {
      "post": {
        "summary": "Create QR with optional webhook; devices:write, plus integrations:write with webhook",
        "description": "Create a direct QR or use POST /api/onboarding-sessions for a hosted/embedded setup wizard. A QR can be issued before the applicable Sender Agreement has been accepted. The workspace policy determines whether its owner accepts sender obligations for covered accounts or each customer accepts individually. Actual device enrollment returns 428 until the required agreements are accepted; acceptance resumes the same unexpired, unrevoked QR with its original enrollment recovery proof. Creating a new pairing still requires the integrator agreement. PUBLIC_URL must use HTTPS. QR expires after 1200 seconds by default; static QR has no expiry and enrolls one phone. Optional email is trimmed/lowercased and attached to the enrolled phone; it does not create a portal account or verify email ownership. The API key defines the tenant. Email stays out of QR and mobile registration. Optional webhook atomically creates or reuses an enabled integration and requires idempotencyKey (optional for plain QR). Request identity includes serverUrl from PUBLIC_URL. Identical pending replay returns 200 with the same QR and original expiry. Canonical comparison includes email, mode, TTL, endpoint, secret and serverUrl derived from PUBLIC_URL. GET never reveals QR codes; no API response echoes signing secrets. Integration configuration changes invalidate automatic QR. Successful enrollment atomically queues signed device.status linked with pairingId for correlation. Revoked includes the original pairingId when known; consumers must persist terminal revocation and reject a later linked event for the same pairing. SendHarbor Android 1.4.0 remains compatible. Maximum 20 active QR and 30 creations per 15 minutes. See docs/pairing-api.md. A webhook supplied by an ordinary cookie user additionally requires project owner authority. Issuer authority is rechecked after asynchronous enrollment/QR work; revocation invalidates unused capabilities. Fresh-QR recovery of a previously registered phone does not emit another linked event: GET this pairing or poll its onboarding session for linked and the existing deviceId. A direct QR may be created before Sender Agreement acceptance; actual enrollment remains428 until the required owner/customer accepts. Keep the same enrollment recovery proof through native acceptance and retry.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "mode": {
                        "const": "temporary",
                        "default": "temporary"
                      },
                      "ttlSeconds": {
                        "type": "integer",
                        "minimum": 60,
                        "maximum": 86400,
                        "default": 1200
                      },
                      "email": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 254,
                        "description": "Необязательный адрес пользователя платформы. Внешние пробелы удаляются, адрес приводится к нижнему регистру и проверяется как email; точки/+suffix сохраняются. null/пустая строка/неверный адрес → 400. Отсутствие поля сохраняет прежнее подключение без контакта.",
                        "examples": [
                          "alex@clinic.example",
                          "  Alex@Clinic.Example  "
                        ]
                      },
                      "webhook": {
                        "$ref": "#/components/schemas/PairingWebhookInput"
                      },
                      "idempotencyKey": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128,
                        "pattern": "^[A-Za-z0-9._:-]{1,128}$",
                        "description": "Required with webhook, optional otherwise. Persistent attempt key scoped to tenant. Save before HTTP request; repeat with same content after uncertain response. Not trimmed. New QR requires a new key."
                      },
                      "principalId": {
                        "type": "string",
                        "pattern": "^[A-Za-z0-9._:-]{1,128}$"
                      }
                    },
                    "dependentRequired": {
                      "webhook": [
                        "idempotencyKey"
                      ]
                    }
                  },
                  {
                    "type": "object",
                    "required": [
                      "mode"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "mode": {
                        "const": "static"
                      },
                      "email": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 254,
                        "description": "Необязательный адрес пользователя платформы. Внешние пробелы удаляются, адрес приводится к нижнему регистру и проверяется как email; точки/+suffix сохраняются. null/пустая строка/неверный адрес → 400. Отсутствие поля сохраняет прежнее подключение без контакта.",
                        "examples": [
                          "alex@clinic.example",
                          "  Alex@Clinic.Example  "
                        ]
                      },
                      "webhook": {
                        "$ref": "#/components/schemas/PairingWebhookInput"
                      },
                      "idempotencyKey": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128,
                        "pattern": "^[A-Za-z0-9._:-]{1,128}$",
                        "description": "Required with webhook, optional otherwise. Persistent attempt key scoped to tenant. Save before HTTP request; repeat with same content after uncertain response. Not trimmed. New QR requires a new key."
                      },
                      "principalId": {
                        "type": "string",
                        "pattern": "^[A-Za-z0-9._:-]{1,128}$"
                      }
                    },
                    "dependentRequired": {
                      "webhook": [
                        "idempotencyKey"
                      ]
                    }
                  }
                ]
              },
              "examples": {
                "platformUser": {
                  "summary": "Подключить телефон пользователя платформы, QR на 20 минут по умолчанию",
                  "value": {
                    "email": "alex@clinic.example"
                  }
                },
                "temporary": {
                  "summary": "Явный срок 20 минут",
                  "value": {
                    "email": "alex@clinic.example",
                    "ttlSeconds": 1200
                  }
                },
                "static": {
                  "summary": "Бессрочный QR для одного телефона",
                  "value": {
                    "mode": "static",
                    "email": "alex@clinic.example"
                  }
                },
                "legacy": {
                  "summary": "Прежнее подключение без контакта платформы",
                  "value": {}
                },
                "automaticWebhook": {
                  "summary": "Automatic webhook; generate and save a random secret before calling",
                  "value": {
                    "email": "alex@clinic.example",
                    "ttlSeconds": 1200,
                    "idempotencyKey": "onboarding-8e2c9709-0f13-4cba-8d46-9c7aa734d71e",
                    "webhook": {
                      "endpoint": "https://magenda.example/api/v1/webhooks/sms-gateway/{integrationId}",
                      "secret": "exampleOnlyReplaceWithRandomSecretNotForRealUse"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Identical pending replay: same QR, original expiry and integration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PairingCreated"
                }
              }
            }
          },
          "201": {
            "description": "QR created with integration when requested. No signing secret in response.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PairingCreated"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request fields, invalid_webhook_options, invalid_idempotency_key or forbidden endpoint. idempotencyKey is required with webhook.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing devices:write or, with webhook, integrations:write; foreign tenant selection or invalid CSRF.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "pairing_idempotency_conflict: same key, different request. pairing_not_pending: QR registering, linked, expired, cancelled or failed. integration_conflict: different endpoint/secret or disabled. pairing_integration_changed: integration changed after QR. Also https_required and pairing_capacity. Only pairing_not_pending includes safe error.onboarding after same-tenant request hash and integration revision checks. Recover IDs and GET status; registering/linked must not be replaced. No recovery metadata for pairing_integration_changed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "sender_terms_acceptance_required: only this customer must separately accept and verify email in a POST /api/onboarding-sessions wizard; no QR or integration is created. terms_acceptance_required: the contracting workspace owner must accept integration terms in their own profile. Neither administrator nor integrator accepts for the end customer. Existing queues keep original deadlines; reads, cancellation and inbound opt-outs continue.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "integration_backlog_full: callback queue lacks capacity; no QR or new integration created. Replay after capacity becomes available.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List active QR codes without secrets; devices:read",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "description": "Up to 100 pending or registering records, newest first. Expired temporary QR codes are excluded. Creation is limited to 20 active records; longer lists are possible only from an earlier version.",
        "responses": {
          "200": {
            "description": "Активные подключения без qrDataUrl/enrollmentPayload",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pairings": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Pairing"
                      }
                    }
                  },
                  "required": [
                    "pairings"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/pairings/{id}": {
      "get": {
        "summary": "Check whether a phone finished connecting; devices:read",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pairing": {
                      "$ref": "#/components/schemas/Pairing"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Cancel an unused QR code; devices:write",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "204": {
            "description": "Успешно"
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/messages": {
      "get": {
        "summary": "List sent messages; messages:read",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "deviceId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "messages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    },
                    "warning": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "hasMore": {
                      "type": "boolean"
                    },
                    "nextAfter": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Stable createdAt,id descending cursor. q searches ID, destination or platform external ID literally. Filters are applied before pagination. nextAfter is opaque."
      },
      "post": {
        "summary": "Accept one SMS into the durable queue; messages:send",
        "description": "202 means the message is saved, not sent or delivered. SIM limits and the one unconfirmed send per phone apply before hand-off. A repeat with the same key returns the original result; do not create a new key after a network timeout.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MessageInput"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Contracting workspace owner must accept current terms; see error.legal. Existing queues keep original deadlines; reads, cancellation and inbound opt-outs continue.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "integration_backlog_full: очередь обратных событий заполнена, новая SMS не отправлена. Повторите запрос с тем же idempotencyKey и содержимым после освобождения места. Уже допущенная отправка сохраняет свой результат даже при параллельном заполнении очереди.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/messages/{id}": {
      "get": {
        "summary": "Read a message's current status; messages:read",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    },
                    "warning": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/incoming-messages": {
      "get": {
        "summary": "Read incoming SMS history; messages:read",
        "description": "Requires messages:read and the same account authorization as outgoing messages. A platform key requires an explicit account selector; account keys remain scoped. Onboarding tokens, mobile tokens and private iframe links do not grant access. New incoming SMS are durably stored even without webhook/WebSocket events. Stable storedAt,id descending pagination; cursor is tied to the selected account and filters. Legacy receipt rows may have no text or phone reception time. Content removed by retention/deletion remains unavailable. No SMS is sent and upstream inbox refresh is not requested.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 254
            },
            "description": "Literal substring of sender, recipient, text, messageId or history id. Whitespace is trimmed; SQL wildcard characters are treated literally."
          },
          {
            "name": "deviceId",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Filter by one phone within the selected account."
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 512
            },
            "description": "Previous pagination.nextCursor. Preserve account and filters; a mismatched or malformed cursor returns 400 invalid_cursor."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "incomingMessages",
                    "pagination"
                  ],
                  "properties": {
                    "incomingMessages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/IncomingMessage"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/IncomingMessagePagination"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/auto-replies": {
      "get": {
        "summary": "List keyword auto-replies; messages:read",
        "description": "Rules of the selected account: keyword rules ordered by normalized keyword, then the reply to any other message. When an incoming SMS matches a rule, SendHarbor queues one ordinary SMS reply from the phone and SIM slot that received it; the reply goes through the normal sending queue with the routing policy, SIM limits, interval, quiet hours and opt-out checks of that phone, and produces the usual message events. If the routing policy does not allow that SIM, no reply is sent. At most one auto-reply is created per sender number per hour in an account, across all its phones and rules, whether or not it was sent. No reply is created for opt-out or opt-in words, for numbers that opted out, for senders that are not a full international number (letter senders, short codes, national numbers without a country code), when the phone did not report the SIM slot, for SMS received more than an hour before upload, for a reply to a connection test, or when a fixed US control reply answers the same SMS. Managed portal sessions cannot read or change rules.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "autoReplies"
                  ],
                  "properties": {
                    "autoReplies": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AutoReply"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_query: only an account selector is accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal session or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a keyword auto-reply; messages:send",
        "description": "Adds a rule to the selected account. Session mutations require Origin and X-CSRF-Token; read-only users and viewers get 403. At most 30 rule changes per account per minute and 100 rules per account.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AutoReplyInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created rule",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "autoReply"
                  ],
                  "properties": {
                    "autoReply": {
                      "$ref": "#/components/schemas/AutoReply"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_auto_reply, auto_reply_keyword_reserved or invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal session or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "auto_reply_exists: the keyword or the reply to any other message already exists; auto_reply_limit: the account has 100 rules",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/auto-replies/{id}": {
      "put": {
        "summary": "Change a keyword auto-reply; messages:send",
        "description": "Replaces the keyword and reply of a rule of the selected account. A reply already created from the old text is not changed.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Auto-reply id."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AutoReplyInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Changed rule",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "autoReply"
                  ],
                  "properties": {
                    "autoReply": {
                      "$ref": "#/components/schemas/AutoReply"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_auto_reply, auto_reply_keyword_reserved or invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal session or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "auto_reply_not_found or account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "auto_reply_exists: another rule has this keyword, or the reply to any other message already exists",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a keyword auto-reply; messages:send",
        "description": "Deletes a rule of the selected account. Replies already created from it stay in the sending queue.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Auto-reply id."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal session or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "auto_reply_not_found or account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/risk-review": {
      "get": {
        "summary": "Risk pause of the selected account; messages:read",
        "description": "Whether SendHarbor paused sending for this account after risk signals, and why (docs/risk-review.md). While paused, queued and new SMS wait with queueReason risk_review and keep their original expiry; nothing is rejected or deleted, and an SMS already handed to the phone is held at its final authorization. review is null when sending is not paused. Administrators' notes are never returned.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "review"
                  ],
                  "properties": {
                    "review": {
                      "oneOf": [
                        {
                          "$ref": "#/components/schemas/RiskReview"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing messages:read or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/risk-review/appeal": {
      "post": {
        "summary": "Account owner: request a review of the risk pause",
        "description": "Puts the review request first in the administrators' queue. One request per decision: another request before the next decision returns 409 appeal_pending; after a kept pause the owner may ask again. Only the account owner's session can ask (403 owner_required); viewers and read-only users get 403 read_only. The note is shown to administrators only.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "message": {
                    "type": "string",
                    "maxLength": 1000,
                    "description": "Optional note for the reviewer: who receives these SMS and why. Surrounding spaces are removed."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "review"
                  ],
                  "properties": {
                    "review": {
                      "$ref": "#/components/schemas/RiskReview"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_appeal: unknown field or a note longer than 1000 characters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "owner_required or read_only",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "review_not_paused: sending is not paused for review; appeal_pending: a request already waits for a decision",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: at most 10 requests an hour per account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/verifications": {
      "post": {
        "summary": "Issue a verification code by SMS; messages:send",
        "description": "Generates a numeric code with a CSPRNG, stores only its HMAC (keyed with the application secret) and queues one SMS through the normal sending queue with priority 2 and a 10-minute TTL. The code is never returned, logged or shown: the queued message text, history, webhooks and exports carry a masked text (••••••); the real text is built only when the SMS is handed to the phone. A new code for the same number in the same account cancels the earlier pending one and its still-queued SMS. Phone choice follows MessageInput: deviceId or poolId; with neither, the only connected phone of the account. SMS pumping protection: per-number limits (1 per 30 s, 5 per hour), per-account limits (10 per minute, 200 per hour), the account country allowlist (default: the country of the account SIM numbers, else countries it already sent ordinary SMS to) and refusal of satellite, international premium and unassigned calling codes. Code SMS are counted in usage with trafficKind otp. Guide: docs/verifications.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Administrator account selection."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerificationInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Code issued; SMS queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationCreated"
                }
              }
            }
          },
          "400": {
            "description": "invalid_verification_input, invalid_phone, invalid_locale, invalid_code_length, invalid_route, device_required or phone_range_refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope, sandbox_key_only or country_not_allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "device_not_found or pool_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "recipient_opted_out, verification_not_sent or a queue conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "verification_phone_rate_limited or verification_account_rate_limited; Retry-After is set",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Sending queue full or service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/verifications/{id}/check": {
      "post": {
        "summary": "Check a verification code; messages:send",
        "description": "At most 5 attempts per code; each attempt is claimed atomically before a constant-time HMAC comparison, so parallel checks cannot exceed the limit or approve twice. approved closes the verification for good; denied leaves attemptsLeft; expired after 10 minutes; max_attempts on the last wrong attempt and afterwards. A malformed code returns 400 and uses no attempt.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Administrator account selection."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerificationCheckInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationCheckResult"
                }
              }
            }
          },
          "400": {
            "description": "invalid_verification_code",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope or sandbox_key_only",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "verification_not_found, also for another account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "verification_not_pending: already approved, replaced by a newer code or not sent",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many checks for this account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/verification-settings": {
      "get": {
        "summary": "Verification country allowlist and recent code counts; messages:read",
        "description": "The effective country calling codes, whether they are the default or a custom list, where the default comes from (sim, sent or none), counts of the last 24 hours and 7 days and the limits. pumpingSuspected is true when at least 20 codes finished and at least 60% of them were never entered. Nothing is paused automatically; risk review decides.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Administrator account selection."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationSettings"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Account or scope forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Set or reset the verification country allowlist; account owner in the dashboard only",
        "description": "countryCodes: up to 50 ITU calling codes such as +380 or +1, or [] to send no codes at all; null returns to the default list. Satellite, international premium, shared-cost and unassigned codes are refused. The change is recorded as verification_countries_updated. Only a dashboard session of the account owner can change the list; API keys, platform keys, staff and service administrators can read it with GET.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Administrator account selection."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerificationSettingsInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationSettings"
                }
              }
            }
          },
          "400": {
            "description": "invalid_country_codes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "session_required: an API key or platform key cannot change the list; owner_required: the session is not the account owner (staff and service administrators included)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many changes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/sandbox/verifications": {
      "post": {
        "summary": "Simulate a verification code (sandbox)",
        "description": "Sandbox only: returns the code in the response, sends no SMS, writes no usage and skips the country allowlist. Number format, refused ranges, separate per-number and per-account limits, the 10-minute expiry and 5 attempts behave as in the real API. Sandbox and real verifications never see each other.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Administrator account selection."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SandboxVerificationInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxVerificationCreated"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or refused range",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Expired/revoked credential",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Account/scopes forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "project_paused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "verification_phone_rate_limited or verification_account_rate_limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/sandbox/verifications/{id}/check": {
      "post": {
        "summary": "Check a sandbox verification code",
        "description": "Same outcomes as the real check, for sandbox verifications only.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Administrator account selection."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerificationCheckInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxVerificationCheckResult"
                }
              }
            }
          },
          "400": {
            "description": "invalid_verification_code",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "verification_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "verification_not_pending",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/suppressions": {
      "get": {
        "summary": "List recipients who opted out; messages:read",
        "description": "Read-only list of active opt-outs of the selected account, newest first. A recipient opts out by replying with a whole-message opt-out word in English, Russian, Ukrainian, Kazakh, Spanish, Portuguese, French, German, Polish or Turkish (for example STOP, BAJA, SAIR, ARRÊT, STOPP, ZATRZYMAJ, İPTAL and the Cyrillic words listed in docs/sending.md); case, surrounding spaces and punctuation and diacritics are ignored, and an ordinary sentence that merely contains such a word is not an opt-out. Only the recipient can opt back in, by replying START or an equivalent such as ALTA; there is no API to remove an opt-out. Requires messages:read and the same account authorization as incoming messages. A platform key requires an explicit account selector; account keys remain scoped. Stable optedOutAt,phone descending pagination; the cursor is tied to the selected account and q.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Digits of the number or part of it, optionally with +, spaces, brackets, dots or dashes, which are ignored. Anything else returns 400 invalid_query."
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 512
            },
            "description": "Previous pagination.nextCursor. Preserve account and q; a mismatched or malformed cursor returns 400 invalid_cursor."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "suppressions",
                    "pagination"
                  ],
                  "properties": {
                    "suppressions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Suppression"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/SuppressionPagination"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid filter, limit or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing messages:read or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/appointments": {
      "get": {
        "summary": "List appointments; messages:read",
        "description": "Appointments of the selected account ordered by start time, each with its reminder SMS and the client's last answer. Filter by from/to (instants with Z or an offset), status or externalId; page with limit (1-100, default 50) and pagination.nextCursor. Managed portal sessions have no access. See docs/appointments.md.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Appointments starting at or after this instant."
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Appointments starting before this instant."
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "scheduled",
                "confirmed",
                "reschedule_requested",
                "cancelled"
              ]
            }
          },
          {
            "name": "externalId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "pagination.nextCursor of the previous page with the same filters."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "appointments",
                    "pagination"
                  ],
                  "properties": {
                    "appointments": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/Appointment"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "required": [
                        "limit",
                        "nextCursor"
                      ],
                      "properties": {
                        "limit": {
                          "type": "integer"
                        },
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown or invalid filter, limit or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal, disabled HTTP API channel for a key, or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create an appointment; messages:send",
        "description": "Saves the appointment and plans its SMS from the account's reminder settings: a confirmation now, a reminder the day before at the same local time and one 2 hours before. A reminder whose time has passed is skipped. Messages are created 29 days before their time at the latest (sendAt accepts 30 days), expire at the start and use replaceKey appointment:{id}:{kind}:{revision}. startsAt is an instant with Z or an offset, or a local time without one read in timeZone; a local time skipped or repeated by a daylight saving change is rejected. With externalId the create is idempotent: the same details return the saved appointment with 200, other details return 409 appointment_exists. Templates that need a variable the appointment does not fill return 400 template_variables_missing with error.missingVariables.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AppointmentInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The same appointment was already created with this externalId",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "appointment"
                  ],
                  "properties": {
                    "appointment": {
                      "$ref": "#/components/schemas/Appointment"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Created; reminders planned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "appointment"
                  ],
                  "properties": {
                    "appointment": {
                      "$ref": "#/components/schemas/Appointment"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, a start in the past or more than two years ahead, or a template variable the appointment does not fill",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal, disabled HTTP API channel for a key, or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "externalId used with other details, or the upcoming appointment limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/appointments/{id}": {
      "get": {
        "summary": "Read an appointment; messages:read",
        "description": "One appointment with its reminders. A reminder shows planned (no message yet), the state of its message (scheduled, sending, sent, delivered, failed, unknown), skipped with a reason, or cancelled.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "appointment"
                  ],
                  "properties": {
                    "appointment": {
                      "$ref": "#/components/schemas/Appointment"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown query parameter",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal, disabled HTTP API channel for a key, or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or appointment not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Change or reschedule an appointment; messages:send",
        "description": "Send only the fields to change; null clears service, place or staff. A new startsAt or phone is a reschedule: the revision grows, waiting reminders are replaced under their replaceKey (the old message becomes cancelled with MESSAGE_SUPERSEDED), reminders that already went out are planned again for the new time, a new confirmation is sent, and the status returns to scheduled with the last answer cleared. Other changes rewrite only reminders that have not gone out. A request that changes nothing returns the appointment unchanged. A cancelled appointment cannot be changed.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AppointmentUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "appointment"
                  ],
                  "properties": {
                    "appointment": {
                      "$ref": "#/components/schemas/Appointment"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or a template variable the appointment does not fill",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal, disabled HTTP API channel for a key, or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or appointment not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The appointment is cancelled or changed while saving",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/appointments/{id}/cancel": {
      "post": {
        "summary": "Cancel an appointment; messages:send",
        "description": "Cancels the appointment and every reminder SMS not yet handed to the phone. Repeating it returns the cancelled appointment. The body is empty or {}.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "maxProperties": 0
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "appointment"
                  ],
                  "properties": {
                    "appointment": {
                      "$ref": "#/components/schemas/Appointment"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "A non-empty body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal, disabled HTTP API channel for a key, or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or appointment not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/appointment-settings": {
      "get": {
        "summary": "Read reminder settings; messages:read",
        "description": "Which SMS the account sends for appointments (all three by default), their language (en by default), the sending phone (null: the account's only connected phone) and the account templates chosen per SMS (null: the built-in text in defaultTexts). variables lists what reminder templates can use.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppointmentSettingsView"
                }
              }
            }
          },
          "400": {
            "description": "Unknown query parameter",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal, disabled HTTP API channel for a key, or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Replace reminder settings; messages:send",
        "description": "A full replacement. A chosen phone must be connected to the account and a chosen template must belong to it and use only the reminder variables (400 template_variables_unknown). New settings apply to reminders that are not yet queued messages.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AppointmentSettingsInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppointmentSettingsView"
                }
              }
            }
          },
          "400": {
            "description": "Invalid settings or a template variable reminders cannot fill",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal, disabled HTTP API channel for a key, or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account, phone or template not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/message-templates": {
      "get": {
        "summary": "List message templates; messages:read",
        "description": "Saved SMS texts of the selected account, sorted by name; an account keeps at most 200. variables lists the {{name}} placeholders in order of first appearance. Requires messages:read and the same account authorization as messages. A platform key requires an explicit account selector; account keys remain scoped. Managed portal sessions have no access. See docs/templates.md.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "templates"
                  ],
                  "properties": {
                    "templates": {
                      "type": "array",
                      "maxItems": 200,
                      "items": {
                        "$ref": "#/components/schemas/MessageTemplate"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown query parameter",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or template not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a message template; messages:send",
        "description": "The name is trimmed and unique in the account (409 template_name_taken). The text is stored exactly as written. Variables are written as {{name}}: a lowercase Latin letter followed by up to 31 lowercase Latin letters, digits or _. There is no escape syntax. Any other {{…}} returns 400 invalid_template_variable naming it. An account keeps at most 200 templates (409 template_limit). Viewers and read-only users cannot create templates.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MessageTemplateInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "template"
                  ],
                  "properties": {
                    "template": {
                      "$ref": "#/components/schemas/MessageTemplate"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid name, text or variable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or template not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Name taken or template limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/message-templates/{id}": {
      "put": {
        "summary": "Replace a message template; messages:send",
        "description": "Replaces name, text and quickReply; an omitted quickReply is false. The same rules as creation apply. A template of another account returns 404.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MessageTemplateInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "template"
                  ],
                  "properties": {
                    "template": {
                      "$ref": "#/components/schemas/MessageTemplate"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid name, text or variable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or template not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Name taken",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a message template; messages:send",
        "description": "Deletes the template. Messages already sent from it keep their text.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or template not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/message-templates/niches": {
      "get": {
        "summary": "List ready-made template sets; messages:read",
        "description": "Built-in starter sets for a clinic, a beauty salon, a repair shop and a delivery service, 3–5 templates each, in English or Russian. They are read from code; nothing is stored until a set is copied. quietHours is only a suggestion to show next to the set: quiet from start to end, so SMS go out between end and start. It does not change any sending policy.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "language",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "en",
                "ru"
              ],
              "default": "en"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "niches"
                  ],
                  "properties": {
                    "niches": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TemplateNiche"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown parameter or language",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or template not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/message-templates/niches/{niche}/copy": {
      "post": {
        "summary": "Copy a ready-made set into the account; messages:send",
        "description": "Creates editable copies of the set in the chosen language (English by default). A template whose name already exists in the account is skipped and left unchanged, so repeating the request creates nothing new. The copy is all or nothing within the 200-template limit (409 template_limit).",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "niche",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "clinic",
                "beauty_salon",
                "repair",
                "delivery"
              ]
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "language": {
                    "enum": [
                      "en",
                      "ru"
                    ],
                    "default": "en"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "templates",
                    "skipped"
                  ],
                  "properties": {
                    "templates": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MessageTemplate"
                      },
                      "description": "Templates created by this request."
                    },
                    "skipped": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Names of set templates that already existed in the account."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown field or language",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or set not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Template limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contacts": {
      "get": {
        "summary": "List contacts; messages:read",
        "description": "Contacts of the selected account sorted by name, then number; 50 per page by default. q searches names in any case and script, or number digits when it is digits (spaces, +, brackets and dashes are ignored). groupId lists one group. optedOut is true while the number has an active STOP for this account. Managed portal sessions have no access. See docs/contacts.md.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "groupId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 1024
            },
            "description": "nextCursor of the previous page; valid only with the same q and groupId."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "contacts",
                    "pagination"
                  ],
                  "properties": {
                    "contacts": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/Contact"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "limit",
                        "total",
                        "nextCursor"
                      ],
                      "properties": {
                        "limit": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid filter, limit or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a contact; messages:send",
        "description": "The number is normalized like the send form (spaces, brackets, dots and dashes removed, a leading 00 becomes +) and must be E.164; national numbers are not guessed. It is unique in the account (409 contact_exists). Field names follow the template variable rule and cannot be name or phone; empty values are dropped. An account keeps at most 10000 contacts (409 contact_limit). Viewers and read-only users cannot create contacts. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "contact"
                  ],
                  "properties": {
                    "contact": {
                      "$ref": "#/components/schemas/Contact"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid number, name or field",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or group not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Number already saved or contact limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contacts/{id}": {
      "get": {
        "summary": "Read a contact; messages:read",
        "description": "One contact of the selected account. See docs/contacts.md.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Contact id"
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "contact"
                  ],
                  "properties": {
                    "contact": {
                      "$ref": "#/components/schemas/Contact"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or contact not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Replace a contact; messages:send",
        "description": "Replaces number, name and fields; an omitted name or fields becomes empty. groupIds, when given, replaces the memberships; without it they stay. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Contact id"
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "contact"
                  ],
                  "properties": {
                    "contact": {
                      "$ref": "#/components/schemas/Contact"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid number, name or field",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account, contact or group not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Number already saved for another contact",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a contact; messages:send",
        "description": "Deletes the contact and its group memberships at once. Messages already sent keep their own copy of the number and text, and an opt-out (STOP) of the number stays. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Contact id"
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or contact not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contact-groups": {
      "get": {
        "summary": "List contact groups; messages:read",
        "description": "Groups of the selected account sorted by name, with the number of contacts in each; at most 100. See docs/contacts.md.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "groups"
                  ],
                  "properties": {
                    "groups": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/ContactGroup"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown query parameter",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a contact group; messages:send",
        "description": "The name is trimmed and unique in the account (409 contact_group_name_taken). An account keeps at most 100 groups (409 contact_group_limit). See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactGroupInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "group"
                  ],
                  "properties": {
                    "group": {
                      "$ref": "#/components/schemas/ContactGroup"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid name",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Name taken or group limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contact-groups/{id}": {
      "put": {
        "summary": "Rename a contact group; messages:send",
        "description": "Renames the group; its contacts stay. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id"
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactGroupInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "group"
                  ],
                  "properties": {
                    "group": {
                      "$ref": "#/components/schemas/ContactGroup"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid name",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or group not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Name taken",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a contact group; messages:send",
        "description": "Deletes the group and its memberships; the contacts stay. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id"
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or group not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contact-groups/{id}/members": {
      "post": {
        "summary": "Add or remove group members; messages:send",
        "description": "Adds and removes contacts of the same account; up to 1000 ids each. Adding a member twice or removing a non-member changes nothing; an unknown contact in add returns 404 and changes nothing. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id"
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [],
                "properties": {
                  "add": {
                    "type": "array",
                    "maxItems": 1000,
                    "items": {
                      "type": "string"
                    }
                  },
                  "remove": {
                    "type": "array",
                    "maxItems": 1000,
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "minProperties": 1
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "group"
                  ],
                  "properties": {
                    "group": {
                      "$ref": "#/components/schemas/ContactGroup"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid lists",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account, group or contact not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contacts/import/preview": {
      "post": {
        "summary": "Check a CSV import; messages:send",
        "description": "Parses the CSV text (RFC 4180; optional UTF-8 BOM; comma or semicolon, whichever the first line uses more; CRLF, LF or CR), detects a header line, maps columns (a given mapping is validated, otherwise phone, name and Latin field titles are detected) and counts what an import would change against the current contacts. Nothing is stored. At most 180 KB, 5000 data rows and 50 columns. fingerprint is null while no phone column is mapped. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "csv"
                ],
                "properties": {
                  "csv": {
                    "type": "string",
                    "description": "The file as UTF-8 text, at most 184320 bytes."
                  },
                  "mapping": {
                    "$ref": "#/components/schemas/ContactImportMapping"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactImportPreview"
                }
              }
            }
          },
          "400": {
            "description": "Unreadable, too large or invalid CSV, or invalid mapping",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contacts/import": {
      "post": {
        "summary": "Import contacts from CSV; messages:send",
        "description": "Repeats the preview with the same csv and mapping and applies it in one transaction: new numbers are added, existing ones get the non-empty values from the file and keep the rest. Invalid and duplicate rows are skipped and reported. Opted-out numbers are imported and counted; sends skip them. fingerprint must be the one from the preview of this csv and mapping (409 contact_import_changed). The whole file must fit the 10000-contact limit (409 contact_limit). groupId adds every imported contact to that group. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "csv",
                  "mapping",
                  "fingerprint"
                ],
                "properties": {
                  "csv": {
                    "type": "string"
                  },
                  "mapping": {
                    "$ref": "#/components/schemas/ContactImportMapping"
                  },
                  "fingerprint": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "groupId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Imported",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactImportResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid CSV or mapping",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account or group not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Preview no longer matches, contacts changed or contact limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contacts/messages/preview": {
      "post": {
        "summary": "Preview a personalized send; messages:send",
        "description": "Renders the template or text for each chosen contact with name, phone and the contact fields as variables, and counts SMS parts of each final text. Contacts with an active STOP, an empty variable, a text longer than 5000 characters or more parts than maxSegments are skipped and listed with their reason; an unknown contact id is listed as not_found. Nothing is created. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactMessageSelection"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactMessagePreview"
                }
              }
            }
          },
          "400": {
            "description": "Invalid selection, text, variable or maxSegments",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account, template or group not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/contacts/messages": {
      "post": {
        "summary": "Send a personalized SMS to contacts; messages:send",
        "description": "Builds the same plan as the preview and queues one SMS per sendable contact, each with its own final text, through the batch pipeline: parts of at most 100 messages are queued as batches batchId:1, batchId:2 and so on. Every part is validated before the first is queued. At most 1000 sendable contacts per request (400 too_many_contacts); none sendable returns 400 no_contacts_to_send. Skipped contacts are returned, never silently dropped. Repeating the same request with the same batchId queues only the parts that are missing; a changed request under the same batchId returns 409 batch_conflict. Requires the HTTP API channel for keys and the usual sending admission. See docs/contacts.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactMessageInput"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactMessageResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, nothing to send or too many recipients",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, read-only access, managed portal or no access to the selected account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Account, template, group, phone or pool not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "batchId belongs to a different send, or the project is archived",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Sending queue full; repeat with the same batchId",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/incoming-messages/{id}": {
      "get": {
        "summary": "Read one incoming SMS; messages:read",
        "description": "Requires messages:read and the same account authorization as outgoing messages. A platform key requires an explicit account selector; account keys remain scoped. Onboarding tokens, mobile tokens and private iframe links do not grant access. Use IncomingMessage.id, not the original event messageId. A missing record or a record in another account returns 404 incoming_message_not_found. The webhooks object exposes only safe metadata for this incoming event; no payload or credentials. handledAt/handledBy are workflow markers only.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "History id returned by GET /api/incoming-messages."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "incomingMessage",
                    "webhooks"
                  ],
                  "properties": {
                    "incomingMessage": {
                      "$ref": "#/components/schemas/IncomingMessage"
                    },
                    "webhooks": {
                      "$ref": "#/components/schemas/IncomingWebhookHistory"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/keys": {
      "get": {
        "summary": "Список ключей без секретов",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Key"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Создать scoped API ключ",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "enum": [
                        "devices:read",
                        "devices:write",
                        "messages:read",
                        "messages:send",
                        "integrations:write"
                      ]
                    }
                  }
                },
                "required": [
                  "name",
                  "scopes"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "$ref": "#/components/schemas/Key"
                    },
                    "secret": {
                      "type": "string",
                      "description": "Показывается только один раз; хранить на backend вашей платформы."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/keys/{id}": {
      "delete": {
        "summary": "Отозвать API ключ",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Успешно"
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/download": {
      "get": {
        "summary": "Метаданные опубликованного APK",
        "security": [],
        "responses": {
          "200": {
            "description": "Validated APK metadata, relative download URL and canonical absolute URL from PUBLIC_URL. The installation QR contains only the absolute APK URL; it is null for HTTP or loopback origins.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/AndroidRelease"
                    },
                    {
                      "type": "object",
                      "required": [
                        "absoluteUrl",
                        "qrDataUrl",
                        "qrUnavailableReason"
                      ],
                      "properties": {
                        "absoluteUrl": {
                          "type": "string",
                          "format": "uri",
                          "description": "Canonical APK URL from configured PUBLIC_URL; independent of request Host."
                        },
                        "qrDataUrl": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Inline PNG QR for the APK URL. Scan with the phone camera; not an enrollment credential."
                        },
                        "qrUnavailableReason": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            null,
                            "https_required",
                            "phone_address_required"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "503": {
            "description": "Интеграция отключена или APK недоступен",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Готовность SQLite и SMSGate",
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "enum": [
                        "ok",
                        "unavailable"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Шлюз или база недоступны",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "const": "unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/device": {
      "post": {
        "summary": "Однократная регистрация Android-устройства по QR",
        "description": "One-use QR enrollment. Optional X-Enrollment-Recovery makes response loss recoverable for the original installation. For 15 minutes after successful enrollment, the original code, secret and frozen registration body return the same device credentials with 201; ordinary QR expiry does not end that completed recovery window. After that, recovery requires a fresh authorized, unconsumed QR for the same tenant, principalId and owner email, plus the same proof and frozen body. The encrypted response is retained for at most 24 hours from original successful registration; fresh QR aliases, retries and restarts never extend that deadline. Pre-upgrade cached responses retain their previous shorter expiry. Recovery creates no second phone or second linked event. A fresh recovery pairing becomes linked to the existing deviceId; poll GET /api/pairings/{id} or its onboarding session instead of expecting a new linked callback for that pairingId. Different/missing proof cannot reuse a consumed QR. Running registration returns 409 enrollment_in_progress; changed body or owner scope returns 409 enrollment_request_changed or enrollment_scope_changed. An unknown upstream outcome or unavailable/expired response requires service support; never direct the user to delete an active phone or clear application data. Revoked issuers, phones and principals cannot recover. pushToken is forced null (SSE). Legacy callers without the header remain one-use.",
        "security": [
          {
            "pairingCode": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "simCards": {
                    "type": "array",
                    "maxItems": 8,
                    "items": {
                      "type": "object"
                    }
                  },
                  "publicKey": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 16384
                  },
                  "keyVersion": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Реквизиты одного устройства; хранить только в приложении",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "token",
                    "login"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "token": {
                      "type": "string"
                    },
                    "login": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Некорректные поля",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "QR недействителен, истёк или уже использован",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "enrollment_in_progress: retry the original persisted attempt later. enrollment_request_changed or enrollment_scope_changed: preserve the original registration and owner/account identity. enrollment_recovery_unavailable: the previous upstream result is unknown or its retained response is unavailable/expired; stop new registration and contact service support with requestId. Never delete an active phone or reset app data to bypass this state. pairing_integration_changed: reconcile integration configuration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "enrollment_recovery_expired: the original-code 15-minute replay window ended. Recovery within the original 24-hour cache requires a fresh authorized QR for the same account/principal/email, scanned by the same installation with its saved proof and frozen body. A fresh QR never extends cache retention. If the result is unavailable, contact service support; do not delete the existing phone.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "sender_terms_acceptance_required: this customer separately accepts its agreement and verifies email through the connection wizard. terms_acceptance_required: the workspace owner accepts the integration agreement. A valid unconsumed QR is not consumed by this refusal; retry it after acceptance if it remains valid.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка регистрации upstream",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "integration_backlog_full: нет места для события регистрации; отказ на предварительной проверке не расходует одноразовый QR. Повторите после освобождения очереди и до истечения QR.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Random 32-byte base64url secret generated and durably saved by this app installation before the first enrollment request. Reuse exactly the same secret and normalized registration body to recover a lost successful response. Never put it in QR, logs or another installation."
          }
        ]
      }
    },
    "/api/integrations/magenda": {
      "get": {
        "summary": "Настройки Magenda без секрета и статистика доставки",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "description": "Только администратор: ID рабочего пространства. Для клиента определяется сессией; чужой tenant запрещён.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Настройки либо null, если интеграция ещё не создана",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "integration": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/Integration"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "deliverySummary": {
                      "$ref": "#/components/schemas/DeliverySummary"
                    },
                    "health": {
                      "$ref": "#/components/schemas/IntegrationHealth"
                    }
                  },
                  "required": [
                    "integration",
                    "deliverySummary"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Неверная аутентификация или подпись",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Недостаточно прав или CSRF",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ограничение частоты",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "API key requires integrations:write and is restricted to its tenant; browser session follows workspace access. No secret is returned."
      },
      "put": {
        "summary": "Создать или обновить связь клиента с Magenda",
        "description": "Первое создание возвращает secret один раз. Существующий secret не меняется и не раскрывается. Только session; API-ключи не принимаются.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "description": "Только администратор: ID рабочего пространства. Для клиента определяется сессией; чужой tenant запрещён.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IntegrationInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Сохранено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IntegrationSaved"
                }
              }
            }
          },
          "400": {
            "description": "Некорректные параметры или запрещённый endpoint",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Неверная аутентификация или подпись",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Недостаточно прав или CSRF",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ограничение частоты",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/integrations/magenda/rotate-secret": {
      "post": {
        "summary": "Сменить общий секрет Magenda",
        "description": "Старый секрет немедленно перестаёт проверять новые команды. Обновите секрет на Magenda; уже выполняющийся callback может завершиться со старой подписью.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "description": "Только администратор: ID рабочего пространства. Для клиента определяется сессией; чужой tenant запрещён.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Новый секрет показан один раз",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSaved"
                    },
                    {
                      "required": [
                        "secret"
                      ]
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Неверная аутентификация или подпись",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Недостаточно прав или CSRF",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ограничение частоты",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/integrations/magenda/deliveries": {
      "get": {
        "summary": "Последние события и результат доставки в Magenda",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "description": "Только администратор: ID рабочего пространства. Для клиента определяется сессией; чужой tenant запрещён.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Журнал",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deliveries": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDelivery"
                      }
                    }
                  },
                  "required": [
                    "deliveries"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Некорректные параметры или запрещённый endpoint",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Неверная аутентификация или подпись",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Недостаточно прав или CSRF",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ограничение частоты",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/integrations/magenda/deliveries/{id}/retry": {
      "post": {
        "summary": "Повторить failed-событие с прежним ID",
        "description": "Сбрасывает счётчик попыток и возвращает событие в pending; новую SMS не создаёт. При отключённой интеграции событие ждёт включения.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "description": "Только администратор: ID рабочего пространства. Для клиента определяется сессией; чужой tenant запрещён.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Снова в очереди",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "delivery": {
                      "$ref": "#/components/schemas/WebhookDelivery"
                    }
                  },
                  "required": [
                    "delivery"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Неверная аутентификация или подпись",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Недостаточно прав или CSRF",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Конфликт идемпотентности или состояние не допускает действие",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ограничение частоты",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/integrations/magenda/test": {
      "post": {
        "summary": "Поставить integration.test в очередь без отправки SMS",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "description": "Только администратор: ID рабочего пространства. Для клиента определяется сессией; чужой tenant запрещён.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Тест поставлен в очередь",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "eventId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "eventId"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Неверная аутентификация или подпись",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Недостаточно прав или CSRF",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Конфликт идемпотентности или состояние не допускает действие",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ограничение частоты",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "integration_backlog_full: тестовое событие не поставлено в очередь. Восстановите доставку накопленных событий.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/integrations/{integrationId}/commands": {
      "post": {
        "summary": "Magenda → Gateway: принять подписанную SMS-команду",
        "description": "HTTP 202 подтверждает durable enqueue. Повтор идентичной команды не отправляет новую SMS; изменённое тело с прежним id/externalId даёт 409. Подпись вычисляется до JSON parsing по исходным байтам. Лимиты на интеграцию: 1000 активных команд, 2000 недоставленных callback (включая failed), 16 MiB UTF-8 JSON callback. Worker ждёт освобождения очереди без расходования попыток. Состояние и заполнение доступны в health.capacity. sms.batch durably records a batch command and returns202 with a statusUrl. Poll admission status separately; identical signed command ID/raw body is idempotent. The webhookCommands project channel is required.",
        "security": [
          {
            "webhookTimestamp": [],
            "webhookSignature": []
          }
        ],
        "parameters": [
          {
            "name": "integrationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/SmsCommand"
                  },
                  {
                    "$ref": "#/components/schemas/SmsCancelCommand"
                  },
                  {
                    "$ref": "#/components/schemas/SmsBatchCommand"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Принято в очередь",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/CommandAccepted"
                    },
                    {
                      "$ref": "#/components/schemas/CancelCommandAccepted"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Некорректные параметры или запрещённый endpoint",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Неверная аутентификация или подпись",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Конфликт идемпотентности или состояние не допускает действие",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Тело запроса слишком велико",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Contracting workspace owner must accept current terms; see error.legal. Existing queues keep original deadlines; reads, cancellation and inbound opt-outs continue.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ограничение частоты",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "integration_disabled либо integration_backlog_full. Новая команда не принята: включите обмен/освободите очередь и повторите тот же ID и точные байты тела с новой timestamp и подписью. При заполненной, но включённой интеграции уже принятая идентичная команда по-прежнему возвращает 202.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/events/incoming": {
      "post": {
        "summary": "Android → Gateway: сохранить входящую SMS и событие Magenda",
        "description": "Устройство и клиент определяются токеном. Поле deviceId из запроса не используется. Повтор одинакового id на устройстве идемпотентен; тело не обрезается.",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IncomingSms"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Сохранено",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "accepted": {
                      "const": true
                    }
                  },
                  "required": [
                    "id",
                    "accepted"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Некорректные параметры или запрещённый endpoint",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Неверная аутентификация или подпись",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Конфликт идемпотентности или состояние не допускает действие",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Тело запроса слишком велико",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ограничение частоты",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Шлюз временно недоступен",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "integration_backlog_full: событие и receipt не сохранены. Телефон должен повторить прежний ID и содержимое после освобождения места; уже принятый идентичный ID подтверждается независимо от заполнения.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/events/incoming/{id}/reply": {
      "post": {
        "summary": "Телефон: ответить на входящее SMS из уведомления через очередь сервера",
        "description": "The phone owner types a reply in the notification of an incoming SMS that this phone delivered (id is the id the phone sent to POST /api/mobile/v1/events/incoming). The server queues an ordinary SMS to the sender from the SIM that received it: the same limits, pacing, quiet hours, STOP, history, webhooks and usage as a dashboard reply, purpose transactional. The phone never sends it with its modem directly; dispatch follows the normal authorize-send path. The same text to the same SMS is deduplicated. 10 requests a minute per phone.",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 5000
                  }
                },
                "required": [
                  "text"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The same text was already queued for this SMS; nothing new was created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "phase": {
                          "type": "string",
                          "enum": [
                            "queued",
                            "submitted",
                            "sending",
                            "sent",
                            "delivered",
                            "failed",
                            "expired",
                            "cancelled",
                            "unknown"
                          ]
                        },
                        "queueReason": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Why the queued reply waits, for example quiet_hours, paused, interval or hour_limit."
                        },
                        "error": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "RECIPIENT_OPTED_OUT when the sender replied STOP: the reply is cancelled in the queue, not sent."
                        }
                      },
                      "required": [
                        "id",
                        "phase",
                        "queueReason",
                        "error"
                      ]
                    },
                    "duplicate": {
                      "type": "boolean",
                      "description": "true when the same text was already queued for this SMS; the earlier message is returned."
                    }
                  },
                  "required": [
                    "message",
                    "duplicate"
                  ]
                }
              }
            }
          },
          "202": {
            "description": "Queued; phase cancelled with error RECIPIENT_OPTED_OUT means the sender has opted out",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "phase": {
                          "type": "string",
                          "enum": [
                            "queued",
                            "submitted",
                            "sending",
                            "sent",
                            "delivered",
                            "failed",
                            "expired",
                            "cancelled",
                            "unknown"
                          ]
                        },
                        "queueReason": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Why the queued reply waits, for example quiet_hours, paused, interval or hour_limit."
                        },
                        "error": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "RECIPIENT_OPTED_OUT when the sender replied STOP: the reply is cancelled in the queue, not sent."
                        }
                      },
                      "required": [
                        "id",
                        "phase",
                        "queueReason",
                        "error"
                      ]
                    },
                    "duplicate": {
                      "type": "boolean",
                      "description": "true when the same text was already queued for this SMS; the earlier message is returned."
                    }
                  },
                  "required": [
                    "message",
                    "duplicate"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "invalid_input, sim_not_enabled or message_exceeds_budget; nothing was queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the phone is not paired, was removed from the dashboard or its account is not active",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "incoming_message_not_found: this phone has not delivered an SMS with this id to its account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Nothing was queued: reply_sender_not_phone (alphanumeric or short sender), reply_sim_unknown, reply_content_removed, or a project hold: project_paused, project_archived, platform_paused, platform_archived, terms_acceptance_required, sender_terms_acceptance_required, risk_review (the account is paused for review, docs/risk-review.md)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited; Retry-After says when to try again",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "gateway_unavailable: the phone list could not be checked; nothing was queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "sending_queue_full or shutting_down; nothing was queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/android/releases/latest": {
      "get": {
        "summary": "Проверка совместимого обновления Android",
        "description": "Returns only a higher versionCode for the same packageName, minSdk <= sdk and HTTPS PUBLIC_URL. Android verifies package, checksum and certificate independently. Anonymous requests receive 204 during pilot or paused rollout. Initial rollout comes from the optional manifest.rollout; legacy manifests fall back to channel. Cohort checks require the authenticated mobile route.",
        "security": [],
        "parameters": [
          {
            "name": "packageName",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 150
            }
          },
          {
            "name": "versionCode",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "sdk",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 21,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Доступно совместимое обновление; url абсолютный HTTPS",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AndroidUpdate"
                }
              }
            }
          },
          "204": {
            "description": "Подходящего обновления нет, включая несовпадающий package, текущую версию или HTTP origin; also rollout paused or pilot mode for an anonymous request."
          },
          "400": {
            "description": "Некорректные параметры или запрещённый endpoint",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/downloads/sms-gateway.apk": {
      "get": {
        "summary": "Скачать опубликованный подписанный APK",
        "security": [],
        "responses": {
          "200": {
            "description": "APK; проверяйте sha256 и сертификат подписи из метаданных",
            "content": {
              "application/vnd.android.package-archive": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "503": {
            "description": "APK rollout is paused; no download is served.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/diagnostics": {
      "post": {
        "summary": "Телефон: передать свежие технические проверки и безопасные события",
        "description": "Идентичность определяется индивидуальным Bearer. Нельзя передавать tenant/device IDs, тексты SMS, номера, произвольные сообщения или URL. События дедуплицируются по UUID в ограниченном окне: до 7 дней и последних 2000 receipts устройства; более старые события ACK без хранения. Повтор того же collectedAt не продлевает свежесть. Missing fields означают unknown/null.",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DiagnosticReport"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Принято",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accepted": {
                      "const": true
                    },
                    "receivedAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "acceptedEventIds": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "format": "uuid"
                      }
                    },
                    "simNetwork": {
                      "const": true,
                      "description": "The server accepts carrierId, mcc and mnc in simCards. Older servers omit it and reject those keys."
                    }
                  },
                  "required": [
                    "accepted",
                    "receivedAt",
                    "acceptedEventIds"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/diagnostics": {
      "get": {
        "summary": "Latest phone checks, including an unreachable gateway; devices:read",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Сохранённый снимок с явной свежестью",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceDiagnostics"
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/sim-catalog": {
      "get": {
        "summary": "Carrier, terms on automated sending and plans for each SIM of the phone, from the SIM catalog; devices:read",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "SIMs from the latest phone report matched to the catalog",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceSimCatalog"
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/support": {
      "get": {
        "summary": "Скачать технический отчёт для поддержки; только session",
        "description": "Только технические данные и последние100 событий телефона. Без SMS, номеров, произвольного имени устройства, данных аккаунта, секретов и URL. Экспорт не отправляется третьей стороне.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "JSON attachment",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/DeviceDiagnostics"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "format": {
                          "const": 1
                        },
                        "events": {
                          "type": "array",
                          "maxItems": 100,
                          "items": {
                            "$ref": "#/components/schemas/OperationalEvent"
                          }
                        },
                        "retentionDays": {
                          "const": 7
                        },
                        "privacy": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "format",
                        "events",
                        "retentionDays",
                        "privacy"
                      ]
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/events": {
      "get": {
        "summary": "Журнал технических событий своего клиента; только session",
        "description": "До7дней, максимум2000 событий клиента и500 событий каждого телефона. Numeric before cursor сохраняет фильтры. Журнал не содержит тел SMS/запросов, номеров и токенов.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "level",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "info",
                "warning",
                "error"
              ]
            }
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "device",
                "connection",
                "permissions",
                "updates",
                "messages",
                "integration",
                "system"
              ]
            }
          },
          {
            "name": "deviceId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "before",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "События от новых к старым",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "events": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/OperationalEvent"
                      }
                    },
                    "hasMore": {
                      "type": "boolean"
                    },
                    "nextBefore": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "retentionDays": {
                      "const": 7
                    }
                  },
                  "required": [
                    "events",
                    "hasMore",
                    "nextBefore",
                    "retentionDays"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса или доступа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/sending-policy": {
      "get": {
        "summary": "Read sending rules and actual SIM usage; devices:read",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Сохранённые данные",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendingPolicyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Change pace, limits, pause and quiet hours; devices:write",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendingPolicyInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Сохранённые данные",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendingPolicyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "426": {
            "description": "app_update_required: registered mobile phones must report app.versionCode >= 1770460 before hourly, daily or monthly limits can be set to zero through the web/project API. A mobile capability header cannot bypass this check on this endpoint. Existing saved policies are not rewritten.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/messages/batch": {
      "post": {
        "summary": "Atomically accept a batch of 1–100 SMS; messages:send",
        "description": "All new records are saved in one transaction, or none are. Use a separate stable idempotencyKey for each item. Repeating the whole batch with the same keys is safe; a conflict on one item rejects the whole batch. Saving does not mean delivery. The JSON body is limited to 256 KiB. Optional named batchId enables stable batch-level admission, generated item idempotency keys and status readback. Without batchId the legacy items/messages contract is unchanged. Commands using integration API keys require the httpApi project channel; console sessions remain available.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "items": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 100,
                        "items": {
                          "$ref": "#/components/schemas/MessageInput"
                        }
                      }
                    },
                    "required": [
                      "items"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "$ref": "#/components/schemas/NamedBatchInput"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted into durable queue; not a carrier delivery promise",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batch": {
                      "$ref": "#/components/schemas/MessageBatch"
                    },
                    "messages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Contracting workspace owner must accept current terms; see error.legal. Existing queues keep original deadlines; reads, cancellation and inbound opt-outs continue.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/messages/{id}/cancel": {
      "post": {
        "summary": "Cancel an SMS not yet handed to a phone; messages:send",
        "description": "Only for state=Queued. Repeating a cancel is idempotent. Once handed to the gateway it returns 409; a cancel does not promise recall from the phone or the carrier network.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Сохранённые данные",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Ошибка запроса, доступа, ёмкости очереди или шлюза",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/support": {
      "get": {
        "summary": "Все локальные клиенты и состояние телефонов для поддержки",
        "description": "Включает клиентов без телефона/интеграции и клиентов с незавершённым provisioning. Это локальный каталог SendHarbor, не синхронизированный каталог сотрудников Magenda. Только cookie-сессия администратора. API keys запрещены. Запрос читает локальные данные, не вызывает gateway и не выполняет тестовую SMS. Все ответы no-store. Неизвестные query-параметры отклоняются. Лимит поддержки: 120 запросов/мин на администратора, дополнительно общий API limit. Контакты platformUsers автоматически появляются после успешного подключения QR с email. Они не требуют ручной clinic-link и не означают, что webhook-интеграция настроена.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "lifecycle",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "active",
                "archived"
              ],
              "default": "all"
            },
            "description": "active исключает offboarded и клиентов архивных проектов; archived включает offboarded и клиентов архивных проектов — тот же набор, что summary.archived в /api/overview для администратора. В кабинете по умолчанию active. API сохраняет all для совместимости. Архив сохраняет карточки клиентов, телефоны и историю."
          },
          {
            "in": "query",
            "name": "q",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 254
            },
            "description": "Поиск по клиенту, локальному пользователю, email автоматически связанного пользователя платформы, clinic ID/name, device ID или integration UUID. Символы LIKE рассматриваются буквально."
          },
          {
            "in": "query",
            "name": "state",
            "required": false,
            "schema": {
              "enum": [
                "all",
                "attention",
                "offline",
                "no_phone"
              ],
              "default": "all"
            },
            "description": "Фильтр состояния; offline требует известного устаревшего контакта, unknown отдельно не является offline. no_phone означает отсутствие активных телефонов, включая клиентов только с отозванными устройствами. attention включает отсутствие телефона, свежие проблемы, сохранённые отказы и проблемы интеграции."
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 25
            },
            "description": "Размер страницы."
          },
          {
            "in": "query",
            "name": "after",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "description": "nextAfter из предыдущего ответа; при изменении поиска/фильтра курсор сбрасывается."
          }
        ],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminSupportList"
                }
              }
            }
          },
          "400": {
            "description": "invalid_support_query / invalid_input: неизвестные параметры, некорректный курсор или тело.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: нужна действующая сессия.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "admin_required / session_required / invalid_csrf / invalid_origin: только администратор; API keys и клиентские сессии запрещены.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: ограничение запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/support/{tenantId}": {
      "get": {
        "summary": "Карточка клиента: все пользователи и телефоны постранично",
        "description": "Просматривайте devicesHasMore/usersHasMore/platformUsersHasMore, чтобы получить полные независимые списки телефонов, login-пользователей и контактов платформы. Только cookie-сессия администратора. API keys запрещены. Запрос читает локальные данные, не вызывает gateway и не выполняет тестовую SMS. Все ответы no-store. Неизвестные query-параметры отклоняются. Лимит поддержки: 120 запросов/мин на администратора, дополнительно общий API limit.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "tenantId",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          },
          {
            "in": "query",
            "name": "deviceLimit",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            },
            "description": "Размер страницы телефонов."
          },
          {
            "in": "query",
            "name": "devicesAfter",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "description": "devicesNextAfter предыдущего ответа."
          },
          {
            "in": "query",
            "name": "userLimit",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": "Размер страницы локальных пользователей."
          },
          {
            "in": "query",
            "name": "usersAfter",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "description": "usersNextAfter предыдущего ответа."
          },
          {
            "in": "query",
            "name": "platformUserLimit",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": "Размер страницы контактов платформы."
          },
          {
            "in": "query",
            "name": "platformUsersAfter",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 254
            },
            "description": "platformUsersNextAfter предыдущего ответа; email-курсор внутри данного клиента."
          }
        ],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminSupportDetail"
                }
              }
            }
          },
          "400": {
            "description": "invalid_support_query / invalid_input: неизвестные параметры, некорректный курсор или тело.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: нужна действующая сессия.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "admin_required / session_required / invalid_csrf / invalid_origin: только администратор; API keys и клиентские сессии запрещены.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "tenant_not_found / device_not_found: объект не существует в заданном клиенте.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: ограничение запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/support/{tenantId}/devices/{deviceId}": {
      "get": {
        "summary": "Телефон: диагностика, очередь, безопасная ошибка и действия",
        "description": "Телефон проверяется в контексте указанного клиента; чужой device ID возвращает 404. Свежесть соединения, свежесть диагностики и история SMS показываются раздельно. Только cookie-сессия администратора. API keys запрещены. Запрос читает локальные данные, не вызывает gateway и не выполняет тестовую SMS. Все ответы no-store. Неизвестные query-параметры отклоняются. Лимит поддержки: 120 запросов/мин на администратора, дополнительно общий API limit.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "tenantId",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          },
          {
            "in": "path",
            "name": "deviceId",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Успешно",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminSupportDeviceDetail"
                }
              }
            }
          },
          "400": {
            "description": "invalid_support_query / invalid_input: неизвестные параметры, некорректный курсор или тело.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: нужна действующая сессия.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "admin_required / session_required / invalid_csrf / invalid_origin: только администратор; API keys и клиентские сессии запрещены.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "tenant_not_found / device_not_found: объект не существует в заданном клиенте.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: ограничение запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/support/tenants/{id}/magenda-link": {
      "put": {
        "summary": "Указать клинику Magenda для административной поддержки",
        "description": "Только cookie-сессия администратора, X-CSRF-Token и тот же Origin. Не требует уже созданной интеграции или телефона. Запись manual помогает идентифицировать клиента, но не меняет отправку/авторизацию и не подтверждает upstream. API keys и customer sessions запрещены. Все query-параметры отклоняются; no-store. Лимит: 30 изменений за 15 минут на администратора. Необязательный прежний способ сохранить справочную клинику. Для автоматической привязки контакта телефона используйте POST /api/pairings с email: ручная clinic-link для этого не требуется.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MagendaClinicLinkInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Сохранена либо удалена информационная ссылка.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "magendaLink": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/MagendaClinicLink"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "magendaLink"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "invalid_support_query / invalid_input: неизвестные параметры, некорректный курсор или тело.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: нужна действующая сессия.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "admin_required / session_required / invalid_csrf / invalid_origin: только администратор; API keys и клиентские сессии запрещены.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "tenant_not_found / device_not_found: объект не существует в заданном клиенте.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: ограничение запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/messages/{id}/resolve": {
      "post": {
        "summary": "Acknowledge unknown outcome and release later queue without resending this SMS",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Required for an administrator session."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "decision",
                  "note",
                  "acknowledgeNoRetry"
                ],
                "properties": {
                  "decision": {
                    "const": "acknowledged_unknown"
                  },
                  "note": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 1000
                  },
                  "acknowledgeNoRetry": {
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing or newly persisted resolution; original unknown state retained",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Explicit acknowledgement and a meaningful note required"
          },
          "403": {
            "description": "Session and CSRF required; API key cannot acknowledge uncertainty"
          },
          "404": {
            "description": "Message not found in the session tenant"
          },
          "409": {
            "description": "Message outcome is not unknown"
          }
        }
      }
    },
    "/api/provisioning/tenants": {
      "post": {
        "summary": "Idempotently provision a clinic for the trusted platform backend",
        "security": [
          {
            "provisioning": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "externalId",
                  "name",
                  "email"
                ],
                "properties": {
                  "externalId": {
                    "type": "string",
                    "pattern": "^magenda:clinic:[A-Za-z0-9._:-]{1,100}$"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stable tenant and encrypted-replay credential; keep solely on backend",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tenantId",
                    "apiKey"
                  ],
                  "properties": {
                    "tenantId": {
                      "type": "string"
                    },
                    "apiKey": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid provisioning credential"
          },
          "409": {
            "description": "owner_workspace_required for new unowned accounts; or provisioning in progress / revoked key. Use an accepted owner platform; never silently restores revoked access."
          },
          "502": {
            "description": "Retry with unchanged externalId"
          }
        },
        "description": " externalId now accepts any stable namespaced identifier (1–128 ASCII letters/digits/._:-). The magenda:clinic: prefix retains legacy clinic linkage. With required service terms, new unowned workspaces return409 owner_workspace_required before provisioning. Create a platform in the accepted contracting owner workspace and use its spk_ account API. Existing provisioning replay remains available; legacy accounts require a reviewed owner association before sending/enrollment, never automatic email-based ownership.",
        "deprecated": true
      }
    },
    "/api/principals/{principalId}/revoke-pairings": {
      "post": {
        "summary": "Revoke pending enrollment and block delayed creation",
        "security": [
          {
            "apiKey": []
          },
          {
            "session": [],
            "csrf": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "principalId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent result. Revocation returns {cancelled,revoked:true}; restore returns {revoked:false}. Existing phones are not revoked."
          },
          "403": {
            "description": "devices:write scope required"
          }
        }
      }
    },
    "/api/principals/{principalId}/restore": {
      "post": {
        "summary": "Explicitly restore future enrollment for a principal",
        "security": [
          {
            "apiKey": []
          },
          {
            "session": [],
            "csrf": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "principalId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent result. Revocation returns {cancelled,revoked:true}; restore returns {revoked:false}. Existing phones are not revoked."
          },
          "403": {
            "description": "devices:write scope required"
          }
        }
      }
    },
    "/api/admin/support/incidents/{id}/acknowledge": {
      "post": {
        "summary": "Take an open support incident into work",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Incident with acknowledgedBy/acknowledgedAt; problem remains visible until recovery"
          },
          "403": {
            "description": "Administrator session required"
          },
          "404": {
            "description": "Incident not found"
          },
          "409": {
            "description": "Incident already resolved"
          }
        }
      }
    },
    "/api/mobile/v1/messages/{id}/authorize-send": {
      "post": {
        "summary": "Final authorization on the phone immediately before durable dispatch claim and modem hand-off",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "simNumber": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8
                  },
                  "simPhoneNumber": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^\\+[1-9]\\d{6,14}$"
                  },
                  "observedVerificationTag": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^[a-fA-F0-9-]{36}$",
                    "description": "Random UUID-like generation for the actual selected SIM, generated and persisted by the phone. Required for the technical identity guard; missing or unavailable identity waits with app_upgrade_required or sim_identity_unavailable. This is not an ICCID, hardware fingerprint or registration ID."
                  }
                },
                "required": [],
                "additionalProperties": false,
                "allOf": [
                  {
                    "if": {
                      "required": [
                        "simPhoneNumber"
                      ],
                      "properties": {
                        "simPhoneNumber": {
                          "type": "string"
                        }
                      }
                    },
                    "then": {
                      "required": [
                        "simNumber"
                      ]
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Allowed at this instant; absolute expiry still applies",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "allowed",
                    "expiresAt"
                  ],
                  "properties": {
                    "allowed": {
                      "const": true
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "simNumber": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 8
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_input: unsupported fields/query or malformed observed SIM data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Device revoked; keep unsent work blocked"
          },
          "404": {
            "description": "Unknown/foreign message or older server; fail closed, do not send"
          },
          "409": {
            "description": "No modem hand-off permitted: RECIPIENT_OPTED_OUT, MESSAGE_CANCELLED, MESSAGE_EXPIRED or MESSAGE_NO_LONGER_VALID. Record proven pre-send failure, without a carrier-failure circuit. SIM_ROUTE_MISMATCH rejects a different observed slot before modem claim."
          },
          "503": {
            "description": "Temporary hold; no modem hand-off. Includes integration/validation availability, diagnostics_stale, sim_missing, sim_identity_unavailable, sim_identity_changed, app_upgrade_required, us_business_profile_required, us_consent_required/expired/revoked, us_recipient_quiet_hours or us_control_stale. Document review is not a condition. Keep native Pending and retry authorization only within the original deadline; never interpret a hold as permission to send.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Called by the authenticated phone immediately before durable modem claim. With the legacy US profile enabled (default), send the actual selected simNumber and observedVerificationTag; the server checks fresh diagnostics and the identity captured for this attempt. simPhoneNumber remains optional when Android does not expose it; a known mismatch is a technical identity hold. Legacy empty bodies are syntactically accepted but do not prove identity. No operator document review, reviewed caps or administrator clearance is required. Sender profile, message purpose, recipient consent/quiet hours, STOP, original expiry and other final checks run again before and after asynchronous validation."
      }
    },
    "/api/magenda/portal-access": {
      "post": {
        "summary": "Backend-only one-use 60-second portal grant; required device read/write and message read/send scopes",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "principalId": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "clinicId": {
                    "type": "string"
                  }
                },
                "required": [
                  "principalId",
                  "email",
                  "clinicId"
                ]
              }
            }
          }
        }
      }
    },
    "/api/magenda/portal-exchange": {
      "post": {
        "summary": "Exchange fragment token for limited 30-minute HttpOnly tenant session; exact same-origin POST",
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "token": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{43}$"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/magenda/offboard": {
      "post": {
        "summary": "Local-first clinic offboarding; retry upstream cleanup idempotently",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {}
              }
            }
          }
        }
      }
    },
    "/api/integrations/{integrationId}/offboard": {
      "post": {
        "summary": "Legacy signed offboarding; exact raw empty JSON object",
        "security": [
          {
            "webhookTimestamp": [],
            "webhookSignature": []
          }
        ],
        "parameters": [
          {
            "name": "integrationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {}
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/name": {
      "put": {
        "summary": "Set tenant-owned phone nickname; devices:write",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      }
    },
    "/api/admin/companies/{id}/deletion-preview": {
      "get": {
        "summary": "Admin: inspect safe deletion of an empty archived company",
        "description": "Administrator cookie session only; read_only support may inspect. Customer sessions and all API keys are rejected. No query parameters. Returns company identity, opaque revision, affected owners/members and blocker codes, without credentials. Local archive is required; offboarded/provisioning companies, children, custom projects, phones (including revoked), SMS/history/usage, keys (including revoked), integrations, pending invitations, setup and unknown dependencies block deletion. Consent/privacy history is retained. If local checks pass, reads upstream phone inventory; unavailable or nonempty inventory blocks deletion. Preview does not change company data. Local changes while awaiting inventory return company_changed; obtain a fresh preview. See docs/admin-companies.md.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Local company/tenant ID. Query selectors are rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Current deletion preview",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminCompanyDeletionPreview"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query or input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired session",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Administrator session required or access changed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "company_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "company_changed: reload deletion preview",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Shared preview/delete limit: 30 requests per minute per administrator; general API limits also apply",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/companies/{id}": {
      "delete": {
        "summary": "Full admin: permanently delete an empty archived leaf company",
        "description": "Full administrator cookie session, correct Origin and X-CSRF-Token required. No API keys, read_only users, recursive deletion or query parameters. Requires exact company name and revision from a current deletion preview. Rechecks administrator/session access, dependency counts and revision inside an immediate transaction after readonly upstream inventory. Deletes only the empty company and reviewed local metadata. User identities and sibling memberships survive; primary owners are detached and sessions of owners plus members are revoked. Retains company_deleted audit with actor and company ID, without a PII snapshot. No upstream deletion is performed. Repeating DELETE after success returns 404. See docs/admin-companies.md.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Local company/tenant ID. Query selectors are rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AdminCompanyDeleteInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Company deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminCompanyDeleteResult"
                }
              }
            }
          },
          "400": {
            "description": "invalid_company_delete, invalid_company_query or confirmation_mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired session",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Administrator access, full access, session, Origin or CSRF check failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "company_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "company_changed: obtain a fresh preview; company_not_empty: a blocker remains, including unavailable upstream inventory",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Shared preview/delete limit: 30 requests per minute per administrator; general API limits also apply",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/risk-reviews": {
      "get": {
        "summary": "Admin: risk review queue",
        "description": "Accounts paused by risk signals, by state. open: needs review; owner requests first, then the oldest pause. kept: still paused after review. lifted: history. At most 100 reviews; kept and lifted start with the latest decision. Read-only administrators can read the queue.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "open",
                "kept",
                "lifted"
              ],
              "default": "open"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "counts",
                    "reviews"
                  ],
                  "properties": {
                    "status": {
                      "enum": [
                        "open",
                        "kept",
                        "lifted"
                      ]
                    },
                    "counts": {
                      "type": "object",
                      "required": [
                        "open",
                        "kept",
                        "lifted"
                      ],
                      "properties": {
                        "open": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "kept": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "lifted": {
                          "type": "integer",
                          "minimum": 0
                        }
                      },
                      "description": "All reviews by state, not limited to this page."
                    },
                    "messageCounts": {
                      "type": "object",
                      "required": [
                        "held",
                        "decided"
                      ],
                      "properties": {
                        "held": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "decided": {
                          "type": "integer",
                          "minimum": 0
                        }
                      },
                      "description": "SMS held by the text and link check that still wait, and decisions made (GET /api/admin/content-reviews)."
                    },
                    "reviews": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/AdminRiskReview"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_review_status or invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "admin_required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/risk-reviews/{id}/decision": {
      "post": {
        "summary": "Full admin: lift or keep a risk pause",
        "description": "lift ends the pause at once and the account queue resumes with its original messages and expiry; unsent pause emails are cancelled, and later signals count only sends and opt-outs after this moment. keep leaves the pause in place; the owner sees it and may request another review. The reason goes to the decision log and the administration audit (risk_pause_lifted, risk_pause_kept) and is never shown to the account.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "decision",
                  "reason"
                ],
                "properties": {
                  "decision": {
                    "enum": [
                      "lift",
                      "keep"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 1000,
                    "description": "Why; surrounding spaces are removed."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "review"
                  ],
                  "properties": {
                    "review": {
                      "$ref": "#/components/schemas/RiskReview"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_decision",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "admin_required or read_only",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "review_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "review_closed: already lifted; review_already_kept: keep was already chosen",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/content-reviews": {
      "get": {
        "summary": "Admin: SMS held by the text and link check",
        "description": "The other half of the Sending review page (docs/risk-review.md). held: SMS waiting with queueReason content_review, oldest first; an SMS that expired or was cancelled by its owner has nothing left to decide and is not listed. decided: the latest 100 decisions. At most 100 items. Read-only administrators can read the list.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "held",
                "decided"
              ],
              "default": "held"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "counts",
                    "accountCounts",
                    "holds"
                  ],
                  "properties": {
                    "status": {
                      "enum": [
                        "held",
                        "decided"
                      ]
                    },
                    "counts": {
                      "type": "object",
                      "required": [
                        "held",
                        "decided"
                      ],
                      "properties": {
                        "held": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "decided": {
                          "type": "integer",
                          "minimum": 0
                        }
                      }
                    },
                    "accountCounts": {
                      "type": "object",
                      "required": [
                        "open",
                        "kept",
                        "lifted"
                      ],
                      "properties": {
                        "open": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "kept": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "lifted": {
                          "type": "integer",
                          "minimum": 0
                        }
                      },
                      "description": "Risk pauses by state, for the account tabs of the same page."
                    },
                    "holds": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/AdminContentReview"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_content_review_status or invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "admin_required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/content-reviews/{id}/decision": {
      "post": {
        "summary": "Full admin: release or cancel a held SMS",
        "description": "release: the SMS continues through the usual queue checks with its original expiry. cancel: the SMS is cancelled with error CONTENT_REVIEW_CANCELLED and the project receives the usual status webhook. allowDomain (release only) must be one of the hosts in domains; links to it and its subdomains no longer hold this account's SMS under any link rule or credential_phishing, and the account's other held SMS left without findings are released by the same decision (released counts them). code_forwarding does not depend on links. The reason goes to the held SMS and the administration audit (content_hold_released, content_hold_cancelled, content_domain_allowed) and is never shown to the account.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Message ID."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "decision",
                  "reason"
                ],
                "properties": {
                  "decision": {
                    "enum": [
                      "release",
                      "cancel"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 1000,
                    "description": "Why; surrounding spaces are removed."
                  },
                  "allowDomain": {
                    "type": "string",
                    "description": "Optional, release only: a host from domains of this SMS, allowed for this account."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "hold",
                    "released"
                  ],
                  "properties": {
                    "hold": {
                      "$ref": "#/components/schemas/AdminContentReview"
                    },
                    "released": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Other held SMS of the account released by allowDomain."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_content_decision or invalid_allowed_domain",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "admin_required or read_only",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "content_review_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "content_review_closed: already released or cancelled; message_not_queued: the SMS expired or was cancelled by its owner",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/users": {
      "get": {
        "summary": "Admin and read-only support: bounded account list",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Full admin: create staff account",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string",
                    "minLength": 12,
                    "maxLength": 256
                  },
                  "access": {
                    "type": "string",
                    "enum": [
                      "full",
                      "read_only"
                    ]
                  }
                },
                "required": [
                  "name",
                  "email",
                  "password",
                  "access"
                ]
              }
            }
          }
        }
      }
    },
    "/api/admin/users/{id}": {
      "patch": {
        "summary": "Full admin: change access or disable login; revoke sessions; protect last full admin",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "disabled": {
                    "type": "boolean"
                  },
                  "access": {
                    "type": "string",
                    "enum": [
                      "full",
                      "read_only"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/users/{id}/reset-password": {
      "post": {
        "summary": "Full admin: reset account password and revoke sessions",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "newPassword": {
                    "type": "string",
                    "minLength": 12,
                    "maxLength": 256
                  }
                },
                "required": [
                  "newPassword"
                ]
              }
            }
          }
        }
      }
    },
    "/api/admin/audit": {
      "get": {
        "summary": "Last 100 administrative actions; actor/target identifiers, no credentials",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/provisioning/tenants/{id}/restore-key": {
      "post": {
        "summary": "Full admin: explicitly restore a revoked provisioning key; CLI refresh in Magenda required; never returns secret",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {}
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/verification": {
      "get": {
        "summary": "Current verification state of each SIM and historical latest test",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "simNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Enqueue one consenting test through normal SIM policies; same UUID is idempotent; 15-minute expiry",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "test": {
                      "$ref": "#/components/schemas/VerificationTest"
                    }
                  },
                  "required": [
                    "test"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "phone": {
                    "type": "string",
                    "pattern": "^\\+[1-9]\\d{6,14}$"
                  },
                  "consent": {
                    "const": true
                  },
                  "simNumber": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8,
                    "description": "Use explicitly for trustworthy SIM-specific acceptance. Omission preserves the legacy aggregate test, which does not mark a current SIM verified."
                  }
                },
                "required": [
                  "id",
                  "phone",
                  "consent"
                ]
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/verification/{testId}/confirm": {
      "post": {
        "summary": "Confirm receipt, then visibility of the matching reply in the external project",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "testId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "test": {
                      "$ref": "#/components/schemas/VerificationTest"
                    }
                  },
                  "required": [
                    "test"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "step": {
                    "type": "string",
                    "enum": [
                      "received",
                      "integration",
                      "magenda"
                    ],
                    "description": "integration is the canonical completion step; magenda is a backward-compatible alias."
                  }
                },
                "required": [
                  "step"
                ]
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/sending-status": {
      "get": {
        "summary": "Authenticated phone queue and SIM availability snapshot",
        "description": "No query parameters; only this token's active phone. Read-only snapshot: never dispatches or retries SMS. 60 calls/minute per device, 300/minute per IP.",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "X-SendHarbor-Limits-Version",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "2"
              ]
            },
            "description": "Send 2 when the mobile client supports zero hourly, daily and monthly limits. Required when the actual response contains a disabled limit; absence returns 426 app_update_required instead of an incompatible 200. Does not change the actual scheduling policy."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendingStatusSnapshot"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "426": {
            "description": "app_update_required: this request did not negotiate disabled-limit support, or the phone must be upgraded before saving disabled limits. No mutation or SMS resend occurs. Update SendHarbor to 1.17.3 or later without clearing app data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/login/mfa": {
      "post": {
        "summary": "Complete sign-in with an authenticator or unused recovery code",
        "description": "Same-origin request. Success consumes the challenge and the TOTP step/recovery code, then issues a cookie session. Password/factor changes invalidate pending challenges.",
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "challenge": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{43}$"
                  },
                  "code": {
                    "type": "string"
                  }
                },
                "required": [
                  "challenge",
                  "code"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/security": {
      "get": {
        "summary": "Read local account MFA status",
        "description": "Local accounts only; managed platform accounts use their platform authentication.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountSecurity"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/mfa/setup": {
      "post": {
        "summary": "Start authenticator setup after password confirmation",
        "description": "Pending secret expires after 10 minutes. It is not active until /confirm; QR and secret must not be logged or shared.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "password": {
                    "type": "string",
                    "format": "password",
                    "maxLength": 256
                  }
                },
                "required": [
                  "password"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "secret": {
                      "type": "string"
                    },
                    "qrDataUrl": {
                      "type": "string"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "secret",
                    "qrDataUrl",
                    "expiresAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/mfa/confirm": {
      "post": {
        "summary": "Activate MFA and receive recovery codes once",
        "description": "A valid fresh TOTP confirms setup. Other sessions and outstanding login challenges are revoked.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "pattern": "^\\d{6}$"
                  }
                },
                "required": [
                  "code"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecoveryCodes"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/mfa/disable": {
      "post": {
        "summary": "Disable MFA after password and factor confirmation",
        "description": "Forbidden for administrators when REQUIRE_ADMIN_MFA=true. Other sessions and challenges are revoked. Managed accounts are not supported.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "password": {
                    "type": "string",
                    "format": "password",
                    "maxLength": 256
                  },
                  "code": {
                    "type": "string"
                  }
                },
                "required": [
                  "password",
                  "code"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Success"
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/mfa/recovery-codes": {
      "post": {
        "summary": "Replace recovery codes after password and factor confirmation",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "password": {
                    "type": "string",
                    "format": "password",
                    "maxLength": 256
                  },
                  "code": {
                    "type": "string"
                  }
                },
                "required": [
                  "password",
                  "code"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecoveryCodes"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/sessions": {
      "get": {
        "summary": "List current account browser sessions",
        "description": "Opaque public session IDs; no bearer tokens, cookies, IP addresses or secrets are returned.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sessions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AccountSession"
                      }
                    }
                  },
                  "required": [
                    "sessions"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/sessions/{id}": {
      "delete": {
        "summary": "Revoke one own browser session",
        "description": "Revoking the current session also clears its cookie. A session of another user returns 404.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Success"
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/sessions/revoke-others": {
      "post": {
        "summary": "Revoke every other own browser session",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "revokedSessions": {
                      "type": "integer",
                      "minimum": 0
                    }
                  },
                  "required": [
                    "revokedSessions"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/android/rollout": {
      "get": {
        "summary": "Inspect published APK rollout and active phone inventory",
        "description": "Administrator browser session only. Initial policy comes from manifest.rollout, independent of signing channel; new publisher output defaults to pilot with an empty cohort. Legacy manifests without rollout use channel pilot=>pilot, stable=>all. Saved policy belongs to the immutable APK sha256 and overrides the manifest default.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AndroidRollout"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Pause, pilot or enable the published APK",
        "description": "Administrator only. sha256 must match the current APK, or 409 release_changed. Pilot IDs must be active phones of ready tenants; non-pilot modes save an empty cohort. Paused also returns 503 for direct APK download. Does not uninstall or downgrade an installed version.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "mode": {
                    "enum": [
                      "paused",
                      "pilot",
                      "all"
                    ]
                  },
                  "deviceIds": {
                    "type": "array",
                    "maxItems": 1000,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    }
                  }
                },
                "required": [
                  "sha256",
                  "mode",
                  "deviceIds"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "policy": {
                      "$ref": "#/components/schemas/AndroidRolloutPolicy"
                    }
                  },
                  "required": [
                    "policy"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/releases/latest": {
      "get": {
        "summary": "Check update eligibility for this authenticated phone",
        "description": "Same compatibility checks as public latest; a pilot APK is offered only to an allowlisted active phone. Revocation is rechecked after identity lookup. Paused returns 204. Android independently verifies package, higher versionCode, checksum and signing certificate.",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "packageName",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 150
            }
          },
          {
            "name": "versionCode",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "sdk",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 21,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Доступно совместимое обновление; url абсолютный HTTPS",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AndroidUpdate"
                }
              }
            }
          },
          "204": {
            "description": "Подходящего обновления нет, включая несовпадающий package, текущую версию или HTTP origin; also rollout paused or pilot mode for an anonymous request."
          },
          "400": {
            "description": "Некорректные параметры или запрещённый endpoint",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Device access revoked or invalid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/verification": {
      "get": {
        "summary": "Read this phone’s SIM-specific RCS setup and actual SMS test evidence",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "simNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Only the active authenticated phone, no tenantId/deviceId overrides. 60 requests/minute per device, 300/minute per IP. "
      },
      "post": {
        "summary": "Start an explicit-SIM test from the authenticated phone",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "test": {
                      "$ref": "#/components/schemas/VerificationTest"
                    }
                  },
                  "required": [
                    "test"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "phone": {
                    "type": "string",
                    "pattern": "^\\+[1-9]\\d{6,14}$"
                  },
                  "consent": {
                    "const": true
                  },
                  "simNumber": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8,
                    "description": "Use explicitly for trustworthy SIM-specific acceptance. Omission preserves the legacy aggregate test, which does not mark a current SIM verified."
                  }
                },
                "required": [
                  "id",
                  "phone",
                  "consent",
                  "simNumber"
                ]
              }
            }
          }
        },
        "description": "Only the active authenticated phone, no tenantId/deviceId overrides. 60 requests/minute per device, 300/minute per IP.  Consent and simNumber are required. A fixed server-owned test SMS goes to the consenting second phone through the regular queue, rate limits and SIM budgets. Maximum ten new tests/hour/device shared with the web console. Reuse the same id after a transport error; this does not send a duplicate."
      }
    },
    "/api/mobile/v1/verification/{testId}/confirm": {
      "post": {
        "summary": "Confirm the test SMS was seen on the consenting second phone",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "testId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "test": {
                      "$ref": "#/components/schemas/VerificationTest"
                    }
                  },
                  "required": [
                    "test"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "step": {
                    "type": "string",
                    "enum": [
                      "received"
                    ],
                    "description": "User acknowledgment of outbound receipt. integration and magenda are not accepted from phone credentials."
                  }
                },
                "required": [
                  "step"
                ]
              }
            }
          }
        },
        "description": "Only this phone’s own test. step=received records a human acknowledgment only, never actual incoming proof or external-project visibility. Actual incoming is measured separately. No identity or query overrides; rate limits shared with mobile verification."
      }
    },
    "/api/devices/{id}/us-messaging": {
      "get": {
        "summary": "Read manual US A2P registration and carrier-permission records for each SIM",
        "description": "Requires devices:read for API keys. Own revoked phone is readable as history with current=false. Only ready tenants are available. Freshness is five minutes; missing legacy identity is never current. Does not infer US from a +1 number.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for administrators; tenant-bound keys/sessions cannot select another tenant. No other query parameters are accepted."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Manual records and current SIM identity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsMessagingOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict or rate limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/us-messaging/{simNumber}": {
      "put": {
        "summary": "Replace one per-SIM manual registration record with optimistic concurrency",
        "description": "Requires devices:write for API keys, or a full/managed customer session or full administrator. Read-only support cannot write. Cookie writes require CSRF and Origin. Positive claims require fresh accepted SIM identity and a matching sender when Android reports it. Revoked phones reject writes. 30 writes per minute per tenant/device. 409 us_messaging_conflict means revision changed; us_messaging_sim_changed means expected identity changed; us_messaging_identity_required means no current accepted identity; us_messaging_sender_mismatch means the observed number differs. Refresh GET and explicitly review; do not retry stale values blindly. Fixed audit action records actor, device/SIM and time, with no provider/number/IDs in logs. No change to queues, SMS dispatch, permissions, rate limits or actual registration.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for administrators; tenant-bound keys/sessions cannot select another tenant. No other query parameters are accepted."
          },
          {
            "name": "simNumber",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UsMessagingInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved manual record",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "sim"
                  ],
                  "properties": {
                    "sim": {
                      "$ref": "#/components/schemas/UsMessagingSim"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Validation, authorization, conflict or rate limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict or rate limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/us-launch": {
      "get": {
        "summary": "Read neutral SIM compatibility state",
        "description": "devices:read and tenant ownership remain required. Returns required:false and user_managed_sim neutral rows for observed SIMs. Historical reviews are not exposed here and never gate sending. A revoked owned device can be read, without implying current readiness.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for administrators; tenant-bound clients cannot choose another tenant."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Launch records, requirement and current diagnostic identity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsLaunchOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, revision/SIM conflict or rate limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/us-launch/{simNumber}": {
      "put": {
        "summary": "Retired SIM document review operation",
        "description": "SIM document submission and administrator review are no longer required. Normal authentication, scope, tenant ownership and session mutation checks still run; authorized requests to an active owned device receive HTTP 410 sim_review_retired. No submission or approval is stored.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "simNumber",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for administrators; tenant-bound clients cannot choose another tenant."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "410": {
            "description": "sim_review_retired: SIM document review is no longer required. Configure the SIM and its sending limits; no administrator approval can be created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, revision/SIM conflict or rate limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "deprecated": true
      }
    },
    "/api/admin/tenants/{tenantId}/devices/{id}/us-launch/{simNumber}/review": {
      "post": {
        "summary": "Retired SIM document review operation",
        "description": "SIM document submission and administrator review are no longer required. Normal authentication, scope, tenant ownership and session mutation checks still run; authorized requests to an active owned device receive HTTP 410 sim_review_retired. No submission or approval is stored.",
        "parameters": [
          {
            "name": "tenantId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "simNumber",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          }
        ],
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "410": {
            "description": "sim_review_retired: SIM document review is no longer required. Configure the SIM and its sending limits; no administrator approval can be created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, revision/SIM conflict or rate limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "deprecated": true
      }
    },
    "/api/us-consents/{phone}": {
      "get": {
        "summary": "Read customer-reported consent for one recipient",
        "description": "messages:read scope. Full and managed customer sessions may read their tenant; read-only support may read. Missing records return revision 0, empty purposes and status missing. No bulk recipient registry is exposed.",
        "parameters": [
          {
            "name": "phone",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\\+[1-9]\\d{6,14}$"
            },
            "description": "URL-encoded full E.164 recipient number, e.g. %2B12025550101."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for administrators. Tenant-bound sessions and keys cannot select another tenant. No other query parameters are accepted."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Consent metadata, suppression state and deployment requirement",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsConsent"
                }
              }
            }
          },
          "400": {
            "description": "Invalid body or unsupported query parameters; see the operation-specific error codes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Foreign tenant, insufficient scope or read-only mutation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Request failed; error.code identifies the cause.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Record or replace customer-reported recipient consent",
        "description": "messages:send scope. Full/managed tenant sessions or scoped keys; session mutations require Origin and X-CSRF-Token. At most 60 writes per tenant/minute. Cannot clear active STOP or assert verified consent. After START, record newly obtained consent later than the most recent STOP. Purpose, expiry and local window are rechecked at dispatch, including final mobile authorization.",
        "parameters": [
          {
            "name": "phone",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\\+[1-9]\\d{6,14}$"
            },
            "description": "URL-encoded full E.164 recipient number."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for administrators. Tenant-bound sessions and keys cannot select another tenant. No other query parameters are accepted."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UsConsentInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved record with incremented revision",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "consent": {
                      "$ref": "#/components/schemas/UsConsent"
                    }
                  },
                  "required": [
                    "consent"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "invalid_us_consent or invalid_query; full replacement and valid timestamp/window are required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Foreign tenant, insufficient scope or read-only mutation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "us_consent_conflict: reload revision; us_consent_revoked: current STOP or consent no later than latest STOP cannot be overridden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Tenant write rate limit reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Request failed; error.code identifies the cause.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/us-messaging-settings": {
      "get": {
        "summary": "Read the tenant business identity and HELP contact settings",
        "description": "messages:read scope. Full/managed tenant sessions and scoped keys; administrator selects tenantId. Metadata is customer_reported and verified:false. No public control-message creation endpoint exists.",
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for administrators. Tenant-bound sessions and keys cannot select another tenant. No other query parameters are accepted."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current settings, completeness and US profile requirement",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsMessagingSettings"
                }
              }
            }
          },
          "400": {
            "description": "Invalid body or unsupported query parameters; see the operation-specific error codes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Foreign tenant, insufficient scope or read-only mutation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Request failed; error.code identifies the cause.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Replace tenant business identity and HELP contact settings",
        "description": "messages:send scope. Full/managed tenant sessions or scoped keys; session mutations require Origin and X-CSRF-Token. At most 30 writes per tenant/minute. Revision protects against lost updates. Updates invalidate pending control replies created from the old settings; they do not fabricate carrier approval.",
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for administrators. Tenant-bound sessions and keys cannot select another tenant. No other query parameters are accepted."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UsMessagingSettingsInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved settings with incremented revision",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "settings": {
                      "$ref": "#/components/schemas/UsMessagingSettings"
                    }
                  },
                  "required": [
                    "settings"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "invalid_us_business_profile or invalid_query; full replacement and safe contact URLs required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Foreign tenant, insufficient scope or read-only mutation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "us_business_profile_conflict: GET and review the current settings before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Tenant write rate limit reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Request failed; error.code identifies the cause.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/us-setup": {
      "get": {
        "summary": "Read the per-SIM US setup wizard",
        "description": "Requires devices:read. Full/managed customers read their own tenant; admin/support selects tenantId. Recipient queries also require messages:read. Unselected consent is never completed by another recipient. Read-only with no gate mutations, dispatch, expiry sweep or provider calls. Revoked phone remains visible as history. API keys and customers never get administrator review capability.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for an administrator; tenant-bound users/keys cannot select another workspace."
          },
          {
            "name": "simNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            },
            "description": "Defaults to the first known SIM; never silently chooses an approved fallback SIM."
          },
          {
            "name": "recipient",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\+[1-9]\\d{6,14}$"
            },
            "description": "E.164 recipient; requires messages:read in addition to devices:read. Do not place it in a shared URL or client route hash."
          },
          {
            "name": "purpose",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "transactional",
                "marketing"
              ],
              "default": "transactional"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Current setup facts for this phone, never an authorization grant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsSetupOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, access, unavailable device/workspace or rate limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/us-setup": {
      "get": {
        "summary": "Read the paired phone US setup steps",
        "description": "Authenticated device, same canonical read model. Rechecks exact token, ready tenant and revocation after identity resolution. Only simNumber may be selected; no other device, tenant or recipient. Returns no actor/admin actions, full diagnostics, evidence references, sender/recipient numbers, owner email, message IDs/text, endpoint or credentials. At most 60 requests/minute/device and 120/minute/IP.",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "simNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            },
            "description": "Defaults to the first known SIM; never silently chooses an approved fallback SIM."
          }
        ],
        "responses": {
          "200": {
            "description": "Current setup facts for this phone, never an authorization grant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsSetupOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, access, unavailable device/workspace or rate limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/projects": {
      "get": {
        "summary": "Projects accessible to the signed-in account",
        "description": "",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projects": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Project"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        }
      },
      "post": {
        "summary": "Create an isolated project",
        "description": "Workspace owner only. Maximum 20 projects per workspace. externalId is an idempotent workspace-scoped identifier; retry failed setup with the same value. Keys, phones, policies, SMS and callbacks are separated by existing tenant boundaries.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectInput"
              }
            }
          }
        }
      }
    },
    "/api/invitations": {
      "get": {
        "summary": "List recent invitations without bearer tokens",
        "description": "Administrator or selected project owner. projectId query selects a project; accepted/revoked records are retained.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        }
      },
      "post": {
        "summary": "Invite a workspace owner or project member",
        "description": "Workspace owners are invited by the service administrator. Project owners invite operator/viewer members. The returned fragment URL is single-use for 7 days. Store/deliver it privately; it is not included in invitation listings.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InvitationInput"
              }
            }
          }
        }
      }
    },
    "/api/invitations/{id}": {
      "delete": {
        "summary": "Revoke an unused invitation",
        "description": "",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        }
      }
    },
    "/api/invitations/accept": {
      "post": {
        "summary": "Join with a one-use invitation",
        "description": "Origin checked and rate limited. Existing accounts must prove their current password and sign in normally, preserving MFA. New accounts receive an HttpOnly session. May return 200 signInRequired for an existing account, or 410 for used/expired/revoked invitations.",
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Membership added; normal sign-in including existing MFA is required"
          },
          "201": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "410": {
            "description": "Invitation unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InvitationAccept"
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}/members": {
      "get": {
        "summary": "List company owners and invited members",
        "description": "Project owner or service administrator only. Returns owners inherited from this account's workspace or parent integration project, plus the existing members list of explicitly assigned users. Inherited owners cannot be revoked through the membership endpoint. This response is scoped to the requested account and excludes global service administrators.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        }
      }
    },
    "/api/projects/{id}/members/{userId}": {
      "delete": {
        "summary": "Revoke project membership",
        "description": "Takes effect on the next authenticated request. Does not change passwords, delete history or revoke access to other projects.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        }
      }
    },
    "/api/pools": {
      "get": {
        "summary": "Phone pools and setup progress",
        "description": "",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pools": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Pool"
                      }
                    },
                    "setup": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        }
      },
      "post": {
        "summary": "Create a phone pool",
        "description": "devices:write. Maximum 100 pools/project, 50 phones/pool. Empty pools are allowed. Every phone belongs to this project. SIM usage is shared across all pools containing the same phone. Sticky sender is enabled by default.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "201": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PoolInput"
              }
            }
          }
        }
      }
    },
    "/api/pools/{id}": {
      "put": {
        "summary": "Update or pause a phone pool",
        "description": "devices:write. Queues survive pause/device changes. Routes are rechecked before reservation and pool pause is checked at final handset authorization. Removing a phone never automatically retries an already dispatched SMS.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PoolInput"
              }
            }
          }
        }
      }
    },
    "/api/portal-access": {
      "post": {
        "summary": "Create universal one-use managed access",
        "description": "Project key must have devices:read/write and messages:read/send. externalUserId is stable; email is a contact, not authorization. Link expires in 60 seconds; exchange creates a project-scoped 30-minute session. Legacy /api/magenda/portal-access remains available.",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalAccessInput"
              }
            }
          }
        }
      }
    },
    "/api/portal-exchange": {
      "post": {
        "summary": "Exchange fragment token for limited 30-minute HttpOnly tenant session; exact same-origin POST",
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "token": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{43}$"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/project/offboard": {
      "post": {
        "summary": "Local-first clinic offboarding; retry upstream cleanup idempotently",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {}
              }
            }
          }
        }
      }
    },
    "/api/auth/options": {
      "get": {
        "summary": "Account email availability",
        "description": "Only configured capabilities; no user lookup.",
        "security": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "registrationEnabled": {
                      "type": "boolean"
                    },
                    "passwordRecoveryEnabled": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "registrationEnabled",
                    "passwordRecoveryEnabled"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/registration/request": {
      "post": {
        "summary": "Request account email",
        "description": "Request a single-use email link, 30 minutes. Generic 202 also for an existing owner. No account or SMS is created until confirmation. Requires explicit self-registration flag and configured SMTP.",
        "security": [],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accepted": {
                      "const": true
                    },
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "accepted"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountEmailRequest"
              }
            }
          }
        }
      }
    },
    "/api/password-recovery/request": {
      "post": {
        "summary": "Request account email",
        "description": "Request a single-use reset link, 20 minutes. Generic 202 for known/unknown email. Requires configured email; no token is returned.",
        "security": [],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accepted": {
                      "const": true
                    },
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "accepted"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  },
                  "language": {
                    "type": "string",
                    "enum": [
                      "en",
                      "ru"
                    ],
                    "description": "Email language. If omitted, negotiated from Accept-Language, with English as fallback."
                  }
                },
                "required": [
                  "email"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/registration/complete": {
      "post": {
        "summary": "Confirm email and create workspace",
        "description": "The fragment token is submitted only in the body. New account returns a session; an existing member must supply the current password and use ordinary login/MFA afterward. Gateway setup retries reuse the same workspace. 201 for a new session, 200 signInRequired for existing users. Normal installations require terms: fetch GET /api/legal/terms/current, show the full exact document and one unchecked explicit assent declaration with authority wording appropriate to individual/business capacity. Missing explicit assent is 428 before workspace provisioning; stale version/digest is 409. Refresh the document and obtain fresh assent. Existing login/reset does not silently sign. Send only {token, check: true} to check an opened link before showing the form: 204 while it works, 410 when it expired, was replaced or was used; nothing is created.",
        "security": [],
        "responses": {
          "200": {
            "description": "Existing account must sign in normally",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "signInRequired": {
                      "const": true
                    }
                  },
                  "required": [
                    "signInRequired"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner terms acceptance required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "token": {
                        "type": "string",
                        "pattern": "^[A-Za-z0-9_-]{43}$"
                      },
                      "password": {
                        "type": "string",
                        "format": "password",
                        "minLength": 12,
                        "maxLength": 256
                      },
                      "terms": {
                        "$ref": "#/components/schemas/ServiceTermsInput"
                      }
                    },
                    "required": [
                      "token",
                      "password"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "$ref": "#/components/schemas/AccountAccessCheck"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/api/password-recovery/complete": {
      "post": {
        "summary": "Reset password",
        "description": "Single use and invalidated by password change. Enabled MFA requires a fresh authenticator or recovery code. All browser sessions are revoked; factors, project keys, phones and queues are preserved. Send only {token, check: true} to check an opened link before showing the form: 204 while it works, 410 when it expired, was replaced, was used or the password changed since; nothing is changed.",
        "security": [],
        "responses": {
          "204": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/AccountAccessComplete"
                  },
                  {
                    "$ref": "#/components/schemas/AccountAccessCheck"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}": {
      "put": {
        "summary": "Update project lifecycle",
        "description": "Owner session only. Pause retains queued SMS with original TTL. Archive blocks new admissions and cancels unused enrollment QR. History and incoming events remain accessible. Restore never extends deadlines; in-flight outcomes are not retransmitted.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "project": {
                      "$ref": "#/components/schemas/Project"
                    }
                  },
                  "required": [
                    "project"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Session project selector; an API key remains bound to its project."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "paused": {
                    "type": "boolean"
                  },
                  "archived": {
                    "type": "boolean"
                  }
                },
                "required": [],
                "additionalProperties": false,
                "minProperties": 1
              }
            }
          }
        }
      }
    },
    "/api/invitations/{id}/reissue": {
      "post": {
        "summary": "Reissue invitation",
        "description": "Owner/admin session only. Revokes old link, preserves recipient/role and returns a new single-use 7-day link once. Used/revoked invitations cannot be reissued.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "email": {
                      "type": "string",
                      "format": "email"
                    },
                    "role": {
                      "type": "string"
                    },
                    "projectId": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "id",
                    "url",
                    "expiresAt"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Session project selector; an API key remains bound to its project."
          }
        ]
      }
    },
    "/api/routes/preview": {
      "post": {
        "summary": "Preview a pool route",
        "description": "Requires devices:read and messages:send. Reads current diagnostics/policies/consent/sticky sender and queue without creating a message, reserving capacity, or contacting a carrier. An eligible route is a snapshot, not a promise. Viewers cannot submit previews.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RoutePreview"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Session project selector; an API key remains bound to its project."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "poolId": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string",
                    "pattern": "^\\+[1-9]\\d{6,14}$"
                  },
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 5000
                  },
                  "purpose": {
                    "enum": [
                      "transactional",
                      "marketing"
                    ]
                  }
                },
                "required": [
                  "poolId",
                  "phone",
                  "text"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/router/status": {
      "get": {
        "summary": "Read project operations",
        "description": "Requires devices:read and messages:read. Scoped counts/reasons, oldest queue age, webhook backlog, admitted monthly usage and observed latency. Recent phone contact is not evidence of carrier balance or permission.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RouterStatus"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Session project selector; an API key remains bound to its project."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ]
      }
    },
    "/api/admin/mail-status": {
      "get": {
        "summary": "Admin account mail health",
        "description": "Administrator session only. Aggregate queue/failure counts, no addresses, tokens, payloads or credentials.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/integrations/project/probe": {
      "post": {
        "summary": "Test signed webhook without SMS",
        "description": "Requires integrations:write. Creates one durable integration.test event with normal signatures/retries. Does not send or reserve SMS.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "eventId": {
                      "type": "string"
                    },
                    "messageCreated": {
                      "const": false
                    }
                  },
                  "required": [
                    "eventId",
                    "messageCreated"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Session project selector; an API key remains bound to its project."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ]
      }
    },
    "/api/integrations/project/probes/{id}": {
      "get": {
        "summary": "Read webhook probe result",
        "description": "Requires integrations:write. Only integration.test events of this project; no payload or secret.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Session project selector; an API key remains bound to its project."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ]
      }
    },
    "/api/platforms": {
      "get": {
        "summary": "List owned platform projects",
        "description": "Owner session; admin may list all. Includes default legacy standalone parents.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      },
      "post": {
        "summary": "Create a platform project",
        "description": "Workspace owner. externalId is workspace-scoped/idempotent. New creation shows master key and webhook secret once; retry never discloses them again.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "description": "Admin must select a workspace owner root.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "404": {
            "description": "Selected administrator workspace does not exist"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlatformInput"
              }
            }
          }
        }
      }
    },
    "/api/platforms/{id}": {
      "put": {
        "summary": "Pause, archive or restore platform",
        "description": "Owner only. Applies sending hold to all child accounts, preserves TTL/history, archive cancels unfinished QR.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlatformSettings"
              }
            }
          }
        }
      }
    },
    "/api/platforms/{id}/integration": {
      "get": {
        "summary": "Read platform integration metadata",
        "description": "URLs, masked key prefixes/scopes, webhook metadata; no raw secrets.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      }
    },
    "/api/platforms/{id}/keys": {
      "post": {
        "summary": "Issue platform key",
        "description": "Owner only; explicit least-privilege scopes; raw secret shown once.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlatformKeyInput"
              }
            }
          }
        }
      }
    },
    "/api/platforms/{id}/keys/{keyId}": {
      "delete": {
        "summary": "Revoke platform key",
        "description": "Revokes internal account grants, managed sessions and pending enrollment source. Existing phone tokens/accepted SMS remain.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      }
    },
    "/api/platforms/{id}/webhook": {
      "put": {
        "summary": "Configure inherited webhook",
        "description": "Public HTTPS endpoint, no credentials/query/fragment. New managed accounts inherit it; legacy callbacks preserved. Owner only. Offboarded child accounts remain disabled and are not resynchronized.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlatformWebhookInput"
              }
            }
          }
        }
      }
    },
    "/api/platforms/{id}/webhook/rotate": {
      "post": {
        "summary": "Rotate shared signing secret",
        "description": "Owner only. Immediate replacement for managed accounts; new webhookSecret shown once.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      }
    },
    "/api/platforms/{id}/accounts": {
      "get": {
        "summary": "List isolated client accounts",
        "description": "Own platform only, accounts:read. Sorted by name, then account ID. Cursor pagination: pass nextAfter (an account ID) as after.",
        "security": [
          {
            "session": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Optional case-insensitive filter by account name or externalId.",
            "schema": {
              "type": "string",
              "maxLength": 120
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      },
      "post": {
        "summary": "Provision isolated client account",
        "description": "Own platform, accounts:write. Same externalId resumes the same account after gateway outage. Matching email never links users or merges data. Returns immutable accountId; webhook inherited automatically.",
        "security": [
          {
            "session": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlatformAccountInput"
              }
            }
          }
        }
      }
    },
    "/api/platforms/{id}/usage": {
      "get": {
        "summary": "Read platform usage",
        "description": "usage:read; immutable accepted/attempted/sent/delivered messages and segments, split business/verification/control and observed/backfill. UTC period. Stages are not additive charges. billing free amount=0.",
        "security": [
          {
            "session": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      }
    },
    "/api/usage": {
      "get": {
        "summary": "Read selected account usage",
        "description": "messages:read; only selected account. Same free usage ledger.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input or missing account selector"
          },
          "401": {
            "description": "Invalid/revoked credential"
          },
          "403": {
            "description": "Access denied"
          },
          "409": {
            "description": "Conflict"
          },
          "429": {
            "description": "Rate limit"
          }
        }
      }
    },
    "/api/batches": {
      "get": {
        "summary": "List selected account batches",
        "description": "messages:read. Cursor pagination, optional stable externalId filter. List returns summaries; detail contains messages.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Required with platform key, or use X-SendHarbor-Account."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "externalId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid or revoked source"
          },
          "403": {
            "description": "Insufficient scope or foreign account"
          },
          "404": {
            "description": "Not found in selected account"
          },
          "409": {
            "description": "Channel disabled, immutable batch conflict, or expired event cursor"
          },
          "429": {
            "description": "Rate/connection limit"
          }
        }
      }
    },
    "/api/batches/{id}": {
      "get": {
        "summary": "Read batch and per-message outcomes",
        "description": "messages:read. Immutable batch membership; current live message states. completed may include sent without delivery receipt; inspect deliveryConfirmed.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Required with platform key, or use X-SendHarbor-Account."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid or revoked source"
          },
          "403": {
            "description": "Insufficient scope or foreign account"
          },
          "404": {
            "description": "Not found in selected account"
          },
          "409": {
            "description": "Channel disabled, immutable batch conflict, or expired event cursor"
          },
          "429": {
            "description": "Rate/connection limit"
          }
        }
      }
    },
    "/api/realtime/tickets": {
      "post": {
        "summary": "Mint a one-use account-bound WebSocket ticket",
        "description": "messages:read and websocket channel. Expires in60 seconds; authenticated source rechecked at upgrade and on every command/poll. Do not put API keys/tickets in URL. Use subprotocols returned by this call. Cookie session writes require CSRF.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Required with platform key, or use X-SendHarbor-Account."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid or revoked source"
          },
          "403": {
            "description": "Insufficient scope or foreign account"
          },
          "404": {
            "description": "Not found in selected account"
          },
          "409": {
            "description": "Channel disabled, immutable batch conflict, or expired event cursor"
          },
          "428": {
            "description": "Contracting workspace owner must accept current terms; see error.legal. Existing queues keep original deadlines; reads, cancellation and inbound opt-outs continue.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate/connection limit"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/realtime/events": {
      "get": {
        "summary": "Read resumable selected-account event journal",
        "description": "messages:read and websocket channel. JSON events with per-account cursor semantics. Retention:7 days /10,000 events per account;409 reset_required on a pruned gap. Reconcile message/batch state and explicitly handle lost incoming history.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Required with platform key, or use X-SendHarbor-Account."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid or revoked source"
          },
          "403": {
            "description": "Insufficient scope or foreign account"
          },
          "404": {
            "description": "Not found in selected account"
          },
          "409": {
            "description": "Channel disabled, immutable batch conflict, or expired event cursor"
          },
          "429": {
            "description": "Rate/connection limit"
          }
        }
      }
    },
    "/api/integrations/project/batches/{id}": {
      "get": {
        "summary": "Read signed batch-command admission status",
        "description": "integrations:write for API keys. state pending/processing/accepted/failed; batchId is assigned after atomic admission. This is not the per-SMS delivery status.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Required with platform key, or use X-SendHarbor-Account."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid or revoked source"
          },
          "403": {
            "description": "Insufficient scope or foreign account"
          },
          "404": {
            "description": "Not found in selected account"
          },
          "409": {
            "description": "Channel disabled, immutable batch conflict, or expired event cursor"
          },
          "429": {
            "description": "Rate/connection limit"
          }
        }
      }
    },
    "/api/realtime": {
      "get": {
        "summary": "Upgrade to the account-bound WebSocket command/event stream",
        "security": [
          {
            "websocketTicket": []
          }
        ],
        "description": "GET upgrade only; no URL query accepted. Origin, if supplied, must equal configured public origin. Server frames: ready/result/error/event/reset_required. Event has sequence and canonical webhook-compatible event envelope; confirm durable processing before persisting sequence. New ticket required on reconnect.4 connections/account,128/process; slow consumers close1013. Source revocation/channel disable closes1008; frame limit256KiB. See RealtimeCommand and docs/integration-channels.md.",
        "responses": {
          "101": {
            "description": "WebSocket upgrade"
          },
          "401": {
            "description": "Expired/used/revoked ticket"
          },
          "403": {
            "description": "Foreign Origin"
          },
          "429": {
            "description": "Connection/rate limit"
          }
        }
      }
    },
    "/api/sandbox": {
      "get": {
        "summary": "Read virtual phone and recent sandbox tests",
        "description": "messages:read. Separate history, two virtual SIMs, scenarios and limits. No gateway call or real usage ledger entry.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ]
      }
    },
    "/api/sandbox/messages": {
      "post": {
        "summary": "Simulate an SMS",
        "description": "messages:send. Atomic idempotent simulation; default delivered. offline/limit wait for explicit simulated resume. unknown never auto-retries. emitWebhook opt-in sends signed sandbox.* events to the existing active account callback; failures roll back admission. Test callbacks use a separate bounded outbox (500 pending/failed events or4MiB/account); they cannot block real callback/SMS capacity. Headers include X-SendHarbor-Sandbox:1 and the normal raw-body HMAC.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxMessageResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SandboxMessageInput"
              }
            }
          }
        }
      }
    },
    "/api/sandbox/messages/{id}": {
      "get": {
        "summary": "Read a simulated message",
        "description": "Only this account; no cross-read between real and sandbox APIs.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxMessageResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ]
      }
    },
    "/api/sandbox/messages/{id}/resume": {
      "post": {
        "summary": "Restore a simulated offline/limited route",
        "description": "Requires messages:send. Never bypasses sendAt: 409 sandbox_schedule_not_due before time. Once due, processes the scheduled scenario. Offline/limit scenarios then require an explicit resume to simulate recovery; already-delivered replays create no events. Failed/unknown outcomes are never retried. Empty object only.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxMessageResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/sandbox/messages/batch": {
      "post": {
        "summary": "Simulate an atomic named batch",
        "description": "1–100 items. Stable batchId, deterministic missing item keys, immutable membership; no real SMS. Maximum1000 stored messages and1000 batches/account; existing retries stay readable/replayable.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "batchId",
                  "items"
                ],
                "properties": {
                  "batchId": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "$ref": "#/components/schemas/SandboxBatchItem"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sandbox/batches/{id}": {
      "get": {
        "summary": "Read a sandbox batch",
        "description": "Account-isolated simulated membership/outcomes.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ]
      }
    },
    "/api/sandbox/events": {
      "get": {
        "summary": "Poll simulated events",
        "description": "Up to100 events, account-filtered global opaque sequence. Retained7 days during maintenance. No real message/counter mutation. Each event includes callback:null or callback metadata with status, attempts, lastError, deliveredAt.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          }
        ]
      }
    },
    "/api/sandbox/incoming": {
      "post": {
        "summary": "Simulate an incoming reply",
        "description": "Idempotent sandbox.sms.received; no physical inbox, consent/suppression or real conversation mutation.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SandboxIncomingInput"
              }
            }
          }
        }
      }
    },
    "/api/sandbox/keys": {
      "get": {
        "summary": "List test-key metadata",
        "description": "Ordinary owner/session or scoped backend key; test keys cannot manage credentials.",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ]
      },
      "post": {
        "summary": "Create a once-only sandbox key",
        "description": "messages:send and messages:read. Owner or ordinary backend key. Seven days, up to10 active/account. Only /api/sandbox; stored hash and metadata, secret shown once. Operators/viewers cannot create.",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sandbox/keys/{id}": {
      "delete": {
        "summary": "Revoke a test key",
        "description": "Ordinary backend credential/owner. Account-bound, no real-key mutation.",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "204": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ]
      }
    },
    "/api/onboarding-sessions": {
      "post": {
        "summary": "Create a temporary phone connection for iframe or custom API UI",
        "description": "devices:read + devices:write, integrations:write when webhook is supplied. Idempotent QR and link; default20min. Link fragment is a restricted capability; private and bound to one pairing/phone. allowedOrigin controls only /connect embedding. Reuse same ID/body on lost response, including after a successful scan while link remains valid. Use the returned private link with the optional iframe, or extract its restricted fragment token on your backend and call GET /api/onboarding/status to render a custom UI without any iframe. Omit allowedOrigin for API-only usage. Both approaches share the same account isolation, QR, expiry, SIM gates and idempotency; a mode setting is not required. Setup creation is allowed while only this customer Sender Agreement is pending. The integrator must have accepted its own terms. Sender responsibility follows the workspace choice. Status may expose a QR with legal.acceptInApp=true while acceptance is pending; scanning opens native acceptance, not enrollment or permission to send. Client proof remains separate from owner coverage. A webhook supplied by an ordinary cookie user additionally requires project owner authority. Issuer authority is rechecked after asynchronous enrollment/QR work; revocation invalidates unused capabilities.",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "410": {
            "description": "Original link expired/revoked; old request cannot mint a replacement QR."
          },
          "428": {
            "description": "Contracting workspace owner must accept current terms; see error.legal. Existing queues keep original deadlines; reads, cancellation and inbound opt-outs continue.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OnboardingInput"
              }
            }
          }
        }
      }
    },
    "/api/onboarding-sessions/{id}": {
      "delete": {
        "summary": "Revoke a connection link",
        "description": "devices:write. Cancels its pending QR; already connected phone remains linked. Revoke the phone separately when required.",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "204": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ]
      },
      "get": {
        "summary": "Resume the same private connection guide",
        "description": "Requires devices:read AND devices:write. Returns the existing temporary capability for this account only; does not create a pairing or a phone. Expired or revoked links return 410. Use renew for an already linked phone, or explicitly revoke/create a new pending QR.",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and owner/administrator sessions. sgk_ keys are already account-bound. Sandbox keys cannot read connection links."
          }
        ],
        "responses": {
          "200": {
            "description": "Existing private link; no new QR or enrollment",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "session": {
                      "type": "object"
                    },
                    "pairing": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string"
                        },
                        "deviceId": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Source revoked or unauthenticated"
          },
          "403": {
            "description": "Account or scopes forbidden"
          },
          "404": {
            "description": "No such link in selected account"
          },
          "410": {
            "description": "Link expired or revoked"
          }
        }
      }
    },
    "/api/onboarding/status": {
      "get": {
        "summary": "Read only the bound phone setup",
        "description": "Read the scoped connection using the short-lived onboarding capability. In mode=self_service, ready requires a connected, current, technically ready configured initial SIM. Other discovered SIMs keep individual status and cannot delay a usable configured route. Recommendations, sender profile, RCS acknowledgements and optional tests do not gate completion. ready never claims a test SMS was sent. Active legal/account restrictions, stale diagnostics, identity and permission checks still apply; no secret, message content or unrelated account is returned. No query/account/device selector. Revoked source key/user/principal/phone closes access; expiry is HTTP 410. Supports backend-to-backend polling for a custom onboarding UI without browser, cookie or iframe. Authenticate your end user and verify access to the stored account/session before relaying QR or status. Never expose the project key in client JavaScript. stage=agreement exposes legal.acceptanceMode and integratorAccepted to identify the required signer. legal.acceptInApp plus a pending pairing QR offers native acceptance without a website login. A company owner hold never requires customers to accept for the owner; the iframe waits and updates automatically.",
        "security": [
          {
            "onboardingLink": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OnboardingStatus"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "410": {
            "description": "Expired/cancelled onboarding link; request a fresh ID/link in the source project."
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        }
      }
    },
    "/api/sandbox/events/{id}/retry": {
      "post": {
        "summary": "Retry a failed sandbox callback",
        "description": "messages:send. Empty body. Same event ID and raw payload, no new SMS/test event. Pending retry is idempotent; already delivered returns409. Separate from real outbox.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Test callback queued"
          },
          "401": {
            "description": "Invalid key"
          },
          "403": {
            "description": "Foreign account or insufficient scope"
          },
          "404": {
            "description": "Test event not found"
          },
          "409": {
            "description": "Already delivered"
          }
        }
      }
    },
    "/api/onboarding-sessions/{id}/renew": {
      "post": {
        "summary": "Resume setup of the same linked phone after link expiry or key rotation",
        "description": "devices:read + devices:write. No new pairing, QR or phone enrollment. Account-bound original session metadata, active existing phone/principal and current caller authority required. Pending/failed pairings reject409. Stable renewal attempt ID returns the same new private URL; old capability remains expired/revoked. Embedding origin is preserved.",
        "security": [
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "idempotencyKey"
                ],
                "properties": {
                  "idempotencyKey": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._:-]{1,128}$"
                  },
                  "ttlSeconds": {
                    "type": "integer",
                    "minimum": 60,
                    "maximum": 3600,
                    "default": 1200
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Fresh scoped link for the same pairing/device (also on idempotent replay)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "session",
                    "url",
                    "deviceId",
                    "resumed"
                  ],
                  "properties": {
                    "session": {
                      "type": "object"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "deviceId": {
                      "type": "string"
                    },
                    "resumed": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid/revoked source credential"
          },
          "403": {
            "description": "Foreign account or insufficient scope"
          },
          "404": {
            "description": "No such account-bound original session"
          },
          "409": {
            "description": "Not linked, changed renewal body or project hold"
          },
          "410": {
            "description": "This renewal attempt already expired; use a new explicit attempt ID"
          }
        }
      }
    },
    "/api/overview": {
      "get": {
        "summary": "Read a global overview of accessible accounts",
        "description": "Ordinary cookie session only; managed sessions and API keys are rejected. Uses the same visibility as /api/projects, including explicit project membership; administrators see all non-offboarded accounts. Archived accounts and archived parent projects are excluded from business metrics and counted separately; for administrators summary.archived also counts offboarded accounts. Paused queues remain included. q/filter/after/limit filter only account rows, never global metrics, summary, attention or waiting. filter defaults to all; attention selects attentionKind=issue, setup selects attentionKind=setup, waiting selects primary issue queue_waiting or phone_waiting, paused selects primary issue paused. These filters return every matching accessible account across pages, not only the short attention preview. Search and filter are combined. Reset after when changing search or filter; a cursor remains an authorized account position, not a snapshot or a filter-bound token. Account rows are ordered by name, then ID; after is the previous page's nextAfter account ID. Current queue covers all live business SMS; last24h is a creation cohort, not send-event throughput. Sent includes Delivered. Verification/control SMS and sandbox are excluded. Phone contact does not prove technical SIM readiness or delivery. validUntil is bounded by metric/contact evidence; unavailable or expired data must not be shown as zero or healthy. No SMS bodies, numbers, contact emails or credentials returned. Read-only; creates no SMS or credentials. waiting lists at most two accounts with a fresh phone-local rate/work-hours/interval hold, independently of directory filters. It is a wait, not an unknown modem outcome. mail is present only for administrators. Custom dates are validated calendar days in explicit UTC. from/to/timeZone are accepted only with period=custom. Changing the range invalidates activity/feed cursors. summary.sent uses actual sent_at for bounded periods; all-time also includes confirmed Sent/Delivered records with no usable send timestamp. summary.sentWithoutTimestamp counts these records independently of the selected period, so the UI can explain their inclusion or exclusion. Their send time is never inferred from observation or delivery time.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 120
            },
            "description": "Case-insensitive account/project name filter, rows only."
          },
          {
            "name": "filter",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "attention",
                "setup",
                "waiting",
                "paused"
              ],
              "default": "all"
            },
            "description": "Account rows only: all accessible active accounts, operational attention, initial setup, automatic waiting, or paused. Combine with q; matched counts the full filtered result before pagination. Never narrows global counters or attention/waiting previews."
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Last account ID from nextAfter; rows continue in name, then ID order. Only an account visible to the caller is accepted; any other ID returns 400 invalid_overview."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "1h",
                "24h",
                "7d",
                "30d",
                "all",
                "custom"
              ],
              "default": "all"
            },
            "description": "Historical range. custom requires from, to and timeZone=UTC; both dates are inclusive. Current operational counts remain current regardless of historical bounds."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "Inclusive starting calendar date in UTC, not before 1970-01-01 or after today UTC. Required with period=custom."
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "Inclusive ending calendar date in UTC, not earlier than from. Future end dates are capped at the current snapshot. Required with period=custom."
            }
          },
          {
            "name": "timeZone",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "UTC"
              ],
              "description": "Explicit calendar timezone. Currently only UTC is supported. Required with period=custom."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh server snapshot; Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "generatedAt",
                    "validUntil",
                    "scope",
                    "metrics",
                    "summary",
                    "attention",
                    "accounts",
                    "matched",
                    "hasMore",
                    "nextAfter"
                  ],
                  "properties": {
                    "generatedAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "validUntil": {
                      "type": "string",
                      "format": "date-time",
                      "description": "The snapshot must be refreshed at this deadline, including ordinary outgoing SMS sent_at and incoming stored_at entering or leaving the 24-hour windows. Phone contact or a fresh snapshot is not proof of sending readiness."
                    },
                    "scope": {
                      "type": "string",
                      "enum": [
                        "visible_non_archived_accounts"
                      ]
                    },
                    "metrics": {
                      "$ref": "#/components/schemas/MessageMetrics"
                    },
                    "summary": {
                      "type": "object",
                      "properties": {
                        "accounts": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "archived": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "phones": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "inContact": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "needsAction": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "waiting": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "paused": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "webhookPending": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "webhookFailed": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "needsSetup": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Initial setup accounts without a phone or current/recent business traffic; not an operational incident."
                        },
                        "needsAttention": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Operational action accounts. needsAction equals needsSetup + needsAttention, across the full authorized scope."
                        },
                        "phonesOffline": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Non-revoked phones without server contact in the last five minutes; equals phones minus inContact. This is not proof that a SIM cannot send."
                        },
                        "phonesAttention": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Non-revoked phones with fresh diagnostics reporting a non-advisory warning or error. Recommendations such as notification or battery settings are excluded."
                        },
                        "phonesUnchecked": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Non-revoked phones without fresh valid diagnostics. May overlap phonesOffline; do not add these counters to derive the number of phones."
                        },
                        "receivedLast24h": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Incoming SMS stored by SendHarbor within the inclusive 24-hour window ending at generatedAt, based on immutable incoming_messages.stored_at rather than the phone clock. Duplicate uploads count once; redacted and legacy receipts without text still count. Covers all authorized non-archived accounts, independently of search and pagination. No message content is included."
                        },
                        "sentLast24h": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Ordinary outgoing SMS currently Sent or Delivered with sent_at in the inclusive 24-hour window ending at generatedAt, including messages created earlier and held in a queue. Counts messages, not segments. Excludes sandbox, verification and control traffic. Covers all authorized non-archived accounts independently of search, filter and pagination; does not replace the created-at cohort in metrics.last24h."
                        },
                        "sentLast24hDelivered": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Subset of summary.sentLast24h whose current state is Delivered. This is delivery confirmation for messages sent in that sent_at window, not a separate delivered_at throughput count. Always at most sentLast24h."
                        },
                        "sentWithoutTimestamp": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Confirmed Sent/Delivered records with no usable sent_at. Included in summary.sent only for period=all; excluded from bounded periods."
                        }
                      }
                    },
                    "attention": {
                      "type": "array",
                      "maxItems": 6,
                      "items": {
                        "type": "object",
                        "properties": {
                          "attentionKind": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "enum": [
                              "setup",
                              "issue",
                              null
                            ],
                            "description": "Presentation category of the primary issue. Setup never includes an active queue, processing/unknown outcomes, phones or recent business traffic; waits/paused/healthy use null."
                          },
                          "receivedLast24h": {
                            "type": "integer",
                            "minimum": 0,
                            "description": "Incoming SMS stored for this account in the last 24 hours, using the same stored_at window and deduplication as summary.receivedLast24h."
                          }
                        }
                      },
                      "description": "Up to three operational issues followed by up to three initial setup accounts across the full authorized scope, independent of row search/filter/pagination."
                    },
                    "accounts": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "type": "object",
                        "properties": {
                          "attentionKind": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "enum": [
                              "setup",
                              "issue",
                              null
                            ],
                            "description": "Presentation category of the primary issue. Setup never includes an active queue, processing/unknown outcomes, phones or recent business traffic; waits/paused/healthy use null."
                          },
                          "receivedLast24h": {
                            "type": "integer",
                            "minimum": 0,
                            "description": "Incoming SMS stored for this account in the last 24 hours, using the same stored_at window and deduplication as summary.receivedLast24h."
                          }
                        }
                      },
                      "description": "Account identity/role, current and last24h business counts, contact counts, queue reasons/retry-check timestamps, webhook backlog and primary issue. Phone contact is not full sending readiness. phoneHolds contains deviceId, reason (phone_rate_limit, phone_work_hours, phone_interval), collectedAt and nextEligibleAt. Freshness is at most 5 minutes with at most 60 seconds clock lead; expired or invalid evidence is omitted. ETA is a recheck time, not a guaranteed dispatch time. issue=phone_waiting is not counted as needsAction. phoneIssue is null or a fresh server-known diagnostic check (deviceId, deviceName, checkId, status=error|warning). Stale evidence is omitted. This never infers SIM balance or an operator limit."
                    },
                    "matched": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Count of all accessible non-archived accounts matching q and filter, before cursor pagination."
                    },
                    "hasMore": {
                      "type": "boolean"
                    },
                    "nextAfter": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "runtime": {
                      "type": "object",
                      "required": [
                        "backgroundProcessingEnabled"
                      ],
                      "properties": {
                        "backgroundProcessingEnabled": {
                          "type": "boolean",
                          "description": "Whether this process starts the sending/integration background workers. Configuration state, not proof of successful processing or delivery."
                        }
                      }
                    },
                    "mail": {
                      "$ref": "#/components/schemas/MailHealth",
                      "description": "Omitted for every non-administrator."
                    },
                    "waiting": {
                      "type": "array",
                      "maxItems": 2,
                      "items": {
                        "type": "object"
                      },
                      "description": "Automatic phone-local waits across the authorized scope, independent of row search/filter/pagination. Same account shape as accounts."
                    },
                    "period": {
                      "type": "string",
                      "enum": [
                        "1h",
                        "24h",
                        "7d",
                        "30d",
                        "all",
                        "custom"
                      ]
                    },
                    "range": {
                      "$ref": "#/components/schemas/HistoryRange"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unsupported, repeated or invalid query/filter, or unauthorized cursor; account/tenant selectors are not accepted. filter accepts exactly all, attention, setup, waiting or paused."
          },
          "401": {
            "description": "Sign-in required."
          },
          "403": {
            "description": "Ordinary session required."
          },
          "429": {
            "description": "60 reads per minute per user."
          }
        }
      }
    },
    "/api/messages/preview": {
      "post": {
        "summary": "Analyze SMS text without sending",
        "description": "Requires messages:send and an explicit authorized account. Computes GSM-7/UCS-2 parts, Unicode causes, optional punctuation savings and a maxSegments check. No message, capacity reservation, database write or carrier call. Does not determine actual carrier charges, consent or route readiness. With templateId instead of text, the saved template of the selected account is rendered with variables first, and the response also contains text: the final SMS text that was analysed. Send that text with POST /api/messages; sending by templateId is not supported. A missing, empty or blank variable returns 400 template_variables_missing with error.missingVariables. Any template is 404 outside its account.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SmsPreflight"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Template or account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Session project selector; an API key remains bound to its project."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MessagePreviewInput"
              }
            }
          }
        }
      }
    },
    "/api/sandbox/messages/preview": {
      "post": {
        "summary": "Analyze SMS text without sending",
        "description": "Same read-only text analysis with isolated sandbox credentials. No real SMS or capacity reservation.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SmsPreflight"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Session project selector; an API key remains bound to its project."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SmsPreflightInput"
              }
            }
          }
        }
      }
    },
    "/api/sandbox/messages/{id}/cancel": {
      "post": {
        "summary": "Cancel a queued sandbox test",
        "description": "Account-scoped, duplicate-safe cancellation. Allowed while the project is paused. A cancelled scheduled job never executes. Requires messages:send. Empty object only.",
        "security": [
          {
            "sandboxKey": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxMessageResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Expired/revoked credential"
          },
          "403": {
            "description": "Account/scopes forbidden"
          },
          "409": {
            "description": "Conflict, stale revision, late replacement or unavailable integration"
          },
          "503": {
            "description": "Bounded queue/history capacity reached"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Explicit account for spk_ and administrator sessions; sgk_/ssk_ are already account-bound."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/sender-terms": {
      "get": {
        "summary": "Selected customer Sender Agreement status",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "description": "devices:read and ordinary account selection/isolation. Parent platform key needs explicit accountId. Minimal receipt for keys; full history only for authorized non-managed owner/admin sessions. No acceptance mutation exists here.",
        "responses": {
          "200": {
            "description": "This account only",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SenderTermsStatus"
                }
              }
            }
          },
          "403": {
            "description": "Foreign account or insufficient scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/onboarding/terms/request": {
      "post": {
        "summary": "Request independent customer email proof",
        "security": [
          {
            "onboardingLink": []
          }
        ],
        "description": "Same restricted capability as onboarding status. Rejects query account/device/project selectors. Requires active source, current integrator assent and a non-paused account. No cookies or API key can sign. The current sender terms, declared identity and server-derived account/project are frozen encrypted; the code is sent by the installation mail provider. Retry same body/key after a lost response. New explicit resend ID invalidates earlier session proof. This is individual or authorized business assent, not SMS-recipient marketing consent. Available only in customer mode. A concurrent choice/revision change invalidates unfinished proof and returns409; refresh status. Company coverage does not create a customer receipt.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "idempotencyKey",
                  "email",
                  "terms"
                ],
                "properties": {
                  "idempotencyKey": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "terms": {
                    "$ref": "#/components/schemas/SenderTermsInput"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Challenge queued; delivery is asynchronous",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SenderTermsChallenge"
                }
              }
            }
          },
          "400": {
            "description": "Unknown fields or invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid/revoked source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Terms version changed, retry conflict or already accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Setup/challenge expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Integrator assent or explicit sender declarations required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Email unavailable; no acceptance recorded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/onboarding/terms/confirm": {
      "post": {
        "summary": "Confirm email code and accept for this customer account",
        "security": [
          {
            "onboardingLink": []
          }
        ],
        "description": "Same active restricted session as the challenge. Confirms its account/project/source/version, expiry and maximum five guesses; invalid guesses persist. Atomic immutable receipt, no SMS attempt. Concurrent exact successful retries return the first receipt. Use current status after success; another account remains blocked.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "challengeId",
                  "code"
                ],
                "properties": {
                  "challengeId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "code": {
                    "type": "string",
                    "pattern": "^[0-9]{6}$"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verified receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "accepted",
                    "receipt"
                  ],
                  "properties": {
                    "accepted": {
                      "const": true
                    },
                    "receipt": {
                      "$ref": "#/components/schemas/SenderTermsReceipt"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid code/input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid/revoked source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version changed or different signer already accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired, superseded or wrong-session proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Integrator assent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Five code guesses exhausted or rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/legal/terms/current": {
      "get": {
        "summary": "Current service terms manifest",
        "security": [],
        "responses": {
          "200": {
            "description": "Version, languages and exact SHA-256 digests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceTermsDescriptor"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "enum": [
                "integrator",
                "sender"
              ],
              "default": "integrator"
            }
          }
        ]
      }
    },
    "/api/account/terms": {
      "get": {
        "summary": "Own workspace agreement and receipts",
        "description": "Full non-managed session. Only the contracting owner receives history; no foreign workspace selectors. Read-only owner may inspect receipts.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current status and immutable history",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceTermsAudit"
                }
              }
            }
          },
          "403": {
            "description": "Session owner context required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/terms/accept": {
      "post": {
        "summary": "Explicit acceptance by the individual owner or authorized business representative",
        "description": "Authenticated full contracting owner + CSRF accepts the Integrator Agreement and optionally chooses workspace sender responsibility. company requires explicit current Sender Agreement with the same identity; customer never signs for clients. API keys, members and service administrators cannot sign as the owner. Immutable receipts preserve exact identity, version, hash and time; stale policy revision returns409 and requires fresh review.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ServiceTermsInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Immutable receipt and current status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceTermsDescriptor"
                }
              }
            }
          },
          "400": {
            "description": "Invalid identity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Owner required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version changed or identity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Explicit assent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/terms-acceptances": {
      "get": {
        "summary": "Read-only administrator agreement audit",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resolved contracting workspace, required version and history",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "workspaceId": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "history": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ServiceTermsReceipt"
                      }
                    },
                    "sender": {
                      "$ref": "#/components/schemas/SenderTermsStatus"
                    },
                    "senderHistory": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SenderTermsReceipt"
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Administrator required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/onboarding/terms/status": {
      "get": {
        "summary": "Resume sender email confirmation in the same setup session",
        "description": "Restricted onboarding capability only. Revalidates current issuer, role, account, project, agreement version and session expiry. Returns only the latest unexpired unused unsuperseded challenge for this session and account; never the code, full email or signer name. Polling creates no mail or assent. Cache-Control: no-store.",
        "security": [
          {
            "onboardingLink": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current email step",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "accepted",
                    "challenge"
                  ],
                  "properties": {
                    "accepted": {
                      "type": "boolean"
                    },
                    "challenge": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/SenderTermsChallenge"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/mail-health": {
      "get": {
        "summary": "Combined sender-confirmation and account-access mail health",
        "description": "Administrator session only. Combined health for both mandatory sender agreement confirmation and registration/reset email; the legacy /api/admin/mail-status endpoint remains account-access-only. No-store; 60 requests/minute.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregate queue health",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MailHealth"
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/live-sim-tests": {
      "get": {
        "summary": "Read the latest controlled Live SIM test for each SIM",
        "description": "devices:read; tenant/account scoped. Includes historical expired/revoked state. No automatic renewal or sending.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "simNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for an administrator; tenant-bound users/keys cannot select another workspace."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Current trial projections",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LiveSimTestOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Start a 60-minute controlled Live SIM test with explicit acknowledgements",
        "description": "Session only (API/platform/mobile keys cannot create a trial); messages:send and devices:write plus CSRF. Configure limits/routing/webhook and confirm current SIM/RCS first. One active session per SIM; up to four sessions per project in rolling 24 hours and ten create requests/minute. Same id/body is idempotent; a changed identity/body conflicts. Retired carrier-review decisions do not block a test. Actual trial revocation, current SIM identity, opt-outs and configured budgets still apply. Before real recipient proof, use the existing verification API for the fixed connection SMS. After proof, ordinary transactional send/batch/schedule may target only that recipient, at most two segments/message; original TTL is bounded by trial expiry. No cross-phone pool or marketing test traffic.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for an administrator; tenant-bound users/keys cannot select another workspace."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LiveSimTestInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Existing or newly created trial",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "liveTest": {
                      "$ref": "#/components/schemas/LiveSimTest"
                    },
                    "productionApproved": {
                      "type": "boolean",
                      "const": false
                    }
                  },
                  "required": [
                    "liveTest",
                    "productionApproved"
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}/live-sim-tests/{trialId}": {
      "delete": {
        "summary": "Stop a controlled test without deleting message history",
        "description": "Session only, devices:write and CSRF. Idempotent stop of an existing owned trial. Revocation does not promise cancellation of a message already handed to the phone or reset usage.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "trialId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for an administrator; tenant-bound users/keys cannot select another workspace."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "204": {
            "description": "Trial stopped; original history and budgets retained"
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/live-sim-tests": {
      "get": {
        "summary": "Read Live SIM tests belonging to the authenticated phone",
        "description": "Device token only; no account/device overrides and no trial creation. Optional simNumber selects the current phone slot.",
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "simNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Own-device trial state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LiveSimTestOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/test-webhook-inbox": {
      "get": {
        "summary": "Read metadata-only receipts for the current account test webhook",
        "description": "messages:read. Prunes expired receipts. A first-party receiver may be selected through normal integration configuration; this GET never enables one. Retention 7 days, capacity 1000 receipts/account. Existing external integrations are identified without returning their URL/secret.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 30
            }
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Required for an administrator; tenant-bound users/keys cannot select another workspace."
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "responses": {
          "200": {
            "description": "Configuration status and metadata receipts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestWebhookInboxOverview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/test-webhook-inbox/{integrationId}": {
      "post": {
        "summary": "Receive a signed test-project notification durably",
        "description": "Only when this enabled integration points to its own HTTPS first-party inbox. HMAC-SHA256 over timestamp.rawBody, 300-second timestamp tolerance. Maximum 256 KiB JSON; 600 requests/minute per IP and integration. Same event ID/body deduplicates and increments deliveries; changed body conflicts. Returns 204 only after durable metadata storage, 503 at 1000 live receipts (sender must retry), and rejects message.validate. No message sending or carrier approval. The receiver does not retain SMS text, phone numbers, signatures or secrets.",
        "security": [
          {
            "webhookTimestamp": [],
            "webhookSignature": []
          }
        ],
        "parameters": [
          {
            "name": "integrationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TestWebhookInboxEvent"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Signed event durably accepted; not SMS delivery proof"
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/activity": {
      "get": {
        "summary": "Service admin: inspect outgoing and incoming SMS activity",
        "description": "Ordinary service-administrator cookie session only, including read_only administrators. Customer, managed portal and API-key identities are rejected. Reads local stored messages and directory metadata without polling the gateway or mutating SMS state. Omit accountId to include all companies: accountId= is invalid. Unknown or repeated parameters are rejected. Rows sort by occurredAt, id and direction descending with deterministic keyset pagination. The cursor fixes the first-page time anchor and filters, not a historical database snapshot: newly inserted rows and outgoing rows updated after the anchor are excluded; such updates can remove rows and change totals between pages. Refresh without a cursor for current data. For status all/failed/expired/cancelled/unknown/received, period filters the last stored event. status sent uses actual sent_at (including Delivered); status delivered uses delivered_at. Current queued/processing rows ignore period. attention retains active unresolved or overdue work regardless of age, while completed failed/rejected/expired events use period. Future scheduled sends and future known budget/window waits are not stalled. A rolling short retry wake time does not hide an old gateway/offline/manual queue. Processing and unscheduled queue delays use a five-minute threshold; offline/contact facts are not inferred balance or carrier errors. This endpoint returns Cache-Control: no-store. Operational views preserve the existing account boundaries and cursor context. SIM=unassigned matches only NULL/unresolved selection. operations provides work-queue counts, grouped causes and eligible waiting age; row.operations separates SMS state from webhook delivery. Custom dates are validated calendar days in explicit UTC. from/to/timeZone are accepted only with period=custom. Changing the range invalidates activity/feed cursors.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 1024
            },
            "description": "Opaque nextCursor from a preceding page with exactly the same filters and limit; expires after 30 minutes."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 254
            },
            "description": "Literal substring search in stored sender/recipient, text, record/message ID and direct or legacy integration external IDs. SQL wildcard characters remain literal. Redacted content is excluded from content search."
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "description": "Company/account filter. Omit for all companies; an empty value is rejected with 400 invalid_account."
          },
          {
            "name": "deviceId",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Stored phone ID."
          },
          {
            "name": "simNumber",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "2",
                "unassigned"
              ]
            },
            "description": "Stored selected SIM slot, or unassigned for exactly unresolved/unknown routing (NULL). It never means all SIMs."
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "outgoing",
                "incoming"
              ],
              "default": "all"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "queued",
                "processing",
                "sent",
                "delivered",
                "received",
                "attention",
                "failed",
                "expired",
                "cancelled",
                "unknown"
              ],
              "default": "all"
            },
            "description": "sent includes Delivered. failed includes Failed/rejected and expired; expired and cancelled also have exact filters. unknown retains acknowledged rows with resolved=true."
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "1h",
                "24h",
                "7d",
                "30d",
                "all",
                "custom"
              ],
              "default": "all"
            },
            "description": "Historical range. custom requires from, to and timeZone=UTC; both dates are inclusive. Current operational counts remain current regardless of historical bounds."
          },
          {
            "name": "view",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "action",
                "waiting",
                "retryable",
                "incoming",
                "webhooks"
              ],
              "default": "all"
            },
            "description": "Work queue intersected with other filters. all uses the normal feed; action includes actionable SMS or webhook problems; waiting includes queued/processing; retryable uses the exact bulk-resend safety predicate; incoming selects received SMS; webhooks selects pending/failed event delivery. The cursor is bound to this value."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "Inclusive starting calendar date in UTC, not before 1970-01-01 or after today UTC. Required with period=custom."
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "Inclusive ending calendar date in UTC, not earlier than from. Future end dates are capped at the current snapshot. Required with period=custom."
            }
          },
          {
            "name": "timeZone",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "UTC"
              ],
              "description": "Explicit calendar timezone. Currently only UTC is supported. Required with period=custom."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Anchored local activity page; summary counters cover both directions and are independent of direction, status and pagination.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminActivityPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/duplicate/unknown filter, empty accountId, mismatched or expired cursor.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Ordinary service administrator session required, or existing account-security policy prevents access.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; retry according to Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/message-feed": {
      "get": {
        "summary": "Read one company’s unified incoming and outgoing SMS feed; messages:read",
        "description": "Requires messages:read and the same account authorization as existing message history. Admin sessions require an explicit account selector; platform keys select an account in their own project; customer/member/managed sessions and account keys remain scoped. Onboarding, mobile and sandbox tokens cannot access this real feed. Reads local stored data without polling the gateway or sending SMS. Includes normal, control and verification history exposed by the existing outgoing history. One row per SMS, ordered by immutable service registration time (outgoing created_at; incoming stored_at), id and direction descending. occurredAt is this ordering time, not a new status update or the phone clock; receivedAt separately records phone reception time and may be absent for legacy receipts. Period consistently filters registration time for every status and defaults to all. Latest statuses update in place. The cursor binds company, filters, limit, mode and a time anchor and expires after 30 minutes; it is not a historical database snapshot. Messages registered after the anchor are excluded. Existing messages keep their place and expose their latest status, including updates after the first page. A live status or text change can alter membership in an explicit status/search filter and its total; this is not a frozen content snapshot. Refresh without a cursor to include new arrivals. Incoming legacy hydration cannot move row order because stored_at is immutable. No cross-company counters or directory are returned. Redacted content is masked and excluded from content search. Cache-Control: no-store. Operational views preserve the existing account boundaries and cursor context. SIM=unassigned matches only NULL/unresolved selection. The company feed accepts view filters but does not expose global operations counts or groups. Custom dates are validated calendar days in explicit UTC. from/to/timeZone are accepted only with period=custom. Changing the range invalidates activity/feed cursors.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 1024
            },
            "description": "Opaque nextCursor from the same company, filters and limit; expires after 30 minutes. Not interchangeable with admin activity cursors."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 254
            },
            "description": "Literal substring search in stored sender/recipient, text, record/message ID and direct or legacy integration external IDs. SQL wildcard characters remain literal. Redacted content is excluded from content search."
          },
          {
            "name": "deviceId",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Stored phone ID."
          },
          {
            "name": "simNumber",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "2",
                "unassigned"
              ]
            },
            "description": "Stored selected SIM slot, or unassigned for exactly unresolved/unknown routing (NULL). It never means all SIMs."
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "outgoing",
                "incoming"
              ],
              "default": "all"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "queued",
                "processing",
                "sent",
                "delivered",
                "received",
                "attention",
                "failed",
                "expired",
                "cancelled",
                "unknown"
              ],
              "default": "all"
            },
            "description": "sent includes Delivered. failed includes Failed/rejected and expired; expired and cancelled also have exact filters. unknown retains acknowledged rows with resolved=true."
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "1h",
                "24h",
                "7d",
                "30d",
                "all",
                "custom"
              ],
              "default": "all"
            },
            "description": "Historical range. custom requires from, to and timeZone=UTC; both dates are inclusive. Current operational counts remain current regardless of historical bounds."
          },
          {
            "name": "view",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "action",
                "waiting",
                "retryable",
                "incoming",
                "webhooks"
              ],
              "default": "all"
            },
            "description": "Work queue intersected with other filters. all uses the normal feed; action includes actionable SMS or webhook problems; waiting includes queued/processing; retryable uses the exact bulk-resend safety predicate; incoming selects received SMS; webhooks selects pending/failed event delivery. The cursor is bound to this value."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "Inclusive starting calendar date in UTC, not before 1970-01-01 or after today UTC. Required with period=custom."
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "Inclusive ending calendar date in UTC, not earlier than from. Future end dates are capped at the current snapshot. Required with period=custom."
            }
          },
          {
            "name": "timeZone",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "UTC"
              ],
              "description": "Explicit calendar timezone. Currently only UTC is supported. Required with period=custom."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Company-scoped unified message page and its phone directory; no global counts or accounts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageFeedPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/duplicate/unknown filter, empty accountId, mismatched or expired cursor.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid session/API credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Wrong company, insufficient messages:read scope, disallowed credential type or existing account/security restriction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Selected company is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; retry according to Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/sending-limits": {
      "get": {
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "X-SendHarbor-Limits-Version",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "2"
              ]
            },
            "description": "Send 2 when the mobile client supports zero hourly, daily and monthly limits. Required when the actual response contains a disabled limit; absence returns 426 app_update_required instead of an incompatible 200. Does not change the actual scheduling policy."
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh own-device limits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MobileSendingLimits"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "426": {
            "description": "app_update_required: this request did not negotiate disabled-limit support, or the phone must be upgraded before saving disabled limits. No mutation or SMS resend occurs. Update SendHarbor to 1.17.3 or later without clearing app data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "summary": "Read this phone’s per-SIM sending limits",
        "description": "Active mobile token only, rechecked after identity lookup. No query parameters. No-store. 30 requests/minute per device, 120/minute per IP shared with updates."
      },
      "put": {
        "security": [
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "X-SendHarbor-Limits-Version",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "2"
              ]
            },
            "description": "Send 2 when the mobile client supports zero hourly, daily and monthly limits. Required when the actual response contains a disabled limit; absence returns 426 app_update_required instead of an incompatible 200. Does not change the actual scheduling policy."
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh own-device limits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MobileSendingLimits"
                }
              }
            }
          },
          "409": {
            "description": "policy_changed: reload limits before asking the user to save again",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authorization, conflict, rate or transport error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "426": {
            "description": "app_update_required: this request did not negotiate disabled-limit support, or the phone must be upgraded before saving disabled limits. No mutation or SMS resend occurs. Update SendHarbor to 1.17.3 or later without clearing app data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "summary": "Update one SIM’s numerical limits on this phone",
        "description": "Atomic compare-and-swap using revision; rejects stale web/mobile edits with 409 policy_changed. Re-evaluates undispatched Queued work only. Never resets reservations, resolves unknown outcomes, retries an SMS, changes SIM routing or disables other holds. A v2 mobile capability permits saving zero caps before the first upgraded diagnostics report, only for this authenticated phone.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MobileSendingLimitsInput"
              }
            }
          }
        }
      }
    },
    "/api/overview/timeline": {
      "get": {
        "summary": "Sends and failures over time for the overview chart",
        "description": "Ordinary session only. Managed sessions and API keys are rejected. Uses the same visible non-archived accounts as GET /api/overview. Sends count by actual send time; failures count by their last update, because they have no send time. Returns sparse counts per minute for up to two hours, otherwise per hour. All-time and long ranges return only their most recent 30 days and set truncated:true.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "1h",
                "24h",
                "7d",
                "30d",
                "custom"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "YYYY-MM-DD; only with period=custom."
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "YYYY-MM-DD; only with period=custom."
          },
          {
            "name": "timeZone",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "UTC"
              ]
            },
            "description": "Only with period=custom."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "period": {
                      "type": "string"
                    },
                    "generatedAt": {
                      "type": "string"
                    },
                    "from": {
                      "type": "integer"
                    },
                    "to": {
                      "type": "integer"
                    },
                    "unit": {
                      "type": "string",
                      "enum": [
                        "minute",
                        "hour"
                      ]
                    },
                    "truncated": {
                      "type": "boolean"
                    },
                    "buckets": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "at": {
                            "type": "integer"
                          },
                          "sent": {
                            "type": "integer"
                          },
                          "delivered": {
                            "type": "integer"
                          },
                          "failed": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid period or query"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Managed sessions cannot read the overview"
          },
          "429": {
            "description": "Too many requests"
          }
        }
      }
    },
    "/api/overview/deliveries": {
      "get": {
        "summary": "Inspect pending or failed webhook deliveries across visible accounts",
        "description": "Ordinary session only, including read-only members. Managed sessions and API keys are rejected. Uses the same visible non-archived account set as GET /api/overview, independent of the selected console company. status=pending includes pending and delivering. Paging uses descending createdAt then ID; after must be visible to this user with this status. No payload, endpoint, signing secret or SMS content is returned. Reading never claims work, retries a webhook, creates an SMS or changes delivery state. nextAttemptAt is a retry check, not a delivery promise; paused reflects integration enablement and the project webhook events channel. Cache-Control: no-store.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "failed"
              ],
              "default": "failed"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Previous nextAfter. Clear when changing status; refresh on an invalid position."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Read-only delivery snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "generatedAt",
                    "status",
                    "total",
                    "hasMore",
                    "nextAfter",
                    "rows"
                  ],
                  "properties": {
                    "generatedAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "pending",
                        "failed"
                      ]
                    },
                    "total": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "hasMore": {
                      "type": "boolean"
                    },
                    "nextAfter": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "rows": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "accountId",
                          "accountName",
                          "type",
                          "status",
                          "attempts",
                          "createdAt",
                          "lastError",
                          "nextAttemptAt",
                          "paused"
                        ],
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "accountId": {
                            "type": "string"
                          },
                          "accountName": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "pending",
                              "delivering",
                              "failed"
                            ]
                          },
                          "attempts": {
                            "type": "integer",
                            "minimum": 0
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "lastError": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "nextAttemptAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time"
                          },
                          "paused": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid/repeated query or a cursor not visible in this status."
          },
          "401": {
            "description": "Sign-in required."
          },
          "403": {
            "description": "Ordinary session required or forbidden account selector."
          },
          "429": {
            "description": "60 reads per minute per user."
          }
        }
      }
    },
    "/api/incoming-messages/{id}/handling": {
      "put": {
        "summary": "Mark an incoming SMS handled or unhandled; messages:send",
        "description": "Account-isolated local workflow state. Requires messages:send; read-only sessions cannot write. Cookie sessions require CSRF. Only the history record ID is accepted. Repeating the same handled value preserves the existing timestamp/actor; false clears both markers. Does not send a reply, retry a webhook, change consent/STOP state or alter message content. 120 requests/minute per selected account.",
        "security": [
          {
            "session": [],
            "csrf": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "IncomingMessage.id, not the mobile event messageId."
          },
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "handled"
                ],
                "properties": {
                  "handled": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated handling marker; no SMS is sent",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "incomingMessage"
                  ],
                  "properties": {
                    "incomingMessage": {
                      "$ref": "#/components/schemas/IncomingMessage"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Validation, authentication, authorization, not-found, conflict or rate-limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/conversation": {
      "get": {
        "summary": "Read the exact thread of an authorized SMS; messages:read",
        "description": "Derives company, phone, selected SIM and peer from messageId plus direction in the selected account. Callers cannot supply a phone number, device or SIM to widen the thread. Cross-account sources return 404. Includes both directions only on that exact route; unresolved automatic routes, missing SIM/peer and redacted sources return limited rather than guessing. Stored messages sort by time,id,direction descending. Cursor is bound to source identity, account, route and limit with a 30-minute anchor. Cache-Control: no-store; 120 requests/minute per account. Reading does not send SMS or call the phone.",
        "security": [
          {
            "session": []
          },
          {
            "apiKey": []
          },
          {
            "platformKey": []
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "X-SendHarbor-Account",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Explicit client account selector; one selector required with platform key. Conflicting selectors rejected."
          },
          {
            "name": "messageId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "description": "Source history ID: outgoing message.id or incoming IncomingMessage.id; not the incoming event messageId."
          },
          {
            "name": "direction",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "outgoing",
                "incoming"
              ]
            },
            "description": "Direction of the source record."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 1200
            },
            "description": "Opaque nextCursor from this exact source, account and limit. Expires after 30 minutes."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConversationPage"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authentication, authorization, not-found, conflict or rate-limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/operations": {
      "get": {
        "summary": "Service admin: inspect confirmed resend operations",
        "description": "Ordinary service-administrator cookie session, including read-only admins. Lists started operations across all actors/companies; preview-only checks are excluded. Sorted by createdAt,id descending. No account selector. Read-only and does not resume operations. Cache-Control: no-store; 120 requests/minute per admin shared with details.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 1200
            },
            "description": "Opaque nextCursor from the previous operation page."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminOperationPage"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authentication, authorization, not-found, conflict or rate-limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/operations/{id}": {
      "get": {
        "summary": "Service admin: inspect one resend operation and its item results",
        "description": "Any ordinary service admin may inspect a started operation, including other actors’ results, but only its original actor can resume it. Queries cannot broaden to another source/account; items are confined to this operation. No SMS or webhook is sent. Use nextAfter for positional pagination. Cache-Control: no-store; 120 requests/minute per admin shared with history.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Confirmed operation ID."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": -1,
              "maximum": 1000,
              "default": -1
            },
            "description": "Exclusive item position; use nextAfter."
          },
          {
            "name": "outcome",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "queued",
                "skipped",
                "failed",
                "pending"
              ],
              "default": "all"
            },
            "description": "failed selects admission_failed skips; skipped excludes those failures; pending has no durable outcome yet."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminOperationDetail"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authentication, authorization, not-found, conflict or rate-limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/activity/resend/preview": {
      "post": {
        "summary": "Service admin: freeze and review a bulk SMS retry selection",
        "description": "Writable ordinary service-administrator cookie session only; customer, managed and API-key identities cannot use this operation. Session CSRF is required. Preview ownership is bound to the actor, independently of currently selected company. Does not enqueue or send SMS. Select at most 1,000 keys or matching rows across companies. More returns 400 resend_selection_too_large; narrow filters. The preview is valid for ten minutes before starting. Only definitive, gateway-confirmed single-part failures before any sent evidence are eligible. Queued/processing, sent/delivered, unknown, multipart-uncertain, expired/cancelled, redacted, superseded/version-controlled, opted-out and unavailable routes are skipped. 30 previews/minute per admin; Cache-Control: no-store.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "selection"
                ],
                "properties": {
                  "selection": {
                    "$ref": "#/components/schemas/BulkResendSelection"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Frozen selection and reasons; nothing is sent",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BulkResendPreview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authentication, authorization, not-found, conflict or rate-limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/activity/resend": {
      "post": {
        "summary": "Service admin: confirm or resume the same bulk retry intent",
        "description": "Writable ordinary service-administrator cookie session only; customer, managed and API-key identities cannot use this operation. Session CSRF is required. Preview ownership is bound to the actor, independently of currently selected company. Pass the actor-owned previewId from review, including when retrying after a lost response. The same preview and source-message claim prevent creating another retry across double clicks, concurrent previews, other admins and restart. Only the original actor can resume; another actor receives 404. Source fingerprint, current eligibility, STOP, company/phone policies and admission are rechecked per item. Creates a separate SMS with the same text, recipient, phone and SIM, retryOf source ID, and a fresh 24-hour queue lifetime. Queueing is not sending or delivery. Original history remains unchanged. Partial durable results survive interruption. An expired unstarted preview returns 409 resend_preview_expired; a started intent remains resumable. 30 calls/minute per admin; Cache-Control: no-store.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "previewId"
                ],
                "properties": {
                  "previewId": {
                    "type": "string",
                    "maxLength": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Durable item results; queued items await normal dispatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BulkResendPreview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authentication, authorization, not-found, conflict or rate-limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/activity/resend/{id}": {
      "get": {
        "summary": "Service admin: read your actor-owned preview or retry result",
        "description": "Ordinary service-administrator cookie session. Only the preview’s creating actor can read this endpoint; another actor receives 404 resend_preview_not_found. It never starts or resumes sending. For cross-admin inspection of already confirmed jobs, use /api/admin/operations/{id}. Cache-Control: no-store.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Actor-owned preview ID."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BulkResendPreview"
                }
              }
            }
          },
          "default": {
            "description": "Validation, authentication, authorization, not-found, conflict or rate-limit error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/sender-policy": {
      "get": {
        "summary": "Read owner signing choice and immutable history",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace policy, current sender terms and owner evidence",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SenderPolicy"
                }
              }
            }
          },
          "403": {
            "description": "Full contracting owner required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Choose who accepts sender obligations",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "description": "Full contracting owner only. company requires current explicit SenderTermsInput with the existing contracting identity; customer requires no senderTerms. CAS expectedRevision prevents stale overwrites. Switching never forges or deletes customer receipts. In customer mode each unsigned account alone waits; company mode requires the current workspace owner receipt. History survives changes. This endpoint cannot be called with a phone, setup or API-key capability.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "mode": {
                    "enum": [
                      "company",
                      "customer"
                    ]
                  },
                  "expectedRevision": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "terms": {
                    "$ref": "#/components/schemas/SenderTermsInput"
                  }
                },
                "required": [
                  "mode",
                  "expectedRevision"
                ],
                "allOf": [
                  {
                    "if": {
                      "properties": {
                        "mode": {
                          "const": "company"
                        }
                      },
                      "required": [
                        "mode"
                      ]
                    },
                    "then": {
                      "required": [
                        "terms"
                      ]
                    },
                    "else": {
                      "not": {
                        "required": [
                          "terms"
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Policy and receipts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SenderPolicy"
                }
              }
            }
          },
          "400": {
            "description": "Invalid choice or identity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Owner required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "sender_policy_changed or terms_version_changed; reload and re-confirm",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Current integration terms required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/terms": {
      "get": {
        "summary": "Current account agreement and available signer paths",
        "description": "Code QR + original X-Enrollment-Recovery before enrollment, or Bearer phone token after enrollment. No website login, query/account/project/device selector or X-SendHarbor-Account is accepted. Source, account, project, expiry and revocation are rechecked; no general owner session is created. Responses are no-store.",
        "security": [
          {
            "pairingCode": []
          },
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Required with Code authorization: retain the original enrollment attempt proof. Not needed with an enrolled phone token."
          }
        ],
        "responses": {
          "200": {
            "description": "Minimized status; ownerAcceptance contains no full owner email/identity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SenderTermsStatus"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or selector",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Revoked or wrong capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Paused/unavailable or wrong signer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Policy, identity or document changed; refresh",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired/revoked QR or email proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner acceptance or explicit consent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Attempt/rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Verification email unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/terms/status": {
      "get": {
        "summary": "Native customer agreement status",
        "description": "Code QR + original X-Enrollment-Recovery before enrollment, or Bearer phone token after enrollment. No website login, query/account/project/device selector or X-SendHarbor-Account is accepted. Source, account, project, expiry and revocation are rechecked; no general owner session is created. Responses are no-store. Customer mode only. The code confirms the exact declared consent, account/project and policy revision. A successful retry preserves one immutable receipt.",
        "security": [
          {
            "pairingCode": []
          },
          {
            "mobileToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Account-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or selector",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Revoked or wrong capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Paused/unavailable or wrong signer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Policy, identity or document changed; refresh",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired/revoked QR or email proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner acceptance or explicit consent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Attempt/rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Verification email unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Required with Code authorization: retain the original enrollment attempt proof. Not needed with an enrolled phone token."
          }
        ]
      }
    },
    "/api/mobile/v1/terms/request": {
      "post": {
        "summary": "Native customer agreement request",
        "security": [
          {
            "pairingCode": []
          },
          {
            "mobileToken": []
          }
        ],
        "description": "Code QR + original X-Enrollment-Recovery before enrollment, or Bearer phone token after enrollment. No website login, query/account/project/device selector or X-SendHarbor-Account is accepted. Source, account, project, expiry and revocation are rechecked; no general owner session is created. Responses are no-store. Customer mode only. The code confirms the exact declared consent, account/project and policy revision. A successful retry preserves one immutable receipt.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "idempotencyKey",
                  "email",
                  "terms"
                ],
                "properties": {
                  "idempotencyKey": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "terms": {
                    "$ref": "#/components/schemas/SenderTermsInput"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Account-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SenderTermsChallenge"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or selector",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Revoked or wrong capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Paused/unavailable or wrong signer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Policy, identity or document changed; refresh",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired/revoked QR or email proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner acceptance or explicit consent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Attempt/rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Verification email unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Required with Code authorization: retain the original enrollment attempt proof. Not needed with an enrolled phone token."
          }
        ]
      }
    },
    "/api/mobile/v1/terms/confirm": {
      "post": {
        "summary": "Native customer agreement confirm",
        "security": [
          {
            "pairingCode": []
          },
          {
            "mobileToken": []
          }
        ],
        "description": "Code QR + original X-Enrollment-Recovery before enrollment, or Bearer phone token after enrollment. No website login, query/account/project/device selector or X-SendHarbor-Account is accepted. Source, account, project, expiry and revocation are rechecked; no general owner session is created. Responses are no-store. Customer mode only. The code confirms the exact declared consent, account/project and policy revision. A successful retry preserves one immutable receipt.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "challengeId",
                  "code"
                ],
                "properties": {
                  "challengeId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "code": {
                    "type": "string",
                    "pattern": "^[0-9]{6}$"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Account-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or selector",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Revoked or wrong capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Paused/unavailable or wrong signer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Policy, identity or document changed; refresh",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired/revoked QR or email proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner acceptance or explicit consent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Attempt/rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Verification email unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Required with Code authorization: retain the original enrollment attempt proof. Not needed with an enrolled phone token."
          }
        ]
      }
    },
    "/api/mobile/v1/terms/owner/status": {
      "get": {
        "summary": "Native existing-owner verification: status",
        "description": "Code QR + original X-Enrollment-Recovery before enrollment, or Bearer phone token after enrollment. No website login, query/account/project/device selector or X-SendHarbor-Account is accepted. Source, account, project, expiry and revocation are rechecked; no general owner session is created. Responses are no-store. OTP is sent only to the existing contracting owner address, never a user-supplied email. Verification returns a purpose-specific signingToken, existing identity and exact manifest bundle; it does not itself accept. The token expires at the original ten-minute email challenge deadline: verification and retries do not extend that deadline. Final accept requires each presented unaccepted document, identical identity and the owner’s configured MFA factor. Phone cannot change responsibility mode. Policy/owner/email/password/factor/source/version changes invalidate proof. Original receipts and verified evidence are immutable; retries cannot duplicate them.",
        "security": [
          {
            "pairingCode": []
          },
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Required with Code authorization: retain the original enrollment attempt proof. Not needed with an enrolled phone token."
          }
        ],
        "responses": {
          "200": {
            "description": "Restricted owner-confirmation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OwnerTermsStatus"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or selector",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Revoked or wrong capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Paused/unavailable or wrong signer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Policy, identity or document changed; refresh",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired/revoked QR or email proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner acceptance or explicit consent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Attempt/rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Verification email unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/terms/owner/request": {
      "post": {
        "summary": "Native existing-owner verification: request",
        "description": "Code QR + original X-Enrollment-Recovery before enrollment, or Bearer phone token after enrollment. No website login, query/account/project/device selector or X-SendHarbor-Account is accepted. Source, account, project, expiry and revocation are rechecked; no general owner session is created. Responses are no-store. OTP is sent only to the existing contracting owner address, never a user-supplied email. Verification returns a purpose-specific signingToken, existing identity and exact manifest bundle; it does not itself accept. The token expires at the original ten-minute email challenge deadline: verification and retries do not extend that deadline. Final accept requires each presented unaccepted document, identical identity and the owner’s configured MFA factor. Phone cannot change responsibility mode. Policy/owner/email/password/factor/source/version changes invalidate proof. Original receipts and verified evidence are immutable; retries cannot duplicate them.",
        "security": [
          {
            "pairingCode": []
          },
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Required with Code authorization: retain the original enrollment attempt proof. Not needed with an enrolled phone token."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "idempotencyKey": {
                    "type": "string",
                    "pattern": "^[-A-Za-z0-9._:]{1,128}$"
                  },
                  "language": {
                    "enum": [
                      "en",
                      "ru"
                    ]
                  }
                },
                "required": [
                  "idempotencyKey",
                  "language"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Restricted owner-confirmation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OwnerTermsChallenge"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or selector",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Revoked or wrong capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Paused/unavailable or wrong signer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Policy, identity or document changed; refresh",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired/revoked QR or email proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner acceptance or explicit consent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Attempt/rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Verification email unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/terms/owner/verify": {
      "post": {
        "summary": "Native existing-owner verification: verify",
        "description": "Code QR + original X-Enrollment-Recovery before enrollment, or Bearer phone token after enrollment. No website login, query/account/project/device selector or X-SendHarbor-Account is accepted. Source, account, project, expiry and revocation are rechecked; no general owner session is created. Responses are no-store. OTP is sent only to the existing contracting owner address, never a user-supplied email. Verification returns a purpose-specific signingToken, existing identity and exact manifest bundle; it does not itself accept. The token expires at the original ten-minute email challenge deadline: verification and retries do not extend that deadline. Final accept requires each presented unaccepted document, identical identity and the owner’s configured MFA factor. Phone cannot change responsibility mode. Policy/owner/email/password/factor/source/version changes invalidate proof. Original receipts and verified evidence are immutable; retries cannot duplicate them.",
        "security": [
          {
            "pairingCode": []
          },
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Required with Code authorization: retain the original enrollment attempt proof. Not needed with an enrolled phone token."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "challengeId": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string",
                    "pattern": "^[0-9]{6}$"
                  }
                },
                "required": [
                  "challengeId",
                  "code"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Restricted owner-confirmation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OwnerTermsGrant"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or selector",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Revoked or wrong capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Paused/unavailable or wrong signer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Policy, identity or document changed; refresh",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired/revoked QR or email proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner acceptance or explicit consent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Attempt/rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Verification email unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/mobile/v1/terms/owner/accept": {
      "post": {
        "summary": "Native existing-owner verification: accept",
        "description": "Code QR + original X-Enrollment-Recovery before enrollment, or Bearer phone token after enrollment. No website login, query/account/project/device selector or X-SendHarbor-Account is accepted. Source, account, project, expiry and revocation are rechecked; no general owner session is created. Responses are no-store. OTP is sent only to the existing contracting owner address, never a user-supplied email. Verification returns a purpose-specific signingToken, existing identity and exact manifest bundle; it does not itself accept. The token expires at the original ten-minute email challenge deadline: verification and retries do not extend that deadline. Final accept requires each presented unaccepted document, identical identity and the owner’s configured MFA factor. Phone cannot change responsibility mode. Policy/owner/email/password/factor/source/version changes invalidate proof. Original receipts and verified evidence are immutable; retries cannot duplicate them.",
        "security": [
          {
            "pairingCode": []
          },
          {
            "mobileToken": []
          }
        ],
        "parameters": [
          {
            "name": "X-Enrollment-Recovery",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "Required with Code authorization: retain the original enrollment attempt proof. Not needed with an enrolled phone token."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "signingToken": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{43}$"
                  },
                  "terms": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "integrator": {
                        "$ref": "#/components/schemas/OwnerIntegratorConsent"
                      },
                      "sender": {
                        "$ref": "#/components/schemas/SenderTermsInput"
                      }
                    }
                  },
                  "mfaCode": {
                    "type": "string"
                  }
                },
                "required": [
                  "signingToken",
                  "terms"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Restricted owner-confirmation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OwnerTermsAcceptance"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or selector",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Revoked or wrong capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Paused/unavailable or wrong signer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Policy, identity or document changed; refresh",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Expired/revoked QR or email proof",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Owner acceptance or explicit consent required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Attempt/rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Verification email unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/config": {
      "get": {
        "summary": "Phone quick start settings",
        "description": "Public. docs/quick-start.md.",
        "security": [],
        "responses": {
          "200": {
            "description": "Settings",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartConfig"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/email": {
      "post": {
        "summary": "Send a six-digit email code",
        "description": "Public. The same answer and email for new and existing addresses; no account lookup. The code lives 10 minutes, allows 5 tries and is stored only as a keyed hash; a new code replaces earlier ones. Limits: 10 requests per IP per 15 minutes, 5 per address per hour, one per address per 60 seconds (429 resend_too_soon with Retry-After). 403 registration_disabled when self-registration is closed.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuickStartEmailRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Code sent",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartChallenge"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Registration closed or another origin",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited or resend too soon",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Email is not configured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/verify": {
      "post": {
        "summary": "Check the code and create an account or sign in",
        "description": "Public. A new address gets a workspace, its default project and its owner as email registration does, and gets a session (201, created true). The owner accepts, as party individual (personal) or business with name as the signatory, the integration terms and the Sender Agreement in company mode for the workspace's own accounts (the first sender policy revision, an immutable company receipt with source quick_start). A phone of this account then enrolls without a second email code. On a server that does not require the terms nothing is recorded. An existing customer without two-step verification signs in (200, created false) and nothing is recorded; the sign-up fields are ignored. Two-step, staff and disabled accounts get 409 password_login_required and must use POST /api/login. Errors: 400 invalid_code (each try counts), 410 code_expired, 429 code_locked after 5 tries, 400 invalid_purpose/invalid_name/invalid_company_name, 428 terms_acceptance_required, 409 terms_version_changed (either document). 30 requests per IP per 15 minutes.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuickStartVerifyRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartSession"
                }
              }
            }
          },
          "201": {
            "description": "Account created and signed in",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartSession"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or wrong code",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Registration closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Password sign-in required or terms changed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Code expired, replaced or used",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Terms not accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many tries",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Gateway setup failed; retry with the same code",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/pairing": {
      "post": {
        "summary": "Pair this phone without a QR",
        "description": "Session of the account owner. Issues an ordinary 20-minute pairing through the existing pairing flow and cancels this account's earlier unused quick start pairings. The phone enrolls with POST /api/mobile/v1/device as after a QR scan.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional account selector; the signed-in person must own the account."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuickStartPairingRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Pairing issued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartPairing"
                }
              }
            }
          },
          "400": {
            "description": "Package not allowed or invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Sign in",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Owner required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Pairing capacity or HTTPS required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Integration terms not accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/pairing/{id}": {
      "get": {
        "summary": "Quick start pairing state",
        "description": "Session of the account owner. 240 reads per minute.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "pairingId from POST /api/quick-start/pairing"
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional account selector; the signed-in person must own the account."
          }
        ],
        "responses": {
          "200": {
            "description": "State",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartPairingState"
                }
              }
            }
          },
          "401": {
            "description": "Sign in",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Owner required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not a quick start pairing of this account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/integration": {
      "post": {
        "summary": "Create a key and the snippet values for one integration",
        "description": "Session of the account owner. Creates an ordinary live API key \"Quick start · <integration>\" with messages:send and messages:read; the secret is returned only here. A new key revokes the earlier quick start keys of the same integration in this account that were never used; a used key stays. 20 per account per hour.",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional account selector; the signed-in person must own the account."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuickStartIntegrationRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Key and snippet values",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartIntegration"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or test number required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Sign in",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Owner required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Phone not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Integration terms not accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/check/{checkId}": {
      "get": {
        "summary": "Check the first SMS of the snippet",
        "description": "Session of the account owner. Indexed reads only, no gateway call; the server counts first_request, first_sms_sent and delivered once per check. 120 reads per minute.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "checkId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "checkId from POST /api/quick-start/integration"
          },
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional account selector; the signed-in person must own the account."
          }
        ],
        "responses": {
          "200": {
            "description": "Progress",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartCheck"
                }
              }
            }
          },
          "401": {
            "description": "Sign in",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Owner required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Check not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/events": {
      "post": {
        "summary": "Count a quick start funnel step",
        "description": "Public and anonymous. Only daily counters per (date, step, src, language) and distinct sids per day are kept; no address, account or IP. 120 per minute per network address.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuickStartEvent"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Counted"
          },
          "400": {
            "description": "Unknown step or invalid field",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Another origin",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/quick-start/funnel": {
      "get": {
        "summary": "Quick start funnel by day",
        "description": "Administrator session only. Every date of the period, oldest first, with every step.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 366,
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Daily counters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartFunnel"
                }
              }
            }
          },
          "400": {
            "description": "Invalid days",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Sign in",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Administrator required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/quick-start/state": {
      "get": {
        "summary": "Resume the quick start from the server session",
        "description": "Session optional. Without a valid session cookie: 200 {signedIn:false}. With the session of the account owner: account, purpose, latest quick start pairing, linked phones and the latest check, so /start can resume after a fresh page load. Other sessions and API keys get 403 owner_required. 120 reads per minute per user.",
        "security": [
          {},
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional account selector; the signed-in person must own the account."
          }
        ],
        "responses": {
          "200": {
            "description": "State",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuickStartState"
                }
              }
            }
          },
          "403": {
            "description": "Owner required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "magendaEvent": {
      "post": {
        "summary": "SMS Gateway → Magenda: событие в настроенный endpoint",
        "security": [
          {
            "webhookTimestamp": [],
            "webhookSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MagendaEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Событие надёжно сохранено или уже обработано с тем же ID и телом"
          },
          "default": {
            "description": "Любой non-2xx или ошибка транспорта приводит к повтору, максимум 12 попыток. 2xx любого кода подтверждает доставку."
          }
        }
      }
    },
    "sandboxEvent": {
      "post": {
        "summary": "Optional signed callback for simulated SMS outcomes",
        "description": "Explicit emitWebhook opt-in. Separate test outbox, sandbox:true markers, X-SendHarbor-Sandbox:1. Verify raw-body HMAC and deduplicate event.id. Never interpret this as a real modem/carrier outcome.",
        "parameters": [
          {
            "in": "header",
            "name": "X-SendHarbor-Sandbox",
            "required": true,
            "schema": {
              "const": "1"
            }
          }
        ],
        "security": [
          {
            "webhookTimestamp": [],
            "webhookSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SandboxEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Durably accepted or deduplicated"
          },
          "default": {
            "description": "Non-2xx/transient failure retries the same event ID/payload in the separate outbox; maximum11 automatic attempts, then explicit retry."
          }
        }
      }
    }
  }
}
