{
  "openapi": "3.1.0",
  "info": {
    "title": "SMSNET API",
    "version": "2026-10",
    "summary": "Programmable two-way SMS from real Android phones and SIMs.",
    "description": "SMSNET turns Android phones with ordinary SIM cards into programmable SMS lines.\nYou send through the REST API (or MCP), the paired phone sends the SMS, and replies\ncome back as webhooks or through the message stream.\n\n**Base URL.** Use the apex `https://smsnet.net`. `api.smsnet.net` serves the same\nWorker, but some ISP resolvers fail on it; the apex resolves everywhere.\n\n**Authentication.** Every `/api/v1` call takes the account API key in the\n`X-API-Key` header. `Authorization: Bearer <key>` is accepted as an alternative\n(and is what the MCP endpoint documents). Keys look like `smsnet_...` (legacy, full\nscope) or `sn_live_...` / `sn_test_...` (scoped: `send`, `read`, `manage`; manage\nimplies all). A missing scope returns `403 {\"error\":\"insufficient_scope\",\"required\":\"send\"}`.\nScope map: GET/HEAD need `read`; POST /messages/send, /conversations/{id}/reply,\n/campaigns, /otp/send, /otp/verify and /ai/suggest-reply need `send`; every other\nmutation needs `manage`. Agent keys (`agent: true`) are MCP-only and get\n`403 {\"error\":\"agent_key_mcp_only\"}` on REST.\nAccount deletion, minting keys, MCP client and recipient approval, and switching off\nthe MCP trust gate need a signed-in owner in the portal (an API key gets 403). A team admin\ncounts as an owner there, except for deleting the account, replacing the account key and\nsetting the owner's phone number, which only the owner can do.\n\n**Errors.** Every 4xx/5xx JSON answer under `/api` uses one envelope (schema `Error`):\n`{\"error\": \"<code or legacy text>\", \"code\": \"<snake_code>\", \"message\": \"<human sentence>\",\n\"docs_url\": \"https://smsnet.net/docs/errors#<snake_code>\"}`. Branch on `code`, show\n`message` to a person, link `docs_url`. `error` keeps the value it had before the envelope\n(a snake code on newer refusals, a human sentence on older ones) for backward compatibility.\nSome errors carry extra fields (`required` on `insufficient_scope`, `retry_after_s`).\nThe full catalogue, with what each code means and how to fix it, is at\nhttps://smsnet.net/docs/errors. Common codes: `send_at_too_far`, `sim_not_found`,\n`idempotency_mismatch`, `idempotency_in_flight`, `insufficient_scope`, `otp_rate_limited`,\n`agent_key_mcp_only`, `too_many_keys`, `cannot_revoke_self`, `invalid_to`, `invalid_phone`,\n`session_required`, `invalid_url`, `invalid_events`, `endpoint_limit`, `quota_exceeded`,\n`abuse_ceiling`, `opted_out`, `no_device`, `rate_limited`, `not_found`, `bad_request`.\nIdempotency: a stored 4xx is replayed like a 2xx; 5xx are not stored.\nThe health check `GET https://smsnet.net/api/health` answers 503 whenever `ok` is false.\n\n**Delivery failure codes.** A message that fails on the phone carries a code in the\n`message.status` webhook (`error_code`) and as the prefix of `error_message` (schema\n`MessageErrorCode`). `THROTTLED` means the carrier refused to send more right now (rate or\npremium-SMS limit). The line rests for 60 minutes (`line.health_changed`, reason\n`carrier_throttle`) and, unless the message was sent with `route_mode: \"strict\"`, the\nmessage moves once to another line with no `failed` webhook. Only when it cannot move does\nit end `failed` with `error_code: \"THROTTLED\"`.\n\n**Idempotency.** `POST /messages/send`, `POST /conversations/{id}/reply`,\n`POST /campaigns`, `POST /otp/send` and `POST /verify/reverse/start` accept an `Idempotency-Key` header (1–255\nchars, scoped per account, kept 24h with a SHA-256 of the body). The same key with\nthe same body replays the stored status and body with `Idempotent-Replayed: true`;\na different body returns 422 `idempotency_mismatch`; a request still in flight\nreturns 409 `idempotency_in_flight`.\n\n**Sandbox.** Messages sent with an `sn_test_` key are never released to a phone. They\nmove pending → sent → delivered in about two seconds (`sandbox: true` on the message),\nfire the same webhooks, and do not count against quota.\n\n**Webhooks.** See the `webhooks` section of this document. Every delivery carries\nStandard Webhooks headers (`webhook-id`, `webhook-timestamp`, `webhook-signature`)\nand the legacy `X-SMSNET-Signature`. An account can have up to 10 endpoints\n(`/webhooks/endpoints`), each with its own events filter, secret, retries and log.\nEndpoint secrets look like `whsec_<base64>`, and the Standard Webhooks HMAC key is the\nbase64-decoded bytes after `whsec_`. The original single endpoint (`/webhooks`,\n`source: \"legacy\"`) keeps its 64-hex secret, used as raw UTF-8 bytes. After a rotation\nthe old secret keeps signing for 24h as a second, space-separated signature. Retries: 5s, 5m, 30m, 2h, 5h, 10h, 14h, 20h, 24h (about 3 days), then\n`failed` and replayable. A `410 Gone` from your endpoint stops retries.\n\n**Etiquette.** Lines are real SIMs on consumer plans. New lines warm up over ~21\ndays, recipients' quiet hours are respected, opt-out keywords (STOP, הסר, ...) are\nhonoured automatically. See https://smsnet.net/skill.md.\n",
    "contact": {
      "name": "SMSNET",
      "url": "https://smsnet.net"
    },
    "termsOfService": "https://smsnet.net/terms",
    "license": {
      "name": "Proprietary",
      "identifier": "LicenseRef-Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://smsnet.net/api/v1",
      "description": "Production (apex, preferred)"
    }
  ],
  "security": [
    {
      "ApiKeyHeader": []
    },
    {
      "BearerKey": []
    }
  ],
  "tags": [
    {
      "name": "Messages",
      "description": "Send, schedule, and stream messages."
    },
    {
      "name": "Conversations",
      "description": "Threads with one contact; reply in place."
    },
    {
      "name": "Contacts",
      "description": "Address book, tags and opt-out."
    },
    {
      "name": "Templates",
      "description": "Reusable message bodies."
    },
    {
      "name": "Campaigns",
      "description": "Paced sends to a list or tag."
    },
    {
      "name": "Lines",
      "description": "SIMs (\"lines\"), their health, warmup and per-line safety controls."
    },
    {
      "name": "Devices",
      "description": "Paired Android phones."
    },
    {
      "name": "OTP",
      "description": "One-time codes, sent and verified."
    },
    {
      "name": "Usage",
      "description": "Counts against the plan."
    },
    {
      "name": "Webhooks",
      "description": "Endpoint config, delivery log and replay."
    },
    {
      "name": "Keys",
      "description": "Scoped API keys."
    },
    {
      "name": "Settings",
      "description": "Account settings and the hybrid fallback."
    },
    {
      "name": "Team",
      "description": "Members, invitations and the shared inbox. Most of these need a signed-in owner or admin."
    },
    {
      "name": "Hooks",
      "description": "Inbound hooks, a secret URL that turns another system's payload into one SMS."
    },
    {
      "name": "Support",
      "description": "Requests to SMSNET support, and the replies on them. Replies from support are also emailed to the account's address."
    },
    {
      "name": "Public",
      "description": "No authentication. Served from `https://smsnet.net/api/public/...`."
    }
  ],
  "paths": {
    "/messages/send": {
      "post": {
        "tags": [
          "Messages"
        ],
        "operationId": "sendMessage",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://smsnet.net/api/v1/messages/send \\n  -H \"X-API-Key: $SMSNET_API_KEY\" \\n  -H \"Content-Type: application/json\" \\n  -H \"Idempotency-Key: order-1842\" \\n  -d '{\"to\":\"+972501234567\",\"body\":\"Your table is ready\",\"client_ref\":\"order-1842\"}'\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst res = await sms.messages.send(\n  { to: \"+972501234567\", body: \"Your table is ready\", client_ref: \"order-1842\" },\n  { idempotencyKey: \"order-1842\" },\n);\nconsole.log(res.message_id, res.segments);\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nres = sms.messages.send(\"+972501234567\", \"Your table is ready\",\n                        client_ref=\"order-1842\", idempotency_key=\"order-1842\")\nprint(res[\"message_id\"])\n"
          }
        ],
        "summary": "Send an SMS",
        "description": "Queues one SMS on a connected line. The dispatcher releases it under the line's\nwarmup cap, pacing, per-line controls and the recipient's quiet hours, unless\n`transactional` is set. Requires scope `send`.\n\nOpt-out link: `{{unsubscribe}}` in `body` becomes the recipient's own opt-out\nlink (`https://smsnet.net/u/<token>`, one per number, the same as in campaigns).\n`unsubscribe: true` without the placeholder adds the link on its own line at the\nend (`Opt out: <link>`, or `להסרה: <link>` for a Hebrew body). The response then\ncarries `optout_link: true`. A sandbox (`sn_test_`) key gets an inert link. A\nplaceholder that would not turn into a link (`{{unsubscribe`, `unsubscribe}}`) is\nrefused with 400 `optout_placeholder_invalid`.\n\nAccount setting \"Add an opt-out link to automated messages\" (`auto_optout_link`,\noff by default; portal Safety > Rules, or `PUT /api/v1/suppression/settings`\n`{\"auto_optout_link\": true}`): when on, every send made with an API key or an AI\nclient that is not `transactional` gets the link as if `unsubscribe: true` were\nset. Sends a person makes in the portal or through SMSNET for Chrome are not\nchanged. The link helps you offer an opt-out; it does not make a message\ncompliant, and opt-outs received any other way remain yours to record.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendMessageRequest"
              },
              "examples": {
                "simple": {
                  "value": {
                    "to": "+972501234567",
                    "body": "Your table is ready",
                    "client_ref": "order_1842"
                  }
                },
                "scheduled_pinned": {
                  "value": {
                    "to": "+972501234567",
                    "body": "Reminder: tomorrow 10:00",
                    "send_at": "2026-10-12T07:00:00Z",
                    "sim_id": "sim_ab12",
                    "route_mode": "prefer"
                  }
                },
                "with_optout_link": {
                  "value": {
                    "to": "+972501234567",
                    "body": "20% off this week only",
                    "unsubscribe": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Queued. (200, not 201, for backward compatibility.)",
            "headers": {
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/IdempotentReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendMessageResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/messages": {
      "get": {
        "tags": [
          "Messages"
        ],
        "operationId": "listMessages",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl \"https://smsnet.net/api/v1/messages?direction=inbound&limit=100&since=$CURSOR\" \\n  -H \"X-API-Key: $SMSNET_API_KEY\"\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst page = await sms.messages.list({ direction: \"inbound\", since: cursor, limit: 100 });\n// or follow next_cursor automatically:\nfor await (const m of sms.messages.iterate({ since: cursor, direction: \"inbound\" })) handle(m);\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\npage = sms.messages.list(direction=\"inbound\", since=cursor, limit=100)\n# or follow next_cursor automatically:\nfor m in sms.messages.iterate(since=cursor, direction=\"inbound\"):\n    handle(m)\n"
          }
        ],
        "summary": "Message stream (cursor)",
        "description": "Everything that happened since your cursor, oldest first. The polling counterpart\nto webhooks. Feed `next_cursor` back as `since`; it is stable even when the page\nis empty. `since` also accepts a bare epoch-ms timestamp. Requires scope `read`.\n",
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Cursor `<created_at>_<id>` from a previous `next_cursor`, or epoch ms."
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "inbound",
                "outbound"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/MessageStatus"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of messages.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessagePage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/send-window": {
      "get": {
        "tags": [
          "Messages"
        ],
        "operationId": "getSendWindow",
        "summary": "Would quiet hours hold a message to this number?",
        "parameters": [
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Send-window explanation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "to": {
                      "type": "string"
                    },
                    "timezone": {
                      "type": "string"
                    },
                    "resolved_from": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/conversations": {
      "get": {
        "tags": [
          "Conversations"
        ],
        "operationId": "listConversations",
        "summary": "List conversations (latest 100)",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "closed",
                "all"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Conversations, most recent first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Conversation"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/conversations/{id}/messages": {
      "get": {
        "tags": [
          "Conversations"
        ],
        "operationId": "listConversationMessages",
        "summary": "Messages in a conversation",
        "description": "Up to 500 messages, oldest first. Marks the conversation read.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Messages.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Message"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/conversations/{id}/reply": {
      "post": {
        "tags": [
          "Conversations"
        ],
        "operationId": "replyToConversation",
        "summary": "Reply within a conversation",
        "description": "Same walls as `/messages/send` (opt-out, plan limits, abuse ceiling). Requires scope `send`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReplyRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Queued.",
            "headers": {
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/IdempotentReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendMessageResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      }
    },
    "/conversations/{id}/status": {
      "put": {
        "tags": [
          "Conversations"
        ],
        "operationId": "setConversationStatus",
        "summary": "Open or close a conversation",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "status"
                ],
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "open",
                      "closed"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/conversations/{id}/read": {
      "put": {
        "tags": [
          "Conversations"
        ],
        "operationId": "markConversationRead",
        "summary": "Clear the unread count",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/conversations/{id}/assign": {
      "post": {
        "tags": [
          "Team"
        ],
        "operationId": "assignConversation",
        "summary": "Hand a conversation to a team member, or to nobody",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id"
                ],
                "properties": {
                  "user_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "A team member, or null to unassign."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Assigned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "conversation_id": {
                      "type": "string"
                    },
                    "assigned_user_id": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "assigned_at": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/conversations/{id}/notes": {
      "get": {
        "tags": [
          "Team"
        ],
        "operationId": "listConversationNotes",
        "summary": "Internal notes on a conversation",
        "description": "Never sent to the customer. An agent limited to some lines sees the notes on those lines and their own.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The notes, oldest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "notes": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ConversationNote"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Team"
        ],
        "operationId": "addConversationNote",
        "summary": "Add an internal note",
        "description": "Needs a signed-in person. The note takes the line of the latest message that person can see in the thread.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "type": "string",
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Added.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "note": {
                      "$ref": "#/components/schemas/ConversationNote"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/team": {
      "get": {
        "tags": [
          "Team"
        ],
        "operationId": "getTeam",
        "summary": "Members, pending invitations and lines",
        "description": "A signed-in owner or admin. An API key gets 403.",
        "responses": {
          "200": {
            "description": "The team.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "members": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TeamMember"
                      }
                    },
                    "invites": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    "member_limit": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/team/invites": {
      "post": {
        "tags": [
          "Team"
        ],
        "operationId": "inviteTeamMember",
        "summary": "Invite someone by email",
        "description": "The same address again replaces the first invitation. An invitation stops working if its sender is no longer an owner or admin.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "admin",
                      "agent"
                    ],
                    "default": "agent"
                  },
                  "all_lines": {
                    "type": "boolean",
                    "default": false
                  },
                  "line_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sent.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "id": {
                      "type": "string"
                    },
                    "email": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "integer"
                    },
                    "emailed": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/team/invites/{id}": {
      "delete": {
        "tags": [
          "Team"
        ],
        "operationId": "withdrawTeamInvite",
        "summary": "Withdraw an invitation",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/team/members/{id}": {
      "put": {
        "tags": [
          "Team"
        ],
        "operationId": "updateTeamMember",
        "summary": "Change a member's role or lines",
        "description": "Only what you send changes: leave out `line_ids` and their lines stay. Moving an admin to\nagent ends what they held, as removal does, and `access_ended` says what. The owner cannot\nbe changed here (403 `owner_protected`).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "admin",
                      "agent"
                    ]
                  },
                  "all_lines": {
                    "type": "boolean"
                  },
                  "line_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "user_id": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string"
                    },
                    "all_lines": {
                      "type": "boolean"
                    },
                    "line_ids": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "access_ended": {
                      "$ref": "#/components/schemas/AccessEnded"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Team"
        ],
        "operationId": "removeTeamMember",
        "summary": "Remove a member",
        "description": "Their session on this account ends at once, and `access_ended` lists what ended with it and what the owner should still rotate.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Removed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "access_ended": {
                      "$ref": "#/components/schemas/AccessEnded"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/team/me": {
      "get": {
        "tags": [
          "Team"
        ],
        "operationId": "getMyTeamAccess",
        "summary": "My role and my lines",
        "responses": {
          "200": {
            "description": "The signed-in person.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "user_id": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string",
                      "enum": [
                        "owner",
                        "admin",
                        "agent"
                      ]
                    },
                    "all_lines": {
                      "type": "boolean"
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/team/assignees": {
      "get": {
        "tags": [
          "Team"
        ],
        "operationId": "listTeamAssignees",
        "summary": "Who a conversation can be assigned to",
        "parameters": [
          {
            "name": "conversation_id",
            "in": "query",
            "required": false,
            "description": "Only people who can see this conversation, the same test the assign call applies.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Names only, no addresses.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "user_id": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "role": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "The conversation does not exist or the caller cannot see it."
          }
        }
      }
    },
    "/support": {
      "get": {
        "tags": [
          "Support"
        ],
        "operationId": "listSupportRequests",
        "summary": "The account's support requests",
        "description": "The newest 50. `last_reply_at` is the latest reply from support; when it is newer than `customer_replied_at` (or that is null) the customer has an answer to read.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "requests": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SupportRequest"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Support"
        ],
        "operationId": "openSupportRequest",
        "summary": "Open a support request",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "subject",
                  "body"
                ],
                "properties": {
                  "subject": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "body": {
                    "type": "string",
                    "maxLength": 5000
                  },
                  "topic": {
                    "type": "string",
                    "enum": [
                      "setup",
                      "sending",
                      "delivery",
                      "billing",
                      "other"
                    ]
                  },
                  "saw_alert": {
                    "type": "string",
                    "maxLength": 80,
                    "description": "The alert id the person had already been shown."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Opened.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "id": {
                      "type": "string",
                      "examples": [
                        "sup_1a2b"
                      ]
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/support/{id}": {
      "get": {
        "tags": [
          "Support"
        ],
        "operationId": "getSupportRequest",
        "summary": "One support request and its replies",
        "description": "The request and every reply on it, oldest first. Notes the support desk keeps for itself are never included. The portal opens a request at `/support?request=<id>` (the link in every reply email).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "request": {
                      "$ref": "#/components/schemas/SupportRequest"
                    },
                    "notes": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SupportNote"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/support/{id}/reply": {
      "post": {
        "tags": [
          "Support"
        ],
        "operationId": "replyToSupportRequest",
        "summary": "Answer support on a request",
        "description": "Adds the customer's answer to the thread. A request that was resolved, or waiting on the customer, goes back to `investigating` and is open again. At most 20 answers an hour per account.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "type": "string",
                    "maxLength": 5000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Added.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "id": {
                      "type": "string",
                      "description": "The note id."
                    },
                    "request_id": {
                      "type": "string"
                    },
                    "stage": {
                      "type": "string",
                      "enum": [
                        "new",
                        "investigating",
                        "waiting_on_customer",
                        "resolved"
                      ]
                    },
                    "status": {
                      "type": "string"
                    },
                    "reopened": {
                      "type": "boolean",
                      "description": "True when the request was resolved or waiting on the customer."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/hooks/inbound": {
      "get": {
        "tags": [
          "Hooks"
        ],
        "operationId": "listInboundHooks",
        "summary": "The account's inbound hooks",
        "responses": {
          "200": {
            "description": "The hooks. The URL itself is never shown again after it is issued.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "hooks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/InboundHook"
                      }
                    },
                    "max_hooks": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Hooks"
        ],
        "operationId": "createInboundHook",
        "summary": "Create an inbound hook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InboundHookInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created. `url` holds the secret and is shown this once.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundHookIssued"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/hooks/inbound/{id}": {
      "put": {
        "tags": [
          "Hooks"
        ],
        "operationId": "updateInboundHook",
        "summary": "Change a hook",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/InboundHookInput"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "enabled": {
                        "type": "boolean"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "hook": {
                      "$ref": "#/components/schemas/InboundHook"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Hooks"
        ],
        "operationId": "deleteInboundHook",
        "summary": "Delete a hook and its URL",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/hooks/inbound/{id}/rotate": {
      "post": {
        "tags": [
          "Hooks"
        ],
        "operationId": "rotateInboundHook",
        "summary": "Replace the secret URL",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The new URL, shown this once. The old one stops at once.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundHookIssued"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/hooks/inbound/{id}/preview": {
      "post": {
        "tags": [
          "Hooks"
        ],
        "operationId": "previewInboundHook",
        "summary": "Show what a sample payload would send",
        "description": "Nothing is queued.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "payload"
                ],
                "properties": {
                  "payload": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "to": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "phone_found": {
                      "type": "boolean"
                    },
                    "body": {
                      "type": "string"
                    },
                    "missing": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/hooks/in/{token}": {
      "post": {
        "tags": [
          "Hooks"
        ],
        "operationId": "receiveInboundHook",
        "summary": "The public receiver",
        "description": "The token in the URL is the credential. One JSON or form payload becomes at most one\ntransactional SMS. Send `Idempotency-Key`, `webhook-id` or `X-Request-Id` so a retry does\nnot text twice. A premium-rate number is refused with 403 `hook_premium_blocked`. An\nopted-out number answers 200 with `skipped: \"opted_out\"`, so the sender stops retrying.\n",
        "security": [],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Queued, a duplicate, or skipped.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "queued": {
                      "type": "boolean"
                    },
                    "duplicate": {
                      "type": "boolean"
                    },
                    "skipped": {
                      "type": "string"
                    },
                    "message_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/contacts": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "operationId": "listContacts",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "# exact lookup by number (URL-encode the +)\ncurl \"https://smsnet.net/api/v1/contacts?phone=%2B972501234567\" -H \"X-API-Key: $SMSNET_API_KEY\"\n# substring search\ncurl \"https://smsnet.net/api/v1/contacts?search=dana&page=1\" -H \"X-API-Key: $SMSNET_API_KEY\"\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst found = await sms.contacts.list({ search: \"dana\" });\n// exact lookup by number:\nconst [contact] = await sms.raw(\"GET\", \"/api/v1/contacts\", undefined, { query: { phone: \"+972501234567\" } });\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nfound = sms.contacts.list(search=\"dana\")\n# exact lookup by number:\nmatches = sms.request(\"GET\", \"/api/v1/contacts\", query={\"phone\": \"+972501234567\"})\n"
          }
        ],
        "summary": "List contacts (50 per page), or look one up by phone",
        "description": "With `phone`, an exact lookup that answers the same array shape (`[]` or `[contact]`). Requires scope `read`.",
        "parameters": [
          {
            "name": "phone",
            "in": "query",
            "schema": {
              "type": "string",
              "examples": [
                "+972501234567"
              ]
            },
            "description": "Exact match on the E.164 number. URL-encode the `+` as `%2B` (an unencoded `+`, which arrives as a space, is accepted too). Fewer than 6 or more than 15 digits is 400 `invalid_phone`."
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Substring match on name or phone."
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Contacts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Contact"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Contacts"
        ],
        "operationId": "upsertContact",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://smsnet.net/api/v1/contacts \\n  -H \"X-API-Key: $SMSNET_API_KEY\" \\n  -H \"Content-Type: application/json\" \\n  -d '{\"phone\":\"+972501234567\",\"name\":\"Dana\",\"tags\":[\"vip\"]}'\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst { id } = await sms.contacts.create({ phone: \"+972501234567\", name: \"Dana\", tags: [\"vip\"] });\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nres = sms.contacts.create(\"+972501234567\", name=\"Dana\", tags=[\"vip\"])\n"
          }
        ],
        "summary": "Create or update a contact by phone",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "phone"
                ],
                "properties": {
                  "phone": {
                    "type": "string",
                    "description": "E.164"
                  },
                  "name": {
                    "type": "string"
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "opt_in": {
                    "type": "boolean"
                  },
                  "notes": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkWithId"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/contacts/import": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "operationId": "importContacts",
        "summary": "Bulk import contacts (and carry over a suppression list)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "contacts",
                  "consent_confirmed"
                ],
                "properties": {
                  "consent_confirmed": {
                    "type": "boolean",
                    "const": true
                  },
                  "contacts": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "phone"
                      ],
                      "properties": {
                        "phone": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "tags": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "opt_out": {
                          "type": "boolean",
                          "description": "Import as already opted out."
                        },
                        "consent_source": {
                          "type": "string",
                          "description": "Where the consent came from. A row with any consent field gets a record in the consent log."
                        },
                        "consent_at": {
                          "type": "string",
                          "description": "When the person agreed: ISO 8601, milliseconds, or dd/mm/yyyy."
                        },
                        "consent_method": {
                          "type": "string",
                          "enum": [
                            "web_form",
                            "checkbox",
                            "paper",
                            "verbal",
                            "sms_keyword",
                            "import",
                            "api",
                            "other"
                          ]
                        },
                        "consent_evidence": {
                          "type": "string",
                          "description": "The wording shown, or a reference to where it is kept."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Imported.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "imported": {
                      "type": "integer"
                    },
                    "suppressed": {
                      "type": "integer"
                    },
                    "consent_logged": {
                      "type": "integer",
                      "description": "Rows that got a consent record."
                    },
                    "consent_bad_dates": {
                      "type": "integer",
                      "description": "Of those, rows whose date could not be read; stored as unknown."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/consent": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "operationId": "listConsent",
        "summary": "The consent trail, newest first",
        "parameters": [
          {
            "name": "phone",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "contact_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "channel",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "sms",
                "email",
                "whatsapp",
                "voice"
              ]
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One page of records.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ConsentRecord"
                      }
                    },
                    "page": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      },
      "post": {
        "tags": [
          "Contacts"
        ],
        "operationId": "recordConsent",
        "summary": "Add to the consent trail (append-only)",
        "description": "Send one record, or `records` with up to 1000. Nothing is stored unless all are valid. `action:\"withdrawn\"` on the sms channel also opts the number out, at most 50 of those a call. A retry is safe. A number already withdrawn writes no second row and is counted in `already_withdrawn`. This log does not change what a campaign needs, which is still `consent_confirmed:true`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/ConsentInput"
                  },
                  {
                    "type": "object",
                    "required": [
                      "records"
                    ],
                    "properties": {
                      "records": {
                        "type": "array",
                        "maxItems": 1000,
                        "items": {
                          "$ref": "#/components/schemas/ConsentInput"
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "recorded": {
                      "type": "integer"
                    },
                    "already_withdrawn": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/consent/export": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "operationId": "exportConsent",
        "summary": "The consent trail as CSV",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "CSV file.",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/consent/coverage": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "operationId": "consentCoverage",
        "summary": "How many of a list have a logged consent",
        "description": "Takes the same `recipients`, `tag` and `tags` as a campaign. Anyone opted out is left out of `total` and counted in `opted_out`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "recipients": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "tag": {
                    "type": "string"
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "channel": {
                    "type": "string",
                    "enum": [
                      "sms",
                      "email",
                      "whatsapp",
                      "voice"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "channel": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "logged": {
                      "type": "integer"
                    },
                    "declared_only": {
                      "type": "integer"
                    },
                    "opted_out": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/suppression/removal-report": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "operationId": "removalReport",
        "summary": "Everyone opted out now, with time and source",
        "parameters": [
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "csv",
                "json"
              ],
              "default": "csv"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "CSV file, or JSON with `format=json`.",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "phone": {
                            "type": "string"
                          },
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "opted_out_at": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "source": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "sms, portal, api, mcp, import or link."
                          },
                          "reason": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "generated_at": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/contacts/{id}": {
      "put": {
        "tags": [
          "Contacts"
        ],
        "operationId": "updateContact",
        "summary": "Update a contact (name, tags, notes, opt_out)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "opt_out": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated contact.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "contact": {
                      "$ref": "#/components/schemas/Contact"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/contacts/{id}/opt-out": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "operationId": "optOutContact",
        "summary": "Opt a contact out (logged in the suppression log)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/templates": {
      "get": {
        "tags": [
          "Templates"
        ],
        "operationId": "listTemplates",
        "summary": "List templates",
        "responses": {
          "200": {
            "description": "Templates.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Template"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Templates"
        ],
        "operationId": "createTemplate",
        "summary": "Create a template",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "body"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "body": {
                    "type": "string"
                  },
                  "category": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkWithId"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/campaigns": {
      "get": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "listCampaigns",
        "summary": "List campaigns (latest 100) with progress",
        "responses": {
          "200": {
            "description": "Campaigns.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Campaign"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "createCampaign",
        "summary": "Create and launch a campaign",
        "description": "Recipients from an explicit list and/or contact tags (deduplicated; opted-out contacts are skipped). Requires scope `send`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCampaignRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Campaign created.",
            "headers": {
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/IdempotentReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "campaign_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/campaigns/{id}": {
      "get": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "getCampaign",
        "summary": "Get one campaign with progress",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Campaign.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "campaign": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/campaigns/{id}/stats": {
      "get": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "getCampaignStats",
        "summary": "Status buckets for a campaign",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Buckets (they add up to `total`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pending": {
                      "type": "integer"
                    },
                    "sent": {
                      "type": "integer"
                    },
                    "delivered": {
                      "type": "integer"
                    },
                    "failed": {
                      "type": "integer"
                    },
                    "expired": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/devices": {
      "get": {
        "tags": [
          "Devices"
        ],
        "operationId": "listDevices",
        "summary": "List paired phones",
        "responses": {
          "200": {
            "description": "Devices.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Device"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/devices/{id}": {
      "delete": {
        "tags": [
          "Devices"
        ],
        "operationId": "removeDevice",
        "summary": "Retire a phone (its lines go inactive, its queue is re-routed)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Removed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "lines_retired": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/fleet": {
      "get": {
        "tags": [
          "Devices"
        ],
        "operationId": "getFleet",
        "summary": "Every phone with its lines, queue depth and capacity",
        "responses": {
          "200": {
            "description": "Fleet view.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "devices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    "total_devices": {
                      "type": "integer"
                    },
                    "total_queued": {
                      "type": "integer"
                    },
                    "remaining_capacity_today": {
                      "type": "integer"
                    },
                    "test_mode": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/sims": {
      "get": {
        "tags": [
          "Lines"
        ],
        "operationId": "listSims",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl https://smsnet.net/api/v1/sims -H \"X-API-Key: $SMSNET_API_KEY\"\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst lines = await sms.sims.list();\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nlines = sms.sims.list()\n"
          }
        ],
        "summary": "List lines (SIMs) with health and controls",
        "responses": {
          "200": {
            "description": "Lines.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Sim"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/sims/{id}": {
      "get": {
        "tags": [
          "Lines"
        ],
        "operationId": "getSim",
        "summary": "Get one line",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Line.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Sim"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Lines"
        ],
        "operationId": "updateSim",
        "summary": "Update daily limit, profile, status, enabled or line type",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "daily_send_limit": {
                    "type": "integer"
                  },
                  "send_profile": {
                    "type": "string",
                    "enum": [
                      "cautious",
                      "balanced",
                      "fast"
                    ]
                  },
                  "status": {
                    "type": "string"
                  },
                  "enabled": {
                    "type": "boolean"
                  },
                  "line_type": {
                    "type": "string",
                    "enum": [
                      "prepaid",
                      "postpaid",
                      "business",
                      "unknown"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/sims/{id}/enable": {
      "post": {
        "tags": [
          "Lines"
        ],
        "operationId": "enableSim",
        "summary": "Turn sending on/off for one line (receiving continues)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "enabled": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/sims/{id}/safety": {
      "put": {
        "tags": [
          "Lines"
        ],
        "operationId": "updateSimSafety",
        "summary": "Per-line safety and send controls",
        "description": "`trust_level: \"established\"` (skip warmup) requires a paid plan (402 otherwise).\nA daily limit is a ceiling: the effective cap is the lower of it and the warmup ramp.\n`max_per_minute`, `max_per_hour`, jitter and `working_hours` are sender-side controls\n(null clears; an absent field is left alone); recipient quiet hours always apply in addition.\nWhen both jitter bounds are set they replace the trust-profile gap for that line.\n`working_hours` also applies to transactional messages (they fail over to another line).\nInvalid values → 400 `invalid_controls`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SimSafetyRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated line.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "trust_level": {
                      "type": "string"
                    },
                    "send_profile": {
                      "type": "string"
                    },
                    "daily_send_limit": {
                      "type": "integer"
                    },
                    "effective_cap_today": {
                      "type": "integer"
                    },
                    "controls": {
                      "$ref": "#/components/schemas/SimControls"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "402": {
            "description": "Paid plan required to skip warmup.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/sims/{id}/health": {
      "get": {
        "tags": [
          "Lines"
        ],
        "operationId": "getSimHealth",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl https://smsnet.net/api/v1/sims/$SIM_ID/health -H \"X-API-Key: $SMSNET_API_KEY\"\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst health = await sms.sims.health(\"sim_abc\"); // score, state, warmup, headroom_today, signals\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nhealth = sms.sims.health(\"sim_abc\")\nprint(health[\"state\"], health[\"score\"])\n"
          }
        ],
        "summary": "Line health score and state",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Health.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LineHealth"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/sims/{id}/health/clear": {
      "post": {
        "tags": [
          "Lines"
        ],
        "operationId": "clearSimRest",
        "summary": "End an automatic rest early",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Health after clearing.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LineHealth"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/sims/{id}/activity": {
      "get": {
        "tags": [
          "Lines"
        ],
        "operationId": "getSimActivity",
        "summary": "Last 200 messages on a line",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Activity rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/sims/{id}/stats": {
      "get": {
        "tags": [
          "Lines"
        ],
        "operationId": "getSimStats",
        "summary": "Lifetime counts for a line",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sent": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "delivered": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "failed": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "inbound": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/capacity": {
      "get": {
        "tags": [
          "Lines"
        ],
        "operationId": "getCapacity",
        "summary": "Daily capacity vs usage vs plan",
        "responses": {
          "200": {
            "description": "Capacity.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "active_sims": {
                      "type": "integer"
                    },
                    "daily_capacity": {
                      "type": "integer"
                    },
                    "used_today": {
                      "type": "integer"
                    },
                    "plan_max_sims": {
                      "type": "integer"
                    },
                    "msg_limit": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/otp/send": {
      "post": {
        "tags": [
          "OTP"
        ],
        "operationId": "sendOtp",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://smsnet.net/api/v1/otp/send \\n  -H \"X-API-Key: $SMSNET_API_KEY\" \\n  -H \"Content-Type: application/json\" \\n  -d '{\"to\":\"+972501234567\",\"length\":6,\"ttl_s\":300}'\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst { otp_id, expires_at } = await sms.otp.send({ to: \"+972501234567\", length: 6, ttl_s: 300 });\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\notp = sms.otp.send(\"+972501234567\", length=6, ttl_s=300)\notp_id = otp[\"otp_id\"]\n"
          }
        ],
        "summary": "Send a one-time code",
        "description": "Generates a numeric code, sends it transactionally (no pacing or quiet hours; opt-out\nand caps still apply) and stores only an HMAC of it. Max 3 active codes per\nnumber per 10 minutes (a verified code frees its slot). Validation errors: 400 `invalid_to`,\n`invalid_length`, `invalid_ttl`, `invalid_template` (must contain `{code}`). With an\n`sn_test_` key the response includes the `code`. Requires scope `send`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OtpSendRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Code sent.",
            "headers": {
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/IdempotentReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OtpSendResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/otp/verify": {
      "post": {
        "tags": [
          "OTP"
        ],
        "operationId": "verifyOtp",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://smsnet.net/api/v1/otp/verify \\n  -H \"X-API-Key: $SMSNET_API_KEY\" \\n  -H \"Content-Type: application/json\" \\n  -d '{\"otp_id\":\"otp_8f2c\",\"code\":\"482913\"}'\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst { valid, reason, attempts_left } = await sms.otp.verify({ otp_id, code: userInput });\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nresult = sms.otp.verify(user_input, otp_id=otp_id)\nif not result[\"valid\"]:\n    print(result[\"reason\"], result.get(\"attempts_left\"))\n"
          }
        ],
        "summary": "Verify a one-time code",
        "description": "Five attempts per code. A valid code is consumed. Requires scope `send`. 400 `invalid_code` / `otp_id_or_to_required`. Pass `otp_id` (preferred) or `to` (latest active code for that number).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OtpVerifyRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verification result (200 also when the code is not valid).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OtpVerifyResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/otp/settings": {
      "get": {
        "tags": [
          "OTP"
        ],
        "operationId": "getOtpSettings",
        "summary": "Countries allowed for codes, and whether codes are paused",
        "responses": {
          "200": {
            "description": "The settings.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OtpSettings"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "put": {
        "tags": [
          "OTP"
        ],
        "operationId": "setOtpSettings",
        "summary": "Allow countries beyond your lines' own",
        "description": "Premium-rate ranges stay blocked in every country. Requires `manage`. A test key cannot change this.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "allowed_countries"
                ],
                "properties": {
                  "allowed_countries": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "ISO country codes, for example [\"US\", \"GB\"]."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The list as stored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/otp/settings/resume": {
      "post": {
        "tags": [
          "OTP"
        ],
        "operationId": "resumeOtp",
        "summary": "End a conversion pause early",
        "responses": {
          "200": {
            "description": "Codes can go again.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/otp/{id}": {
      "get": {
        "tags": [
          "OTP"
        ],
        "operationId": "getOtp",
        "summary": "A code's status and delivery state",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Status (`active`, `verified`, `failed`, `expired`) and delivery state.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/otp/validate-template": {
      "servers": [
        {
          "url": "https://smsnet.net/api/public"
        }
      ],
      "post": {
        "tags": [
          "OTP"
        ],
        "operationId": "validateOtpTemplate",
        "summary": "Check a code template, with bytes and encoding",
        "description": "No key needed. Composes `presets` into the template and reports the bytes in one SMS, the\nencoding, and what is wrong. Hebrew takes two bytes a character. Pass the returned `template`\nas `template` on `POST /otp/send`, or send the same fields there.\n",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "template": {
                    "type": "string"
                  },
                  "presets": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "sms_retriever",
                        "webotp",
                        "ios_domain"
                      ]
                    }
                  },
                  "app_hash": {
                    "type": "string"
                  },
                  "domain": {
                    "type": "string"
                  },
                  "length": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The result. `ok` is false when `errors` is not empty.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/verify/reverse/start": {
      "post": {
        "tags": [
          "OTP"
        ],
        "operationId": "startReverseVerification",
        "summary": "Reverse OTP, the person texts your line",
        "description": "Sends nothing. Show `sms_link` on a phone or a QR of `qr_data` on a desktop; the person sends the\nprefilled text from their own phone, and their carrier may charge them for it. A token lasts 2 to\n3 minutes and works once. Good for signup, not for a sensitive action: a sender number can be\nforged. Not counted against plan quota. Accounts without business verification get\n`verification_required`. Requires `send`; accepts `Idempotency-Key`.\n",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "business_name": {
                    "type": "string",
                    "maxLength": 40,
                    "description": "Goes in the text. Default the account name."
                  },
                  "phone": {
                    "type": "string",
                    "description": "If given the text must come from this number."
                  },
                  "session_id": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 128,
                    "description": "Your session for this person. Default one is generated and returned."
                  },
                  "ttl_s": {
                    "type": "integer",
                    "minimum": 120,
                    "maximum": 180,
                    "default": 180
                  },
                  "lang": {
                    "type": "string",
                    "enum": [
                      "en",
                      "he"
                    ],
                    "default": "en"
                  },
                  "sim_id": {
                    "type": "string"
                  },
                  "client_ref": {
                    "type": "string",
                    "maxLength": 128
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Started.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "verification_id",
                    "session_id",
                    "token",
                    "line_number",
                    "body",
                    "sms_link",
                    "qr_data",
                    "expires_at"
                  ],
                  "properties": {
                    "verification_id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "pending"
                      ]
                    },
                    "session_id": {
                      "type": "string",
                      "description": "Needed to read the result."
                    },
                    "token": {
                      "type": "string"
                    },
                    "line_number": {
                      "type": "string"
                    },
                    "body": {
                      "type": "string",
                      "description": "The exact text the person sends."
                    },
                    "sms_link": {
                      "type": "string"
                    },
                    "qr_data": {
                      "type": "string",
                      "description": "An SMSTO: string to draw as a QR code."
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/verify/{id}": {
      "get": {
        "tags": [
          "OTP"
        ],
        "operationId": "getVerification",
        "summary": "The result of a reverse verification",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "name": "X-Session-Id",
            "in": "header",
            "schema": {
              "type": "string"
            },
            "description": "The session_id used at start, or returned by it. Send this one of the two."
          },
          {
            "name": "session_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "The same, as a query parameter. It works, but a query string lands in access logs."
          }
        ],
        "responses": {
          "200": {
            "description": "`status` is `pending`, `verified` or `expired`. `phone` is the number that texted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "verification_id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "pending",
                        "verified",
                        "expired"
                      ]
                    },
                    "verified": {
                      "type": "boolean"
                    },
                    "phone": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "mismatch": {
                      "type": "boolean",
                      "description": "A text came from a number other than the declared one."
                    }
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/verify/reverse/{id}/simulate": {
      "post": {
        "tags": [
          "OTP"
        ],
        "operationId": "simulateVerification",
        "summary": "Finish a sandbox verification (test key only)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "from": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/usage": {
      "get": {
        "tags": [
          "Usage"
        ],
        "operationId": "getUsage",
        "summary": "Rolling usage window and daily series",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 90,
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Usage.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "getWebhookConfig",
        "summary": "Legacy webhook endpoint, secret, events and 24h delivery stats",
        "responses": {
          "200": {
            "description": "Config.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookConfig"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "put": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "setWebhookUrl",
        "summary": "Set or clear the legacy webhook URL",
        "description": "Acts on the `source:\"legacy\"` endpoint (created on first PUT). https only; private and loopback addresses are refused. Pass an empty `url` to clear. Integrations should use `/webhooks/endpoints` instead and never touch this URL.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "url": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "secret": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/webhooks/endpoints": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "listWebhookEndpoints",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl https://smsnet.net/api/v1/webhooks/endpoints -H \"X-API-Key: $SMSNET_API_KEY\"\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst { endpoints } = await sms.webhooks.endpoints.list();\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nendpoints = sms.webhooks.endpoints.list()[\"endpoints\"]\n"
          }
        ],
        "summary": "List webhook endpoints (secrets never included)",
        "description": "Requires scope `manage`.",
        "responses": {
          "200": {
            "description": "Endpoints.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "endpoints"
                  ],
                  "properties": {
                    "endpoints": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookEndpoint"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "createWebhookEndpoint",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://smsnet.net/api/v1/webhooks/endpoints \\n  -H \"X-API-Key: $SMSNET_API_KEY\" \\n  -H \"Content-Type: application/json\" \\n  -d '{\"url\":\"https://example.com/smsnet\",\"events\":[\"message.received\",\"message.status\"],\"description\":\"billing service\"}'\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst ep = await sms.webhooks.endpoints.create({\n  url: \"https://example.com/smsnet\",\n  events: [\"message.received\", \"message.status\"],\n  description: \"billing service\",\n});\nsaveSecret(ep.secret); // \"whsec_...\", shown once\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nep = sms.webhooks.endpoints.create(\"https://example.com/smsnet\",\n                                   events=[\"message.received\", \"message.status\"],\n                                   description=\"billing service\")\nsave_secret(ep[\"secret\"])  # \"whsec_...\", shown once\n"
          }
        ],
        "summary": "Add a webhook endpoint (secret shown once)",
        "description": "Up to 10 per account, the legacy endpoint included (409 `endpoint_limit`). URL must be https to a public host (400 `invalid_url`); 400 `invalid_events`, 400 `invalid_source` (`legacy` is reserved). A workflow tool such as n8n, Zapier or Make can use its own endpoint, so nothing overwrites anything else. Requires scope `manage`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookEndpointRequest"
              },
              "examples": {
                "n8n": {
                  "value": {
                    "url": "https://n8n.example.com/webhook/abc",
                    "events": [
                      "message.received"
                    ],
                    "description": "n8n workflow Leads",
                    "source": "n8n"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created. Store the secret now; it is not shown again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedWebhookEndpoint"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/webhooks/endpoints/{id}": {
      "patch": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "updateWebhookEndpoint",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X PATCH https://smsnet.net/api/v1/webhooks/endpoints/$ENDPOINT_ID \\n  -H \"X-API-Key: $SMSNET_API_KEY\" \\n  -H \"Content-Type: application/json\" \\n  -d '{\"enabled\":true}'\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nawait sms.webhooks.endpoints.update(endpointId, { enabled: true });\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nsms.webhooks.endpoints.update(endpoint_id, enabled=True)\n"
          }
        ],
        "summary": "Change URL, events, description, or re-enable an endpoint",
        "description": "An endpoint failing for 5 consecutive days (or 50 consecutive deliveries) is disabled automatically and the owner is emailed; PATCH `enabled:true` re-enables it.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWebhookEndpointRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "deleteWebhookEndpoint",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X DELETE https://smsnet.net/api/v1/webhooks/endpoints/$ENDPOINT_ID -H \"X-API-Key: $SMSNET_API_KEY\"\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nawait sms.webhooks.endpoints.delete(endpointId);\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nsms.webhooks.endpoints.delete(endpoint_id)\n"
          }
        ],
        "summary": "Delete an endpoint",
        "description": "Its pending deliveries are marked failed. Deleting the legacy endpoint clears the legacy URL.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/webhooks/endpoints/{id}/rotate-secret": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "rotateWebhookEndpointSecret",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://smsnet.net/api/v1/webhooks/endpoints/$ENDPOINT_ID/rotate-secret -H \"X-API-Key: $SMSNET_API_KEY\"\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nconst { secret } = await sms.webhooks.endpoints.rotateSecret(endpointId); // old one signs for 24h more\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nsecret = sms.webhooks.endpoints.rotate_secret(endpoint_id)[\"secret\"]  # old one signs for 24h more\n"
          }
        ],
        "summary": "Rotate one endpoint's secret",
        "description": "The old secret keeps signing in parallel for 24h (second signature in `webhook-signature`).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "New secret.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "secret"
                  ],
                  "properties": {
                    "secret": {
                      "type": "string",
                      "examples": [
                        "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw"
                      ]
                    },
                    "previous_valid_until": {
                      "type": "integer",
                      "description": "Epoch ms until which the old secret also signs."
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/webhooks/endpoints/{id}/test": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "testWebhookEndpoint",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://smsnet.net/api/v1/webhooks/endpoints/$ENDPOINT_ID/test -H \"X-API-Key: $SMSNET_API_KEY\"\n"
          },
          {
            "lang": "JavaScript",
            "label": "Node (smsnet)",
            "source": "import { Smsnet } from \"smsnet\";\nconst sms = new Smsnet(process.env.SMSNET_API_KEY);\nawait sms.webhooks.endpoints.test(endpointId);\n"
          },
          {
            "lang": "Python",
            "label": "Python (smsnet)",
            "source": "from smsnet import Client\nsms = Client()  # reads SMSNET_API_KEY\nsms.webhooks.endpoints.test(endpoint_id)\n"
          }
        ],
        "summary": "Send webhook.test to this endpoint only",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Test queued and attempted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "delivery": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "additionalProperties": true
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/webhooks/rotate-secret": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "rotateWebhookSecret",
        "summary": "Rotate the legacy endpoint's signing secret",
        "responses": {
          "200": {
            "description": "New secret.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "secret": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/webhooks/test": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "sendTestWebhook",
        "summary": "Send a signed webhook.test event to the legacy endpoint",
        "responses": {
          "200": {
            "description": "Test queued and attempted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "delivery": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "additionalProperties": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/webhooks/deliveries": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "listWebhookDeliveries",
        "summary": "Delivery log (30 days)",
        "parameters": [
          {
            "name": "endpoint_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Only deliveries to this endpoint."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "delivered",
                "failed"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deliveries, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WebhookDelivery"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/webhooks/deliveries/{id}/replay": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "replayWebhookDelivery",
        "summary": "Replay one delivery",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Requeued.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "queued": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/webhooks/replay-failed": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "replayFailedWebhooks",
        "summary": "Replay every failed delivery",
        "parameters": [
          {
            "name": "endpoint_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Only this endpoint's failed deliveries."
          }
        ],
        "responses": {
          "200": {
            "description": "Requeued.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "queued": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/keys": {
      "get": {
        "tags": [
          "Keys"
        ],
        "operationId": "listKeys",
        "summary": "List API keys (display prefix only)",
        "description": "Requires scope `manage`.",
        "responses": {
          "200": {
            "description": "Keys.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiKey"
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "tags": [
          "Keys"
        ],
        "operationId": "createKey",
        "summary": "Create a scoped key (full key returned once)",
        "description": "Needs a signed-in owner in the portal; an API key gets 403 (a leaked key must not mint more keys). At most 25 active keys (409 `too_many_keys`).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateKeyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedApiKey"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/keys/{id}": {
      "delete": {
        "tags": [
          "Keys"
        ],
        "operationId": "deleteKey",
        "summary": "Revoke a key",
        "description": "Session or a `manage` key. A key cannot revoke itself (400 `cannot_revoke_self`); `legacy` cannot be deleted (400).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "id": {
                      "type": "string"
                    },
                    "revoked": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/settings": {
      "put": {
        "tags": [
          "Settings"
        ],
        "operationId": "updateSettings",
        "summary": "Account settings (timezone, quiet hours, send profile, test mode)",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "timezone": {
                    "type": "string",
                    "examples": [
                      "Asia/Jerusalem"
                    ]
                  },
                  "send_profile": {
                    "type": "string",
                    "enum": [
                      "cautious",
                      "balanced",
                      "fast"
                    ]
                  },
                  "quiet_start": {
                    "type": "string",
                    "examples": [
                      "21:00"
                    ]
                  },
                  "quiet_end": {
                    "type": "string",
                    "examples": [
                      "08:00"
                    ]
                  },
                  "test_mode": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/settings/fallback": {
      "get": {
        "tags": [
          "Settings"
        ],
        "operationId": "getFallback",
        "summary": "Hybrid fallback provider (masked)",
        "responses": {
          "200": {
            "description": "Fallback config, or null when none is set.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/FallbackConfigMasked"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "put": {
        "tags": [
          "Settings"
        ],
        "operationId": "setFallback",
        "summary": "Configure the account's own Twilio as fallback",
        "description": "Stored encrypted with the account key. Invalid input → 400 `invalid_fallback`. A `fallback:true` message is accepted with no paired phone when a provider is set. Used only for messages sent with `fallback:true` that no line could release within 10 minutes; never for `route_mode:\"strict\"`. Opt-out and suppression still apply.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FallbackConfig"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved (masked).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FallbackConfigMasked"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      },
      "delete": {
        "tags": [
          "Settings"
        ],
        "operationId": "deleteFallback",
        "summary": "Remove the fallback provider",
        "responses": {
          "200": {
            "$ref": "#/components/responses/Ok"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/plans": {
      "get": {
        "tags": [
          "Public"
        ],
        "operationId": "listPlans",
        "summary": "Public pricing plans",
        "description": "Plans `free`, `starter`, `growth`, `scale`, `agency` and `reseller`, each with its USD price (`price_num`)\nand, since 10.10.2026, its ILS list price before VAT (`price_ils`) and with VAT 18% (`price_ils_total`).\n`price_book` is the full price book: per plan `USD` (VAT 0%, sold abroad) and `ILS` (VAT 18% added, sold in Israel),\nVAT rates, the Reseller seat price and the Agency shape (up to 5 sub-accounts sharing 5 lines, no white label).\n",
        "security": [],
        "responses": {
          "200": {
            "description": "Plans.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "properties": {
                    "plans": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true,
                        "properties": {
                          "key": {
                            "type": "string",
                            "enum": [
                              "free",
                              "starter",
                              "growth",
                              "scale",
                              "agency",
                              "reseller"
                            ]
                          },
                          "name": {
                            "type": "string"
                          },
                          "price": {
                            "type": "string",
                            "example": "$29"
                          },
                          "price_num": {
                            "type": "number",
                            "description": "USD per month."
                          },
                          "price_ils": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "ILS per month before VAT."
                          },
                          "price_ils_total": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "ILS per month including VAT 18%."
                          },
                          "note": {
                            "type": "string"
                          },
                          "retention": {
                            "type": "string"
                          },
                          "features": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    },
                    "price_book": {
                      "type": "object",
                      "additionalProperties": true,
                      "properties": {
                        "currencies": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "USD",
                              "ILS"
                            ]
                          }
                        },
                        "vat_rate": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "number"
                          },
                          "example": {
                            "USD": 0,
                            "ILS": 18
                          }
                        },
                        "plans": {
                          "type": "object",
                          "additionalProperties": true,
                          "description": "Per plan: { USD: {amount, vat_rate, total, display}, ILS: {amount, vat_rate, vat, total, display, display_total} }."
                        },
                        "seat_price": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "number"
                          }
                        },
                        "agency": {
                          "type": "object",
                          "properties": {
                            "max_subaccounts": {
                              "type": "integer"
                            },
                            "pooled_lines": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "plans": [
                    {
                      "key": "agency",
                      "name": "Agency",
                      "price": "$129",
                      "price_num": 129,
                      "price_ils": 449,
                      "price_ils_total": 529.82,
                      "note": "per month, 5 lines"
                    }
                  ],
                  "price_book": {
                    "currencies": [
                      "USD",
                      "ILS"
                    ],
                    "vat_rate": {
                      "USD": 0,
                      "ILS": 18
                    },
                    "agency": {
                      "max_subaccounts": 5,
                      "pooled_lines": 5
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/health": {
      "servers": [
        {
          "url": "https://smsnet.net/api"
        }
      ],
      "get": {
        "tags": [
          "Public"
        ],
        "operationId": "getHealth",
        "summary": "Liveness check for monitors (database and dispatcher)",
        "description": "Full URL: `https://smsnet.net/api/health`. 200 with `ok: true` when the database answers and the dispatcher ran in the last 5 minutes; **503** with `ok: false` otherwise (`degraded: dispatch_stale` or `db: down`). The body is not the error envelope: read `ok`.",
        "security": [],
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -fsS https://smsnet.net/api/health || echo \"SMSNET unhealthy\"\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Healthy.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "ok": true,
                  "db": "up",
                  "dispatch_age_seconds": 42
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "503": {
            "description": "Unhealthy (dispatcher stale or database down).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "ok": false,
                  "db": "up",
                  "dispatch_age_seconds": 612,
                  "degraded": "dispatch_stale"
                }
              }
            }
          }
        }
      }
    },
    "/public/status": {
      "servers": [
        {
          "url": "https://smsnet.net/api"
        }
      ],
      "get": {
        "tags": [
          "Public"
        ],
        "operationId": "getPublicStatus",
        "summary": "Service status (cached 30s)",
        "description": "Full URL: `https://smsnet.net/api/public/status`. Dispatcher is degraded after 3 minutes without a tick, outage after 10.",
        "security": [],
        "responses": {
          "200": {
            "description": "Status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicStatus"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/public/carrier-limits": {
      "servers": [
        {
          "url": "https://smsnet.net/api"
        }
      ],
      "get": {
        "tags": [
          "Public"
        ],
        "operationId": "getCarrierLimits",
        "summary": "Measured daily sending per carrier (aggregate, anonymous, cached 1h)",
        "description": "Full URL: `https://smsnet.net/api/public/carrier-limits`. Only carriers with at least 3 lines from at least 2 accounts over the last 30 days. Never account ids, numbers or content. An empty list is a valid answer.",
        "security": [],
        "responses": {
          "200": {
            "description": "Carrier limits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CarrierLimits"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/public/mcp-tools": {
      "servers": [
        {
          "url": "https://smsnet.net/api"
        }
      ],
      "get": {
        "tags": [
          "Public"
        ],
        "operationId": "getMcpTools",
        "summary": "The MCP tool catalogue (names, descriptions, input schemas)",
        "description": "Full URL: `https://smsnet.net/api/public/mcp-tools`. The same list `tools/list` returns on `https://smsnet.net/mcp` to a trusted client, published without auth so directories and agents can read it before connecting.",
        "security": [],
        "responses": {
          "200": {
            "description": "Tool catalogue.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "protocol_version": {
                      "type": "string",
                      "examples": [
                        "2025-06-18"
                      ]
                    },
                    "endpoint": {
                      "type": "string",
                      "examples": [
                        "https://smsnet.net/mcp"
                      ]
                    },
                    "auth": {
                      "type": "string",
                      "description": "How to authenticate to the endpoint."
                    },
                    "trust_tools": {
                      "type": "array",
                      "description": "The two tools a not-yet-approved client sees (approve_client, check_approval).",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    "tools": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "name",
                          "description",
                          "inputSchema"
                        ],
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "scope": {
                            "type": "string",
                            "enum": [
                              "send",
                              "read",
                              "manage"
                            ]
                          },
                          "inputSchema": {
                            "type": "object",
                            "additionalProperties": true
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    }
  },
  "webhooks": {
    "message.received": {
      "post": {
        "operationId": "onMessageReceived",
        "summary": "An inbound SMS arrived",
        "description": "Fired for every inbound message, including ones released from quarantine (`was_quarantined:true`).",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "message.received"
                      },
                      "data": {
                        "$ref": "#/components/schemas/MessageReceivedData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "message.status": {
      "post": {
        "operationId": "onMessageStatus",
        "summary": "An outbound message changed status",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "message.status"
                      },
                      "data": {
                        "$ref": "#/components/schemas/MessageStatusData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "message.quarantined": {
      "post": {
        "operationId": "onMessageQuarantined",
        "summary": "An inbound message was held as likely phishing (body not included)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "message.quarantined"
                      },
                      "data": {
                        "type": "object",
                        "properties": {
                          "quarantine_id": {
                            "type": "string"
                          },
                          "from": {
                            "type": "string"
                          },
                          "score": {
                            "type": "number"
                          },
                          "threshold": {
                            "type": "number"
                          },
                          "reasons": {
                            "type": "array",
                            "items": {}
                          },
                          "sim_id": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "created_at": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "contact.opted_out": {
      "post": {
        "operationId": "onContactOptedOut",
        "summary": "A contact opted out (keyword, portal, API or import)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "contact.opted_out"
                      },
                      "data": {
                        "$ref": "#/components/schemas/ContactSuppressionData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "contact.opted_in": {
      "post": {
        "operationId": "onContactOptedIn",
        "summary": "A contact resubscribed",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "contact.opted_in"
                      },
                      "data": {
                        "$ref": "#/components/schemas/ContactSuppressionData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "device.offline": {
      "post": {
        "operationId": "onDeviceOffline",
        "summary": "A phone stopped sending heartbeats (12 minutes)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "device.offline"
                      },
                      "data": {
                        "type": "object",
                        "properties": {
                          "device_id": {
                            "type": "string"
                          },
                          "nickname": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "phone_number": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "last_seen": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "reason": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "device.online": {
      "post": {
        "operationId": "onDeviceOnline",
        "summary": "A phone came back after a device.offline was sent",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "device.online"
                      },
                      "data": {
                        "$ref": "#/components/schemas/DevicePowerData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "device.power_lost": {
      "post": {
        "operationId": "onDevicePowerLost",
        "summary": "A phone was unplugged while below 50% battery",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "device.power_lost"
                      },
                      "data": {
                        "$ref": "#/components/schemas/DevicePowerData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "sim.capacity": {
      "post": {
        "operationId": "onSimCapacity",
        "summary": "A line is approaching or at its daily cap",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "sim.capacity"
                      },
                      "data": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "line.health_changed": {
      "post": {
        "operationId": "onLineHealthChanged",
        "summary": "A line's health state changed (for example healthy to resting)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "line.health_changed"
                      },
                      "data": {
                        "type": "object",
                        "required": [
                          "sim_id",
                          "from",
                          "to"
                        ],
                        "properties": {
                          "sim_id": {
                            "type": "string"
                          },
                          "from": {
                            "$ref": "#/components/schemas/LineState"
                          },
                          "to": {
                            "$ref": "#/components/schemas/LineState"
                          },
                          "reason": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "resting_until": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          }
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "mcp.client_pending": {
      "post": {
        "operationId": "onMcpClientPending",
        "summary": "An unknown AI client used this account's key (approval needed if the trust gate is on)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "mcp.client_pending"
                      },
                      "data": {
                        "$ref": "#/components/schemas/McpClientData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "mcp.client_trusted": {
      "post": {
        "operationId": "onMcpClientTrusted",
        "summary": "An AI client was approved",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "mcp.client_trusted"
                      },
                      "data": {
                        "$ref": "#/components/schemas/McpClientData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "mcp.client_denied": {
      "post": {
        "operationId": "onMcpClientDenied",
        "summary": "An AI client was denied",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "mcp.client_denied"
                      },
                      "data": {
                        "$ref": "#/components/schemas/McpClientData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "mcp.approval_requested": {
      "post": {
        "operationId": "onMcpApprovalRequested",
        "summary": "An agent's first message to a new number is waiting for human approval",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "mcp.approval_requested"
                      },
                      "data": {
                        "type": "object",
                        "properties": {
                          "approval_id": {
                            "type": "string"
                          },
                          "to": {
                            "type": "string"
                          },
                          "client_id": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "client_name": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "expires_at": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "account.trial_ended": {
      "post": {
        "operationId": "onAccountTrialEnded",
        "summary": "The trial ended",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "data": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "account.subscribed": {
      "post": {
        "operationId": "onAccountSubscribed",
        "summary": "A paid subscription started or changed",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "data": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "account.downgraded": {
      "post": {
        "operationId": "onAccountDowngraded",
        "summary": "The account moved to a lower plan",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "data": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "account.payment_failed": {
      "post": {
        "operationId": "onAccountPaymentFailed",
        "summary": "A subscription payment failed",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "data": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "support.opened": {
      "post": {
        "operationId": "onSupportOpened",
        "summary": "A support request was opened",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "data": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    },
    "webhook.test": {
      "post": {
        "operationId": "onWebhookTest",
        "summary": "Test event from POST /webhooks/test",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookId"
          },
          {
            "$ref": "#/components/parameters/WebhookTimestamp"
          },
          {
            "$ref": "#/components/parameters/WebhookSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetSignature"
          },
          {
            "$ref": "#/components/parameters/SmsnetTimestamp"
          },
          {
            "$ref": "#/components/parameters/SmsnetEvent"
          },
          {
            "$ref": "#/components/parameters/SmsnetDelivery"
          },
          {
            "$ref": "#/components/parameters/SmsnetAttempt"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEnvelope"
                  },
                  {
                    "properties": {
                      "event": {
                        "const": "webhook.test"
                      },
                      "data": {
                        "type": "object",
                        "properties": {
                          "message": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged. Any 2xx counts."
          },
          "410": {
            "description": "Gone. Stops retries for this delivery."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Account API key (`smsnet_...`, `sn_live_...` or `sn_test_...`)."
      },
      "BearerKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "The same API key as a Bearer token. Used by the MCP endpoint."
      }
    },
    "parameters": {
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "1–255 characters, unique per logical operation. Kept 24h per account.",
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        }
      },
      "WebhookId": {
        "name": "webhook-id",
        "in": "header",
        "required": true,
        "description": "Standard Webhooks message id (equals the envelope `id`). Stable across retries; dedupe on it.",
        "schema": {
          "type": "string",
          "examples": [
            "wh_8f2a1c"
          ]
        }
      },
      "WebhookTimestamp": {
        "name": "webhook-timestamp",
        "in": "header",
        "required": true,
        "description": "Unix seconds when this attempt was signed. Reject if more than 300s from now.",
        "schema": {
          "type": "string",
          "examples": [
            "1760000000"
          ]
        }
      },
      "WebhookSignature": {
        "name": "webhook-signature",
        "in": "header",
        "required": true,
        "description": "Space-separated list of `v1,<base64(HMAC-SHA256(key, msg = webhook-id + \".\" + webhook-timestamp + \".\" + rawBody))>`. key = base64-decoded bytes after `whsec_` for endpoint secrets, or the raw UTF-8 bytes of a legacy 64-hex secret. Two signatures appear for 24h after a rotation; accept if any matches.",
        "schema": {
          "type": "string"
        }
      },
      "SmsnetSignature": {
        "name": "X-SMSNET-Signature",
        "in": "header",
        "required": true,
        "description": "Legacy scheme: `v1=<hex(HMAC-SHA256(key = UTF-8 bytes of the whole secret string, including any `whsec_` prefix, X-SMSNET-Timestamp + \".\" + rawBody))>`, current secret only. Prefer webhook-signature.",
        "schema": {
          "type": "string"
        }
      },
      "SmsnetTimestamp": {
        "name": "X-SMSNET-Timestamp",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "SmsnetEvent": {
        "name": "X-SMSNET-Event",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "SmsnetDelivery": {
        "name": "X-SMSNET-Delivery",
        "in": "header",
        "required": true,
        "description": "Delivery id, stable across retries (same as webhook-id).",
        "schema": {
          "type": "string"
        }
      },
      "SmsnetAttempt": {
        "name": "X-SMSNET-Attempt",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        }
      }
    },
    "headers": {
      "IdempotentReplayed": {
        "description": "Present with value `true` when the response is a stored replay.",
        "schema": {
          "type": "string",
          "enum": [
            "true"
          ]
        }
      }
    },
    "responses": {
      "Ok": {
        "description": "Done.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "ok": {
                  "type": "boolean",
                  "const": true
                }
              }
            }
          }
        }
      },
      "OkWithId": {
        "description": "Created.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "ok": {
                  "type": "boolean"
                },
                "id": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "BadRequest": {
        "description": "Invalid input: `send_at_too_far`, `invalid_send_at`, `invalid_expires_at`, `invalid_route_mode` (also route_mode without sim_id), `invalid_client_ref`, `body_too_long` (over 1600), `invalid_to`, `no_device`, ...",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid API key. The message says which (replaced key, wrong prefix, unknown).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Opted-out recipient (`code:opted_out`), suspended account, `insufficient_scope`, `agent_key_mcp_only` or `session_required`.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Not found (for example `sim_not_found`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Conflict": {
        "description": "`idempotency_in_flight` (the first request with this key has not finished), `too_many_keys`, or `endpoint_limit`.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unprocessable": {
        "description": "`idempotency_mismatch`: the key was used with a different body.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Plan limit (`code:quota_exceeded`), first-week ceiling (`code:abuse_ceiling`), or `otp_rate_limited`.",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "description": "The error envelope. Every 4xx/5xx JSON answer under `/api` (and `/mcp`, outside JSON-RPC\nerror bodies) carries these four fields. Branch on `code`, show `message`, link `docs_url`.\nThe catalogue of codes is at https://smsnet.net/docs/errors.\n",
        "required": [
          "error",
          "code",
          "message",
          "docs_url"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "The value this field had before the envelope existed (a snake code on newer refusals, a human sentence on older ones). Kept for backward compatibility; prefer `code`.",
            "examples": [
              "insufficient_scope",
              "to and body are required"
            ]
          },
          "code": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$",
            "description": "Stable machine code (snake_case). Every value is documented at `docs_url`.",
            "examples": [
              "insufficient_scope",
              "opted_out",
              "quota_exceeded",
              "invalid_phone",
              "endpoint_limit",
              "rate_limited"
            ]
          },
          "message": {
            "type": "string",
            "description": "A human sentence you can show to a person.",
            "examples": [
              "The API key lacks the scope this route needs."
            ]
          },
          "docs_url": {
            "type": "string",
            "format": "uri",
            "description": "`https://smsnet.net/docs/errors#<code>`: what the code means and how to fix it.",
            "examples": [
              "https://smsnet.net/docs/errors#insufficient_scope"
            ]
          },
          "required": {
            "type": "string",
            "description": "On `insufficient_scope`, the scope that was missing.",
            "enum": [
              "send",
              "read",
              "manage"
            ]
          },
          "retry_after_s": {
            "type": "integer",
            "description": "On some 429s, seconds to wait before retrying."
          }
        },
        "additionalProperties": true
      },
      "MessageErrorCode": {
        "type": "string",
        "description": "Why a message failed on the phone, as reported by the gateway app. Sent as `error_code` on the\n`message.status` webhook and as the prefix of the message's `error_message` (`THROTTLED: ...`).\n`THROTTLED`: the carrier refused to send more right now (rate limit or premium-SMS guard). The\nline rests for 60 minutes and the message moves once to another line unless `route_mode` is\n`strict`; only a message that cannot move ends `failed` with this code.\n`OUTCOME_UNKNOWN`: the phone could not tell whether the SMS left (status `unknown`); it is not\nresent automatically. Other values are passed through from the phone.\n",
        "examples": [
          "THROTTLED",
          "OUTCOME_UNKNOWN"
        ]
      },
      "Health": {
        "type": "object",
        "required": [
          "ok"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "db": {
            "type": "string",
            "enum": [
              "up",
              "down"
            ]
          },
          "dispatch_age_seconds": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Seconds since the dispatcher last ran."
          },
          "degraded": {
            "type": "string",
            "enum": [
              "dispatch_stale"
            ],
            "description": "Present when ok is false because the dispatcher has not run for over 5 minutes."
          }
        }
      },
      "Timestamp": {
        "description": "ISO-8601 string or epoch milliseconds.",
        "oneOf": [
          {
            "type": "string",
            "format": "date-time"
          },
          {
            "type": "integer"
          }
        ]
      },
      "MessageStatus": {
        "type": "string",
        "enum": [
          "pending",
          "ready",
          "sent",
          "delivered",
          "failed",
          "expired",
          "received"
        ]
      },
      "Encoding": {
        "type": "string",
        "enum": [
          "GSM-7",
          "UCS-2"
        ]
      },
      "SendMessageRequest": {
        "type": "object",
        "required": [
          "to",
          "body"
        ],
        "properties": {
          "to": {
            "type": "string",
            "description": "Recipient in E.164",
            "examples": [
              "+972501234567"
            ]
          },
          "body": {
            "type": "string",
            "maxLength": 1600
          },
          "send_at": {
            "$ref": "#/components/schemas/Timestamp",
            "description": "Schedule. Max 20 days ahead (400 `send_at_too_far`). Alias of `scheduled_at`; `send_at` wins."
          },
          "scheduled_at": {
            "$ref": "#/components/schemas/Timestamp",
            "description": "Legacy name for `send_at`."
          },
          "expires_at": {
            "$ref": "#/components/schemas/Timestamp",
            "description": "Give up after this time. Must be in the future and after `send_at`."
          },
          "expires_in_hours": {
            "type": "number",
            "minimum": 1,
            "maximum": 336,
            "description": "Alternative to `expires_at`. Default is the account TTL, else 24h."
          },
          "sim_id": {
            "type": "string",
            "description": "Pin to one of your lines. 404 `sim_not_found` if it is not yours."
          },
          "route_mode": {
            "type": "string",
            "enum": [
              "prefer",
              "strict"
            ],
            "description": "`prefer` (default when sim_id is given) uses the pinned line if eligible, else normal routing. `strict` only that line; waits or expires, never fails over."
          },
          "client_ref": {
            "type": "string",
            "maxLength": 128,
            "description": "Your reference. Echoed on every message object and every message.* webhook."
          },
          "fallback": {
            "type": "boolean",
            "default": false,
            "description": "Allow sending via the account's own Twilio if no line can release it within 10 minutes. Ignored for strict routing."
          },
          "transactional": {
            "type": "boolean",
            "default": false,
            "description": "Only for a message the recipient is waiting on right now (a code, a receipt). Skips pacing and quiet hours; never for lists or reminders. Ignored when scheduled."
          },
          "device_id": {
            "type": "string",
            "description": "Send from a specific phone."
          },
          "override_optout": {
            "type": "boolean",
            "description": "Send to an opted-out contact. Only for legally required notices."
          },
          "unsubscribe": {
            "type": "boolean",
            "default": false,
            "description": "Add a personal opt-out link, or place it with `{{unsubscribe}}` in the body. Pressing it opts the recipient out of your account. It helps you offer an opt-out; it does not make a message compliant, and opt-outs received any other way remain yours to record. Without the placeholder the link goes on its own line at the end. The link counts toward the 1600 characters. Applied automatically to non-transactional API and MCP sends when the account setting `auto_optout_link` is on."
          }
        }
      },
      "SendMessageResponse": {
        "type": "object",
        "required": [
          "ok",
          "message_id"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "id": {
            "type": "string",
            "description": "Same as message_id."
          },
          "message_id": {
            "type": "string",
            "examples": [
              "msg_9d2c"
            ]
          },
          "conversation_id": {
            "type": "string"
          },
          "device_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "to": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/MessageStatus",
            "description": "Only for transactional sends and replies."
          },
          "transactional": {
            "type": "boolean",
            "description": "Only present (true) for a transactional send."
          },
          "route_mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "prefer",
              "strict",
              null
            ]
          },
          "fallback": {
            "type": "boolean"
          },
          "segments": {
            "type": "integer",
            "description": "SMS parts. GSM-7: 160 single / 153 per part (extension chars count 2). UCS-2: 70 / 67 (UTF-16 units)."
          },
          "encoding": {
            "$ref": "#/components/schemas/Encoding"
          },
          "client_ref": {
            "type": [
              "string",
              "null"
            ]
          },
          "sim_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Present when the message is pinned or already released to a line."
          },
          "send_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Epoch ms."
          },
          "expires_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Epoch ms."
          },
          "sandbox": {
            "type": "boolean"
          },
          "optout_link": {
            "type": "boolean",
            "description": "Present (true) when the body went out with the recipient's opt-out link."
          },
          "quota": {
            "type": "object",
            "properties": {
              "month": {
                "$ref": "#/components/schemas/QuotaCounter"
              },
              "day": {
                "$ref": "#/components/schemas/QuotaCounter"
              },
              "grace": {
                "type": "boolean"
              },
              "note": {
                "type": "string"
              }
            }
          }
        },
        "additionalProperties": true
      },
      "QuotaCounter": {
        "type": "object",
        "properties": {
          "used": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          }
        }
      },
      "ReplyRequest": {
        "type": "object",
        "required": [
          "body"
        ],
        "properties": {
          "body": {
            "type": "string",
            "maxLength": 1600
          },
          "client_ref": {
            "type": "string",
            "maxLength": 128
          },
          "sim_id": {
            "type": "string"
          },
          "route_mode": {
            "type": "string",
            "enum": [
              "prefer",
              "strict"
            ]
          },
          "device_id": {
            "type": "string"
          },
          "send_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "expires_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "unsubscribe": {
            "type": "boolean",
            "description": "As in `/messages/send`: add the opt-out link at the end, or use `{{unsubscribe}}` in `body`."
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "id",
          "direction",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "conversation_id": {
            "type": "string"
          },
          "campaign_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "direction": {
            "type": "string",
            "enum": [
              "inbound",
              "outbound"
            ]
          },
          "from_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "to_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "body": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/MessageStatus"
          },
          "sim_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "client_ref": {
            "type": [
              "string",
              "null"
            ]
          },
          "segments": {
            "type": [
              "integer",
              "null"
            ]
          },
          "encoding": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Encoding"
              },
              {
                "type": "null"
              }
            ]
          },
          "via": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "fallback",
              "sandbox",
              null
            ],
            "description": "null = sent by a phone; `fallback` = via the hybrid fallback; `sandbox` = simulated."
          },
          "sandbox": {
            "type": "boolean"
          },
          "fallback": {
            "type": "boolean"
          },
          "channel": {
            "type": "string",
            "enum": [
              "sms",
              "rcs"
            ],
            "description": "`rcs` for an inbound reply the phone read from a Google Messages chat (RCS) notification; `sms` otherwise, and for every outbound message."
          },
          "route_mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "prefer",
              "strict",
              null
            ]
          },
          "pinned_sim_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "send_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Epoch ms (the stored scheduled_at)."
          },
          "error_message": {
            "type": [
              "string",
              "null"
            ],
            "description": "Failure text. Starts with a code when the phone reported one, for example `THROTTLED: carrier limit` (see `MessageErrorCode`)."
          },
          "scheduled_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "expires_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "sent_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "delivered_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "created_at": {
            "type": "integer",
            "description": "Epoch ms."
          }
        },
        "additionalProperties": true
      },
      "MessagePage": {
        "type": "object",
        "required": [
          "messages",
          "next_cursor",
          "has_more"
        ],
        "properties": {
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "description": "Pass back as `since`."
          },
          "has_more": {
            "type": "boolean"
          }
        }
      },
      "Conversation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "closed"
            ]
          },
          "unread_count": {
            "type": "integer"
          },
          "last_message_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "contact_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "contact_phone": {
            "type": "string"
          },
          "last_body": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Contact": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "tags": {
            "type": "string",
            "description": "JSON-encoded array of strings."
          },
          "opt_in": {
            "type": "integer"
          },
          "opt_out": {
            "type": "integer"
          },
          "opt_out_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "opt_out_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "integer"
          }
        },
        "additionalProperties": true
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "CreateCampaignRequest": {
        "type": "object",
        "required": [
          "consent_confirmed"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "template_id": {
            "type": "string"
          },
          "recipients": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "object",
                  "properties": {
                    "phone": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  }
                }
              ]
            }
          },
          "tag": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "device_id": {
            "type": "string"
          },
          "rate_per_minute": {
            "type": "integer"
          },
          "send_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "scheduled_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "consent_confirmed": {
            "type": "boolean",
            "const": true
          },
          "unsubscribe_link": {
            "type": "boolean",
            "description": "Add a personal opt-out link on a line of its own, in the language of the message. `{{unsubscribe}}` in the body places it instead, and turns it on."
          },
          "name_fallback": {
            "type": "string",
            "maxLength": 40,
            "description": "Used for `{{name}}` when the recipient has no name. `{{name|text}}` in the body wins over this. With neither, the variable is dropped."
          }
        }
      },
      "ConsentInput": {
        "type": "object",
        "required": [
          "phone",
          "source"
        ],
        "properties": {
          "phone": {
            "type": "string"
          },
          "channel": {
            "type": "string",
            "enum": [
              "sms",
              "email",
              "whatsapp",
              "voice"
            ],
            "default": "sms"
          },
          "action": {
            "type": "string",
            "enum": [
              "granted",
              "withdrawn"
            ],
            "default": "granted"
          },
          "source": {
            "type": "string",
            "maxLength": 120
          },
          "method": {
            "type": "string",
            "enum": [
              "web_form",
              "checkbox",
              "paper",
              "verbal",
              "sms_keyword",
              "import",
              "api",
              "other"
            ],
            "default": "api"
          },
          "given_at": {
            "type": [
              "string",
              "integer"
            ],
            "description": "When the person agreed: ISO 8601, milliseconds, or dd/mm/yyyy. Not in the future."
          },
          "evidence": {
            "type": "string",
            "maxLength": 2000,
            "description": "The wording shown, or a reference. Stored encrypted."
          }
        }
      },
      "ConversationNote": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "user_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "author_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "body": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "TeamMember": {
        "type": "object",
        "properties": {
          "user_id": {
            "type": "string"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "owner",
              "admin",
              "agent"
            ]
          },
          "all_lines": {
            "type": "boolean"
          },
          "line_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "AccessEnded": {
        "type": "object",
        "description": "What ended with someone's access. A secret already seen cannot be taken back, so what they may have seen is listed.",
        "properties": {
          "keys_revoked": {
            "type": "integer",
            "description": "Keys and client tokens they made or approved. None of these refresh again."
          },
          "invites_revoked": {
            "type": "integer"
          },
          "push_subscriptions_removed": {
            "type": "integer"
          },
          "inbound_hooks_to_rotate": {
            "type": "array",
            "description": "Hooks whose secret URL was issued while this admin was on the account.",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              }
            }
          },
          "webhooks_to_review": {
            "type": "integer",
            "description": "Webhook endpoints on the account. A signing secret is shown to whoever sets or rotates it."
          },
          "note": {
            "type": "string"
          }
        }
      },
      "InboundHookInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 80
          },
          "phone_field": {
            "type": "string",
            "maxLength": 120,
            "description": "Dotted path to the phone number in the payload."
          },
          "template": {
            "type": "string",
            "maxLength": 480,
            "description": "Text with {{dotted.path}} placeholders."
          },
          "sim_id": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "InboundHook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "phone_field": {
            "type": "string"
          },
          "template": {
            "type": "string"
          },
          "sim_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "enabled": {
            "type": "boolean"
          },
          "token_prefix": {
            "type": "string"
          },
          "sent_count": {
            "type": "integer"
          },
          "last_used_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "last_result": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "InboundHookIssued": {
        "type": "object",
        "properties": {
          "hook": {
            "$ref": "#/components/schemas/InboundHook"
          },
          "url": {
            "type": "string"
          },
          "token": {
            "type": "string"
          }
        }
      },
      "ConsentRecord": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "contact_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "channel": {
            "type": "string"
          },
          "action": {
            "type": "string",
            "enum": [
              "granted",
              "withdrawn"
            ]
          },
          "source": {
            "type": "string"
          },
          "method": {
            "type": [
              "string",
              "null"
            ]
          },
          "given_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "evidence": {
            "type": [
              "string",
              "null"
            ]
          },
          "recorded_by": {
            "type": "string"
          },
          "recorded_via": {
            "type": "string",
            "enum": [
              "portal",
              "api",
              "import",
              "opt_out"
            ]
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          }
        },
        "additionalProperties": true
      },
      "Device": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "nickname": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "online",
              "offline"
            ]
          },
          "battery_level": {
            "type": [
              "integer",
              "null"
            ]
          },
          "network_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_ping_at": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "LineState": {
        "type": "string",
        "enum": [
          "healthy",
          "watch",
          "resting",
          "blocked"
        ]
      },
      "LineHealth": {
        "type": "object",
        "required": [
          "sim_id",
          "score",
          "state"
        ],
        "description": "watch if failure_rate_24h >= 0.10 or optout_rate_7d >= 0.02 (min 20 sent);\nresting for 6h if failure_rate_24h >= 0.25 or optout_rate_7d >= 0.05 (min 20 sent);\nblocked = quarantine/blocked flags. Resting lines are skipped and their pending\nnon-strict messages re-route to another eligible line of the account.\n",
        "properties": {
          "sim_id": {
            "type": "string"
          },
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "state": {
            "$ref": "#/components/schemas/LineState"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "resting_until": {
            "type": [
              "integer",
              "null"
            ]
          },
          "warmup": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "level": {
                "type": "integer"
              },
              "cap": {
                "type": "integer"
              },
              "next_cap": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "sent_today": {
            "type": "integer"
          },
          "headroom_today": {
            "type": "integer"
          },
          "signals": {
            "type": "object",
            "properties": {
              "failure_rate_24h": {
                "type": "number"
              },
              "optout_rate_7d": {
                "type": "number"
              },
              "reply_rate_7d": {
                "type": "number"
              },
              "sent_24h": {
                "type": "integer"
              },
              "sent_7d": {
                "type": "integer"
              }
            }
          },
          "rcs": {
            "$ref": "#/components/schemas/RcsState"
          }
        }
      },
      "RcsState": {
        "type": "object",
        "description": "Are replies to this line probably going to RCS, where SMSNET cannot see them?\nIn Gateway only mode Google Messages stays the default SMS app; with RCS chats on,\na reply (STOP included) goes over RCS and never reaches the SMS inbox. The SMSNET\napp can read Google Messages notifications to catch them (`capture: on`).\n`likely`: gateway mode, capture not on, 20 or more sent in 7 days and no replies.\n`strong`: capture not on and the phone saw Google Messages chat notifications in\nthe last 24 hours; or capture was on and is now `no_access` or `disconnected`\n(`capture_lost`); or Google Messages notifications are off on the phone\n(`notif_health: messages_notifications_off`). Advisory only: it never changes\n`state`. GET /api/v1/alerts carries the same verdict as `rcs_replies:<sim_id>`.\nWhen a line enters `strong`, the account owner is emailed once (at most once per\nline per 3 days, and again only after it was fixed and broke again).\nThis check is an estimate and can be wrong; you remain responsible for honoring\nopt-outs received in any channel.\n",
        "properties": {
          "mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "gateway",
              "messages",
              null
            ],
            "description": "As the phone last reported it. null = an app build that does not report it."
          },
          "capture": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "on",
              "off",
              "no_access",
              "disconnected",
              null
            ],
            "description": "RCS reply capture on the phone. `no_access` = notification access not granted; `disconnected` = access granted but Android unbound the listener."
          },
          "seen_24h": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Google Messages chat notifications the phone saw in the last 24 hours."
          },
          "notif_health": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "ok",
              "messages_notifications_off",
              "unknown",
              null
            ],
            "description": "Are Google Messages notifications on? null = not reported."
          },
          "last_capture_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "The last RCS reply captured (a filed reply or an in-app test), epoch ms."
          },
          "last_test_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "The last in-app self-test (Capture RCS replies > Test) that reached SMSNET, epoch ms."
          },
          "last_test_matched": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether that test came with the sender's number (true) or a name only (false). null = no test yet."
          },
          "capture_lost": {
            "type": "boolean",
            "description": "Capture was reported on at some point and is not on now."
          },
          "risk": {
            "type": "string",
            "enum": [
              "none",
              "likely",
              "strong"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "A plain sentence saying what is wrong and how to fix it."
          },
          "auto_optout_link": {
            "type": "boolean",
            "description": "The account setting \"Add an opt-out link to automated messages\"."
          },
          "recommend_optout_link": {
            "type": "boolean",
            "description": "`risk` is not none and `auto_optout_link` is off."
          },
          "guide": {
            "type": "string",
            "examples": [
              "/guides/rcs-replies"
            ]
          }
        }
      },
      "WorkingHours": {
        "type": [
          "object",
          "null"
        ],
        "required": [
          "start",
          "end"
        ],
        "properties": {
          "start": {
            "type": "string",
            "pattern": "^\\d{2}:\\d{2}$",
            "examples": [
              "09:00"
            ]
          },
          "end": {
            "type": "string",
            "pattern": "^\\d{2}:\\d{2}$",
            "examples": [
              "20:00"
            ]
          },
          "days": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
            },
            "description": "0 = Sunday."
          },
          "tz": {
            "type": "string",
            "examples": [
              "Asia/Jerusalem"
            ]
          }
        }
      },
      "SimControls": {
        "type": "object",
        "properties": {
          "max_per_minute": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 30
          },
          "max_per_hour": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 600
          },
          "jitter_min_s": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 600
          },
          "jitter_max_s": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 600
          },
          "working_hours": {
            "$ref": "#/components/schemas/WorkingHours"
          }
        }
      },
      "SimSafetyRequest": {
        "allOf": [
          {
            "$ref": "#/components/schemas/SimControls"
          },
          {
            "type": "object",
            "properties": {
              "trust_level": {
                "type": "string",
                "enum": [
                  "test",
                  "new",
                  "seasoned",
                  "established"
                ]
              },
              "send_profile": {
                "type": "string",
                "enum": [
                  "cautious",
                  "balanced",
                  "fast"
                ]
              },
              "daily_send_limit": {
                "type": "integer",
                "minimum": 1,
                "maximum": 2000
              }
            }
          }
        ]
      },
      "Sim": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "device_id": {
            "type": "string"
          },
          "device_nickname": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "carrier": {
            "type": [
              "string",
              "null"
            ]
          },
          "slot": {
            "type": "integer"
          },
          "status": {
            "type": "string"
          },
          "enabled": {
            "type": [
              "integer",
              "boolean"
            ]
          },
          "online": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "trust_level": {
            "type": "string"
          },
          "send_profile": {
            "type": "string"
          },
          "daily_send_limit": {
            "type": "integer"
          },
          "daily_sent_count": {
            "type": "integer"
          },
          "effective_cap_today": {
            "type": "integer"
          },
          "remaining_today": {
            "type": "integer"
          },
          "warmup_day": {
            "type": [
              "integer",
              "null"
            ]
          },
          "warmup_days_total": {
            "type": "integer"
          },
          "blocked_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "next_send_in_seconds": {
            "type": "integer"
          },
          "health": {
            "$ref": "#/components/schemas/LineHealth"
          },
          "controls": {
            "$ref": "#/components/schemas/SimControls"
          },
          "line_type": {
            "type": "string",
            "enum": [
              "prepaid",
              "postpaid",
              "business",
              "unknown"
            ]
          },
          "line": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "prepaid",
                  "postpaid",
                  "business",
                  "unknown"
                ]
              },
              "israeli": {
                "type": "boolean"
              },
              "carrier_daily_cap": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Enforced. Israeli prepaid lines, counted in message parts."
              },
              "recommended_daily_limit": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "A recommendation only. Never enforced."
              },
              "note": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        },
        "additionalProperties": true
      },
      "OtpSendRequest": {
        "type": "object",
        "required": [
          "to"
        ],
        "properties": {
          "to": {
            "type": "string"
          },
          "length": {
            "type": "integer",
            "minimum": 4,
            "maximum": 8,
            "default": 6
          },
          "ttl_s": {
            "type": "integer",
            "minimum": 60,
            "maximum": 900,
            "default": 300
          },
          "template": {
            "type": "string",
            "default": "Your code is {code}",
            "description": "Must contain `{code}`."
          },
          "presets": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "sms_retriever",
                "webotp",
                "ios_domain"
              ]
            },
            "description": "Add the lines these formats read, under `template`. They combine into one message. With `sms_retriever` a message over 140 bytes is refused (Hebrew: about 70 characters)."
          },
          "app_hash": {
            "type": "string",
            "description": "The 11-character Android app hash. Required by `sms_retriever`."
          },
          "domain": {
            "type": "string",
            "description": "Host name for the `@domain #code` line, no scheme or port. Required by `webotp` and `ios_domain`."
          },
          "sim_id": {
            "type": "string"
          },
          "client_ref": {
            "type": "string",
            "maxLength": 128
          }
        }
      },
      "OtpSendResponse": {
        "type": "object",
        "required": [
          "otp_id",
          "to",
          "expires_at",
          "message_id"
        ],
        "properties": {
          "otp_id": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "message_id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "queued",
              "released",
              "sent",
              "delivered",
              "undeliverable"
            ],
            "description": "Where the SMS is. `released`: handed to a line heard from in the last minute. `queued`: waiting for one."
          },
          "line_available": {
            "type": "boolean",
            "description": "False when no line can take a code right now. Without one soon the `otp.undeliverable` webhook fires. Absent with an `sn_test_` key."
          },
          "sandbox": {
            "type": "boolean",
            "description": "Present with an `sn_test_` key."
          },
          "code": {
            "type": "string",
            "description": "Only with an `sn_test_` key (nothing reaches a phone), so test flows can finish."
          }
        }
      },
      "OtpSettings": {
        "type": "object",
        "properties": {
          "allowed_countries": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "line_countries": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "paused_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "OtpVerifyRequest": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "otp_id": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        }
      },
      "OtpVerifyResponse": {
        "type": "object",
        "required": [
          "valid"
        ],
        "properties": {
          "valid": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "enum": [
              "expired",
              "mismatch",
              "too_many_attempts",
              "not_found"
            ]
          },
          "attempts_left": {
            "type": "integer",
            "description": "On `mismatch`."
          },
          "otp_id": {
            "type": "string",
            "description": "On a valid code."
          },
          "to": {
            "type": "string"
          },
          "client_ref": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Usage": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "days": {
            "type": "integer"
          },
          "sent": {
            "type": "integer"
          },
          "delivered": {
            "type": "integer"
          },
          "failed": {
            "type": "integer"
          },
          "queued": {
            "type": "integer"
          },
          "expired": {
            "type": "integer"
          },
          "outbound_total": {
            "type": "integer"
          },
          "replies": {
            "type": "integer"
          },
          "opt_outs": {
            "type": "integer"
          },
          "delivery_rate": {
            "type": "integer"
          },
          "reply_rate": {
            "type": "integer"
          },
          "series": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string"
                },
                "sent": {
                  "type": "integer"
                },
                "delivered": {
                  "type": "integer"
                },
                "failed": {
                  "type": "integer"
                },
                "queued": {
                  "type": "integer"
                },
                "replies": {
                  "type": "integer"
                }
              }
            }
          },
          "messages_sent": {
            "type": "integer"
          },
          "plan_limit": {
            "type": "integer"
          },
          "plan": {
            "type": "string"
          }
        }
      },
      "WebhookConfig": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "url": {
            "type": [
              "string",
              "null"
            ]
          },
          "secret": {
            "type": [
              "string",
              "null"
            ],
            "description": "64 hex characters. Used as raw UTF-8 for both signature schemes."
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEventType"
            }
          },
          "signature": {
            "type": "object",
            "additionalProperties": true,
            "description": "Legacy X-SMSNET-Signature scheme."
          },
          "standard_webhooks": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "headers": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "scheme": {
                "type": "string"
              },
              "secret_encoding": {
                "type": "string",
                "const": "utf8"
              },
              "tolerance_seconds": {
                "type": "integer"
              }
            }
          },
          "retry_schedule_seconds": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "examples": [
              [
                5,
                300,
                1800,
                7200,
                18000,
                36000,
                50400,
                72000,
                86400
              ]
            ]
          },
          "max_attempts": {
            "type": "integer",
            "examples": [
              10
            ]
          },
          "last_24h": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer"
              },
              "delivered": {
                "type": "integer"
              },
              "pending": {
                "type": "integer"
              },
              "failed": {
                "type": "integer"
              }
            }
          },
          "last_attempt": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          },
          "endpoints_count": {
            "type": "integer"
          },
          "endpoints_limit": {
            "type": "integer",
            "examples": [
              10
            ]
          }
        }
      },
      "WebhookDelivery": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "string"
          },
          "endpoint_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "url": {
            "type": "string"
          },
          "event": {
            "$ref": "#/components/schemas/WebhookEventType"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "delivered",
              "failed"
            ]
          },
          "attempts": {
            "type": "integer"
          },
          "response_code": {
            "type": [
              "integer",
              "null"
            ]
          },
          "last_error": {
            "type": [
              "string",
              "null"
            ]
          },
          "next_attempt_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "delivered_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "WebhookEndpoint": {
        "type": "object",
        "required": [
          "id",
          "url",
          "events",
          "enabled"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "description": "Event names, or `[\"*\"]` for all.",
            "items": {
              "type": "string"
            }
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "enabled": {
            "type": "boolean"
          },
          "disabled_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "auto_failures",
              "manual",
              null
            ],
            "description": "Why the endpoint is disabled. Re-enabling resets it and the failure streak."
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "description": "Informational: portal, api, n8n, zapier, make, mcp, legacy (free text, max 32)."
          },
          "created_at": {
            "type": "integer"
          },
          "updated_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "last_success_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "last_failure_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "consecutive_failures": {
            "type": "integer"
          },
          "secret_rotating_until": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Epoch ms while the previous secret still signs, else null."
          }
        }
      },
      "CreateWebhookEndpointRequest": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "default": [
              "*"
            ],
            "items": {
              "type": "string"
            }
          },
          "description": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "maxLength": 32
          }
        }
      },
      "UpdateWebhookEndpointRequest": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "enabled": {
            "type": "boolean"
          }
        }
      },
      "CreatedWebhookEndpoint": {
        "allOf": [
          {
            "$ref": "#/components/schemas/WebhookEndpoint"
          },
          {
            "type": "object",
            "required": [
              "secret"
            ],
            "properties": {
              "secret": {
                "type": "string",
                "description": "`whsec_<base64>`. Shown once."
              }
            }
          }
        ]
      },
      "WebhookEventType": {
        "type": "string",
        "enum": [
          "message.received",
          "message.status",
          "message.quarantined",
          "contact.opted_out",
          "contact.opted_in",
          "device.offline",
          "device.online",
          "device.power_lost",
          "sim.capacity",
          "line.health_changed",
          "mcp.client_pending",
          "mcp.client_trusted",
          "mcp.client_denied",
          "mcp.approval_requested",
          "account.trial_ended",
          "account.subscribed",
          "account.downgraded",
          "account.payment_failed",
          "support.opened",
          "webhook.test"
        ]
      },
      "WebhookEnvelope": {
        "type": "object",
        "required": [
          "id",
          "event",
          "type",
          "account_id",
          "data",
          "timestamp"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Same as the webhook-id header. Each endpoint gets its own id for the same event."
          },
          "event": {
            "$ref": "#/components/schemas/WebhookEventType"
          },
          "type": {
            "$ref": "#/components/schemas/WebhookEventType",
            "description": "Same as `event` (Standard Webhooks naming)."
          },
          "account_id": {
            "type": "string",
            "description": "Route on this when one endpoint serves several accounts."
          },
          "data": {
            "type": "object",
            "additionalProperties": true
          },
          "timestamp": {
            "type": "integer",
            "description": "Epoch ms when the event was created."
          }
        }
      },
      "SupportRequest": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "topic": {
            "type": [
              "string",
              "null"
            ]
          },
          "subject": {
            "type": [
              "string",
              "null"
            ]
          },
          "body": {
            "type": [
              "string",
              "null"
            ],
            "description": "Only on GET /support/{id}."
          },
          "status": {
            "type": "string",
            "description": "open, answered or closed."
          },
          "stage": {
            "type": "string",
            "enum": [
              "new",
              "investigating",
              "waiting_on_customer",
              "resolved"
            ]
          },
          "created_at": {
            "type": "integer"
          },
          "answered_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "first_response_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "customer_replied_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "last_reply_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Latest reply from support. List only."
          },
          "reply_count": {
            "type": "integer",
            "description": "Replies in the thread, both sides. List only."
          }
        },
        "additionalProperties": true
      },
      "SupportNote": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "from": {
            "type": "string",
            "enum": [
              "support",
              "customer"
            ]
          },
          "author": {
            "type": "string",
            "description": "\"SMSNET Support\" or \"You\"."
          },
          "body": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "MessageReceivedData": {
        "type": "object",
        "properties": {
          "message_id": {
            "type": "string"
          },
          "from": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "conversation_id": {
            "type": "string"
          },
          "sim_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "received_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "The time the phone says it arrived (epoch ms)",
            "when it reported one.": null
          },
          "channel": {
            "type": "string",
            "enum": [
              "sms",
              "rcs"
            ],
            "description": "`rcs` when the phone read the reply from a Google Messages chat notification. Absent (treat as `sms`) on a released quarantined message."
          },
          "was_quarantined": {
            "type": "boolean"
          },
          "quarantine_id": {
            "type": "string"
          }
        },
        "additionalProperties": true
      },
      "MessageStatusData": {
        "type": "object",
        "required": [
          "message_id",
          "status"
        ],
        "properties": {
          "message_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "sent",
              "delivered",
              "failed",
              "expired",
              "unknown"
            ]
          },
          "to_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "error": {
            "type": "string",
            "description": "On failed or unknown: the failure text (for a throttle it starts with `THROTTLED`)."
          },
          "error_code": {
            "$ref": "#/components/schemas/MessageErrorCode"
          },
          "campaign_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "client_ref": {
            "type": [
              "string",
              "null"
            ]
          },
          "sim_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "via": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "fallback",
              "sandbox",
              null
            ]
          },
          "sandbox": {
            "type": "boolean"
          }
        },
        "additionalProperties": true
      },
      "ContactSuppressionData": {
        "type": "object",
        "properties": {
          "phone": {
            "type": "string"
          },
          "rule": {
            "type": "string",
            "description": "The matched keyword or the reason."
          },
          "source": {
            "type": "string",
            "enum": [
              "sms",
              "portal",
              "api",
              "import",
              "mcp"
            ]
          },
          "at": {
            "type": "integer"
          }
        }
      },
      "DevicePowerData": {
        "type": "object",
        "properties": {
          "device_id": {
            "type": "string"
          },
          "nickname": {
            "type": [
              "string",
              "null"
            ]
          },
          "battery_pct": {
            "type": [
              "integer",
              "null"
            ]
          },
          "charging": {
            "type": [
              "boolean",
              "null"
            ]
          }
        }
      },
      "McpClientData": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "client_id": {
            "type": "string"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "fingerprint_short": {
            "type": "string"
          }
        }
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "`legacy` for the original account key."
          },
          "name": {
            "type": "string"
          },
          "prefix": {
            "type": "string",
            "examples": [
              "sn_live_a1b2"
            ]
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "send",
                "read",
                "manage"
              ]
            }
          },
          "mode": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ]
          },
          "agent": {
            "type": "boolean"
          },
          "recipient_approval": {
            "type": "boolean",
            "description": "First message to a new number waits for one-click human approval (MCP)."
          },
          "created_at": {
            "type": "integer"
          },
          "last_used_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "revoked_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "legacy": {
            "type": "boolean"
          }
        }
      },
      "CreateKeyRequest": {
        "type": "object",
        "required": [
          "name",
          "scopes"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "enum": [
                "send",
                "read",
                "manage"
              ]
            }
          },
          "mode": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ],
            "default": "live"
          },
          "agent": {
            "type": "boolean",
            "default": false,
            "description": "MCP-only key."
          },
          "recipient_approval": {
            "type": "boolean",
            "description": "Defaults to the value of `agent`."
          }
        }
      },
      "CreatedApiKey": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiKey"
          },
          {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string",
                "description": "The full key. Shown once."
              },
              "note": {
                "type": "string"
              }
            }
          }
        ]
      },
      "FallbackConfig": {
        "type": "object",
        "required": [
          "provider",
          "account_sid",
          "auth_token",
          "from"
        ],
        "properties": {
          "provider": {
            "type": "string",
            "const": "twilio"
          },
          "account_sid": {
            "type": "string"
          },
          "auth_token": {
            "type": "string"
          },
          "from": {
            "type": "string",
            "description": "E.164 number or a Messaging Service SID (MG…)."
          }
        }
      },
      "FallbackConfigMasked": {
        "type": "object",
        "properties": {
          "provider": {
            "type": "string",
            "const": "twilio"
          },
          "account_sid": {
            "type": "string",
            "description": "Masked, e.g. AC…1234."
          },
          "from": {
            "type": "string"
          },
          "auth_token_set": {
            "type": "boolean"
          },
          "updated_at": {
            "type": [
              "integer",
              "string",
              "null"
            ]
          }
        }
      },
      "ComponentState": {
        "type": "string",
        "enum": [
          "operational",
          "degraded",
          "outage"
        ]
      },
      "PublicStatus": {
        "type": "object",
        "required": [
          "status",
          "components",
          "updated_at"
        ],
        "properties": {
          "status": {
            "$ref": "#/components/schemas/ComponentState"
          },
          "components": {
            "type": "object",
            "properties": {
              "api": {
                "$ref": "#/components/schemas/ComponentState"
              },
              "dispatcher": {
                "type": "object",
                "properties": {
                  "status": {
                    "$ref": "#/components/schemas/ComponentState"
                  },
                  "last_tick_at": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  }
                }
              },
              "webhooks": {
                "type": "object",
                "properties": {
                  "status": {
                    "$ref": "#/components/schemas/ComponentState"
                  },
                  "backlog": {
                    "type": "integer"
                  }
                }
              },
              "lines": {
                "type": "object",
                "properties": {
                  "online": {
                    "type": "integer"
                  },
                  "total": {
                    "type": "integer"
                  }
                }
              }
            }
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CarrierLimits": {
        "type": "object",
        "required": [
          "carriers"
        ],
        "properties": {
          "updated_at": {
            "type": [
              "integer",
              "string"
            ]
          },
          "carriers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "carrier": {
                  "type": "string"
                },
                "country": {
                  "type": "string",
                  "description": "ISO 3166 alpha-2 from the calling code (fallback +<cc>)."
                },
                "lines": {
                  "type": "integer"
                },
                "p50_daily_sent": {
                  "type": "number"
                },
                "p90_daily_sent": {
                  "type": "number"
                },
                "failure_rate": {
                  "type": "number"
                },
                "sample_days": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    }
  }
}
