{
  "openapi": "3.1.0",
  "info": {
    "title": "ChatRail API",
    "version": "1.0.0",
    "description": "Send, schedule and receive WhatsApp messages through a linked-device session.\n\n**Two things the API is careful about, which shape every endpoint below.**\n\n*Accepted is not delivered.* A 202 means the message is durably stored and queued. Only the `status` field ever claims WhatsApp delivered anything, and `queued`, `submitted`, `sent`, `delivered` and `read` are deliberately distinct.\n\n*A retry must not send twice.* Send `Idempotency-Key` on every send. A replay returns the original response; a concurrent duplicate is told to retry rather than allowed to race.",
    "contact": {
      "name": "ChatRail",
      "url": "https://www.chatrail.dev"
    }
  },
  "servers": [
    {
      "url": "https://www.chatrail.dev"
    }
  ],
  "tags": [
    {
      "name": "Messages",
      "description": "Sending, delivery state and export."
    },
    {
      "name": "Connections",
      "description": "WhatsApp numbers and their pairing lifecycle."
    },
    {
      "name": "Groups",
      "description": "Creating and running WhatsApp groups from a connected number."
    },
    {
      "name": "Schedules",
      "description": "Recurring sends."
    },
    {
      "name": "Facts",
      "description": "What the AI may tell customers about the business: the owner’s own page of hours, prices and policies."
    },
    {
      "name": "Webhooks",
      "description": "Where inbound events and delivery updates are sent."
    },
    {
      "name": "Opt-outs",
      "description": "People who asked not to be messaged. Sends to them are refused."
    },
    {
      "name": "AI",
      "description": "Optional, per connection, off by default."
    },
    {
      "name": "Team",
      "description": "Membership and invitations. Dashboard sessions only."
    },
    {
      "name": "Workspace",
      "description": "Identity, credentials, plan and usage."
    },
    {
      "name": "Billing",
      "description": "Checkout and the customer portal."
    },
    {
      "name": "Auth",
      "description": "Dashboard sign-in. Not used by API clients."
    },
    {
      "name": "MCP",
      "description": "Workspace tools for a coding assistant."
    },
    {
      "name": "Operational",
      "description": "Health and metrics."
    }
  ],
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "request_id",
              "details"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "VALIDATION_FAILED",
                  "INVALID_JSON",
                  "PAYLOAD_TOO_LARGE",
                  "UNSUPPORTED_MEDIA_TYPE",
                  "UNAUTHENTICATED",
                  "INVALID_CREDENTIAL",
                  "CREDENTIAL_EXPIRED",
                  "CREDENTIAL_REVOKED",
                  "INSUFFICIENT_SCOPE",
                  "FORBIDDEN",
                  "NOT_FOUND",
                  "ALREADY_EXISTS",
                  "IDEMPOTENCY_KEY_REUSED",
                  "CONFLICT",
                  "CONNECTION_NOT_READY",
                  "CONNECTION_REQUIRES_REPAIR",
                  "INVALID_STATE_TRANSITION",
                  "FEATURE_UNAVAILABLE",
                  "RECIPIENT_OPTED_OUT",
                  "PLAN_UPGRADE_REQUIRED",
                  "QUOTA_EXCEEDED",
                  "PLAN_LIMIT_REACHED",
                  "RATE_LIMITED",
                  "WORKSPACE_SUSPENDED",
                  "INTERNAL_ERROR",
                  "SERVICE_UNAVAILABLE",
                  "PROVIDER_UNAVAILABLE",
                  "DEPENDENCY_TIMEOUT"
                ],
                "description": "Stable. Branch on this, not on `message`. Renaming a code is a breaking change."
              },
              "message": {
                "type": "string",
                "description": "Written for a developer reading it. The wording may change."
              },
              "request_id": {
                "type": "string",
                "description": "Quote this to support. It is also returned in the `x-request-id` header."
              },
              "details": {
                "type": "object",
                "additionalProperties": true,
                "description": "Structured context, such as validation `issues`. An empty object when there is none."
              }
            }
          }
        },
        "example": {
          "error": {
            "code": "VALIDATION_FAILED",
            "message": "The request body is not valid.",
            "request_id": "req_6f1c2a9e0b7d4e3f8a5c1d2e3f4a5b6c",
            "details": {
              "issues": [
                {
                  "path": "to",
                  "message": "Invalid phone number"
                }
              ]
            }
          }
        }
      }
    },
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "A workspace API key, `cr_live_…`. Server-side only: it carries workspace authority and must never reach a browser. A key holds only the scopes chosen when it was created; scopes are never implied, so `messages:write` does not grant `messages:read`. Each operation lists the scope it needs. The full list is in `x-scopes`.",
        "x-scopes": [
          "messages:read",
          "messages:write",
          "connections:read",
          "connections:write",
          "webhooks:read",
          "webhooks:write",
          "schedules:read",
          "schedules:write",
          "ai:read",
          "ai:write",
          "mcp:read",
          "mcp:write",
          "usage:read"
        ]
      },
      "oauth": {
        "type": "oauth2",
        "description": "OAuth 2.1 with PKCE, for MCP clients. Accepted only by `POST /v1/mcp`. Clients register themselves (RFC 7591) at `/v1/oauth/register`; discovery is at `/.well-known/oauth-authorization-server`.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://www.chatrail.dev/v1/oauth/authorize",
            "tokenUrl": "https://www.chatrail.dev/v1/oauth/token",
            "refreshUrl": "https://www.chatrail.dev/v1/oauth/token",
            "scopes": {
              "mcp:read": "Read connections, message delivery state, schedules and webhook deliveries",
              "mcp:write": "Reschedule or cancel messages, react to messages and replay webhooks"
            }
          }
        }
      },
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "chatrail_session",
        "description": "Dashboard session cookie. Set by `/v1/auth/verify`."
      }
    }
  },
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/v1/messages/text": {
      "post": {
        "summary": "Send a message",
        "description": "Accepts a message for delivery and returns 202. **202 means accepted, never delivered** — the message is durably stored and queued, and only the `status` field ever claims delivery. Send `media` or `location` for an attachment, `send_at` to defer it. Supply `Idempotency-Key` so a retry cannot send twice. A first message to someone the number has never talked to is checked against WhatsApp and paced: 10 an hour in a number's first week, 30 after, at least 20 seconds apart. Over the pace it stays `queued` and goes out later; nothing is refused. A message WhatsApp accepts but never confirms sending within 24 hours is failed with `not_confirmed`.",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_messages_text",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 255
            },
            "description": "Any unique string, up to 255 characters, chosen by you. Send the same key on a retry and the original response comes back instead of a second send. Keys are scoped to the API key and the endpoint and kept for 24 hours. Reusing a key with a different body is refused with 422. Without one the send still works, and the response says `idempotent: false`.",
            "example": "order-CR-2048-shipped"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 40
                  },
                  "to": {
                    "anyOf": [
                      {
                        "type": "string",
                        "minLength": 5,
                        "maxLength": 40
                      },
                      {
                        "type": "object",
                        "properties": {
                          "phone": {
                            "type": "string",
                            "minLength": 5,
                            "maxLength": 40
                          }
                        },
                        "required": [
                          "phone"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "group": {
                            "type": "string",
                            "minLength": 5,
                            "maxLength": 40
                          }
                        },
                        "required": [
                          "group"
                        ],
                        "additionalProperties": false
                      }
                    ]
                  },
                  "body": {
                    "type": "string",
                    "maxLength": 4096
                  },
                  "media": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "maxLength": 2048,
                        "format": "uri"
                      },
                      "kind": {
                        "type": "string",
                        "enum": [
                          "image",
                          "video",
                          "audio",
                          "document"
                        ]
                      },
                      "mimetype": {
                        "type": "string",
                        "minLength": 3,
                        "maxLength": 255
                      },
                      "filename": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                      }
                    },
                    "required": [
                      "url"
                    ],
                    "additionalProperties": false
                  },
                  "location": {
                    "type": "object",
                    "properties": {
                      "latitude": {
                        "type": "number",
                        "minimum": -90,
                        "maximum": 90
                      },
                      "longitude": {
                        "type": "number",
                        "minimum": -180,
                        "maximum": 180
                      },
                      "title": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                      }
                    },
                    "required": [
                      "latitude",
                      "longitude"
                    ],
                    "additionalProperties": false
                  },
                  "contact": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                      },
                      "phone": {
                        "type": "string",
                        "minLength": 5,
                        "maxLength": 40
                      },
                      "organization": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                      }
                    },
                    "required": [
                      "name",
                      "phone"
                    ],
                    "additionalProperties": false
                  },
                  "poll": {
                    "type": "object",
                    "properties": {
                      "question": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                      },
                      "options": {
                        "minItems": 2,
                        "maxItems": 12,
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        }
                      },
                      "multiple_answers": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "question",
                      "options"
                    ],
                    "additionalProperties": false
                  },
                  "reply_to": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "mentions": {
                    "minItems": 1,
                    "maxItems": 50,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 40
                    }
                  },
                  "link_preview": {
                    "type": "boolean"
                  },
                  "context": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  },
                  "metadata": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  },
                  "pause_ai": {
                    "type": "boolean"
                  },
                  "context_sensitivity": {
                    "type": "string",
                    "enum": [
                      "normal",
                      "sensitive",
                      "restricted"
                    ]
                  },
                  "send_at": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "timezone": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  }
                },
                "required": [
                  "connection",
                  "to"
                ],
                "additionalProperties": false
              },
              "example": {
                "connection": "main",
                "to": "+15551234567",
                "body": "Order CR-2048 has shipped.",
                "context": {
                  "order_id": "CR-2048",
                  "status": "dispatched"
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted and queued.",
            "headers": {
              "Idempotent-Replay": {
                "description": "`true` when this is the stored response to an earlier request with the same `Idempotency-Key`. Nothing was sent again.",
                "schema": {
                  "type": "string",
                  "enum": [
                    "true"
                  ]
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The message id. Read its status or cancel it with this."
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "scheduled",
                        "accepted",
                        "queued",
                        "submitting",
                        "submitted",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "canceled"
                      ],
                      "description": "`queued`, or `scheduled` with `send_at`. Accepted is not delivered."
                    },
                    "kind": {
                      "type": "string",
                      "enum": [
                        "text",
                        "image",
                        "video",
                        "audio",
                        "document",
                        "location",
                        "contact",
                        "poll"
                      ]
                    },
                    "connection": {
                      "type": "string",
                      "description": "The connection that will send it."
                    },
                    "accepted_at": {
                      "type": "string",
                      "format": "date-time",
                      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string",
                          "format": "date-time",
                          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "idempotent": {
                      "type": "boolean",
                      "description": "True when the request carried an `Idempotency-Key`, so a retry cannot send twice."
                    }
                  },
                  "required": [
                    "id",
                    "status",
                    "kind",
                    "connection",
                    "accepted_at",
                    "scheduled_at",
                    "idempotent"
                  ],
                  "additionalProperties": false
                },
                "example": {
                  "id": "0192f4a1-7c3e-7b2a-9d41-5e6f7a8b9c0d",
                  "status": "queued",
                  "kind": "text",
                  "connection": "main",
                  "accepted_at": "2026-11-17T09:30:00.000Z",
                  "scheduled_at": null,
                  "idempotent": true
                }
              }
            }
          },
          "400": {
            "description": "The body, recipient or attachment was rejected.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "The plan does not include this. The message names what would allow it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The connection is not ready, or an identical Idempotency-Key is in flight.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "The Idempotency-Key was reused with a different body.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Quota or rate limit.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "X-RateLimit-Limit": {
                "description": "Requests allowed in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Requests left in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Seconds until the window resets.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/messages": {
      "get": {
        "summary": "List messages",
        "description": "Newest first, cursor paginated. Offsets are not offered: they skip and duplicate.",
        "tags": [
          "Messages"
        ],
        "operationId": "get_v1_messages",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "default": 25,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "connection",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 40
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "scheduled",
                "accepted",
                "queued",
                "submitting",
                "submitted",
                "sent",
                "delivered",
                "read",
                "failed",
                "canceled"
              ]
            }
          },
          {
            "name": "direction",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "inbound",
                "outbound"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of messages and a `next_cursor`."
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:read"
            ]
          }
        ],
        "x-scopes": [
          "messages:read"
        ]
      }
    },
    "/v1/messages/{id}": {
      "get": {
        "summary": "Get a message",
        "tags": [
          "Messages"
        ],
        "operationId": "get_v1_messages__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Message id."
          }
        ],
        "responses": {
          "200": {
            "description": "The message and its delivery timeline."
          },
          "404": {
            "description": "No such message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:read"
            ]
          }
        ],
        "x-scopes": [
          "messages:read"
        ]
      },
      "patch": {
        "summary": "Edit a message",
        "description": "Replaces the text of a text message this number sent, within WhatsApp's 15-minute window, and/or its `context`. Captions cannot be changed after sending. The first text is kept and audited. Editing the text does not change the context the AI answers from: send `context` too when the correction matters to it (a new gate, a new time). A context-only edit has no window and does not reach WhatsApp.",
        "tags": [
          "Messages"
        ],
        "operationId": "patch_v1_messages__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Message id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "body": {
                    "type": "string",
                    "maxLength": 4096
                  },
                  "context": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  },
                  "context_sensitivity": {
                    "type": "string",
                    "enum": [
                      "normal",
                      "sensitive",
                      "restricted"
                    ]
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "body": "Corrected: viewing is at 3pm, not 2pm.",
                "context": {
                  "property": {
                    "address": "14 Mill Lane",
                    "viewing": "15:00"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The message, with `edited_at` set."
          },
          "404": {
            "description": "No such message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Not editable: received, not a text message, deleted, or past the window.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/messages/{id}/cancel": {
      "post": {
        "summary": "Cancel a message",
        "description": "Only while it has not reached the provider. Once submitted the message exists on somebody's phone and cancelling would be a lie.",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_messages__id__cancel",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Message id."
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled."
          },
          "404": {
            "description": "No such message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Already handed to the provider.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/messages/{id}/reactions": {
      "post": {
        "summary": "React to a message",
        "description": "Sets this number's reaction on a message it sent or received; an empty `emoji` removes it. Works on any message that has reached WhatsApp.",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_messages__id__reactions",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Message id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "emoji": {
                    "type": "string",
                    "maxLength": 16
                  }
                },
                "required": [
                  "emoji"
                ],
                "additionalProperties": false
              },
              "example": {
                "emoji": "👍"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The message, with `reaction` set."
          },
          "404": {
            "description": "No such message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Not possible for this message, or WhatsApp refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "The connection's engine does not support reactions.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/messages/{id}/read": {
      "post": {
        "summary": "Mark a message read",
        "description": "Shows blue ticks to the sender of an inbound message. Idempotent: a second call sends nothing.",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_messages__id__read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Message id."
          }
        ],
        "responses": {
          "200": {
            "description": "The message, with `seen_at` set."
          },
          "404": {
            "description": "No such message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Only a received message can be marked read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/connections/{connection}": {
      "patch": {
        "summary": "Change connection settings",
        "description": "Send only the settings you want to change. `reject_calls` declines incoming calls on this number automatically. It is off by default, because the caller sees the call declined. Each call is still announced as `call.received`, with `rejected` saying whether it was declined. `proxy` routes this number through its own HTTP proxy (Team plan), or removes it with `null` (any plan). A proxy is `server` (an IP address and port, not a hostname, and a public address) with an optional `username` and `password`. It is applied when the number is paired, so it can only be changed before the number is linked, or after WhatsApp has logged it out. The response shows the address and `has_credentials`; the username and password are never returned.",
        "tags": [
          "Connections"
        ],
        "operationId": "patch_v1_connections__connection_",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reject_calls": {
                    "type": "boolean"
                  },
                  "proxy": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "server": {
                            "type": "string",
                            "minLength": 9,
                            "maxLength": 64
                          },
                          "username": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256,
                            "allOf": [
                              {
                                "pattern": "^[\\x21-\\x7e]+$"
                              },
                              {
                                "pattern": "^[^/?#%]+$"
                              },
                              {
                                "pattern": "^[^:]+$"
                              }
                            ]
                          },
                          "password": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256,
                            "allOf": [
                              {
                                "pattern": "^[\\x21-\\x7e]+$"
                              },
                              {
                                "pattern": "^[^/?#%]+$"
                              }
                            ]
                          }
                        },
                        "required": [
                          "server"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "reject_calls": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated connection."
          },
          "400": {
            "description": "A setting is not valid, such as a proxy that is a hostname or a private address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "The plan does not include proxies.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such connection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The proxy cannot be changed: the number is linked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "The number's WhatsApp engine cannot use a proxy.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      },
      "get": {
        "summary": "Get a connection",
        "tags": [
          "Connections"
        ],
        "operationId": "get_v1_connections__connection_",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "responses": {
          "200": {
            "description": "The connection and its state."
          },
          "404": {
            "description": "No such connection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:read"
            ]
          }
        ],
        "x-scopes": [
          "connections:read"
        ]
      },
      "delete": {
        "summary": "Delete a connection",
        "description": "Soft deletes it and queues removal of its data.",
        "tags": [
          "Connections"
        ],
        "operationId": "delete_v1_connections__connection_",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "404": {
            "description": "No such connection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/connections/{connection}/groups": {
      "post": {
        "summary": "Create a group",
        "description": "Creates a WhatsApp group with this number as its owner. Everyone added counts against the member-add guardrail: at most 20 people per connection per hour, because adding people who did not ask to be added is how numbers get reported. Paid plans.",
        "tags": [
          "Groups"
        ],
        "operationId": "post_v1_connections__connection__groups",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "participants": {
                    "minItems": 1,
                    "maxItems": 50,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 5,
                      "maxLength": 40
                    }
                  }
                },
                "required": [
                  "name",
                  "participants"
                ],
                "additionalProperties": false
              },
              "example": {
                "name": "Riverside viewings",
                "participants": [
                  "+447700900123",
                  "+447700900456"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new group, with its members."
          },
          "402": {
            "description": "Not on this plan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Over the member-add guardrail for this hour.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "X-RateLimit-Limit": {
                "description": "Requests allowed in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Requests left in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Seconds until the window resets.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      },
      "get": {
        "summary": "List WhatsApp groups",
        "description": "Returns a bounded, name-sorted page for a group picker. Group ids use the same `from.group` representation delivered in message webhooks. Participant identities are never returned.",
        "tags": [
          "Connections"
        ],
        "operationId": "get_v1_connections__connection__groups",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "default": 100,
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "default": 0,
              "type": "integer",
              "minimum": 0,
              "maximum": 100000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of groups."
          },
          "404": {
            "description": "No such connection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "The transport returned an unreadable response.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The transport is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:read"
            ]
          }
        ],
        "x-scopes": [
          "connections:read"
        ]
      }
    },
    "/v1/connections/{connection}/groups/{group}": {
      "get": {
        "summary": "Get a group",
        "description": "Name, description, settings and members with their roles.",
        "tags": [
          "Groups"
        ],
        "operationId": "get_v1_connections__connection__groups__group_",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          },
          {
            "name": "group",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id."
          }
        ],
        "responses": {
          "200": {
            "description": "The group."
          },
          "404": {
            "description": "No such group for this number.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:read"
            ]
          }
        ],
        "x-scopes": [
          "connections:read"
        ]
      },
      "patch": {
        "summary": "Update a group",
        "description": "Change the name or description, or who may send messages and edit group info. This number must be an admin of the group. Paid plans.",
        "tags": [
          "Groups"
        ],
        "operationId": "patch_v1_connections__connection__groups__group_",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          },
          {
            "name": "group",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 2048
                  },
                  "messages_admins_only": {
                    "type": "boolean"
                  },
                  "info_admins_only": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "messages_admins_only": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated group."
          },
          "409": {
            "description": "WhatsApp refused; not an admin?",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/connections/{connection}/groups/{group}/participants": {
      "post": {
        "summary": "Change group members",
        "description": "`add`, `remove`, `promote` to admin or `demote`. Adding counts against the member-add guardrail (20 per connection per hour). Paid plans.",
        "tags": [
          "Groups"
        ],
        "operationId": "post_v1_connections__connection__groups__group__participants",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          },
          {
            "name": "group",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "add",
                      "remove",
                      "promote",
                      "demote"
                    ]
                  },
                  "participants": {
                    "minItems": 1,
                    "maxItems": 50,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 5,
                      "maxLength": 40
                    }
                  }
                },
                "required": [
                  "action",
                  "participants"
                ],
                "additionalProperties": false
              },
              "example": {
                "action": "add",
                "participants": [
                  "+447700900789"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The group after the change."
          },
          "429": {
            "description": "Over the member-add guardrail for this hour.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "X-RateLimit-Limit": {
                "description": "Requests allowed in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Requests left in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Seconds until the window resets.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/connections/{connection}/groups/{group}/invite": {
      "get": {
        "summary": "Get a group invite link",
        "description": "The chat.whatsapp.com link for joining the group.",
        "tags": [
          "Groups"
        ],
        "operationId": "get_v1_connections__connection__groups__group__invite",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          },
          {
            "name": "group",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id."
          }
        ],
        "responses": {
          "200": {
            "description": "The link."
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:read"
            ]
          }
        ],
        "x-scopes": [
          "connections:read"
        ]
      }
    },
    "/v1/connections/{connection}/groups/{group}/invite/revoke": {
      "post": {
        "summary": "Revoke a group invite link",
        "description": "Invalidates the current link and returns a new one.",
        "tags": [
          "Groups"
        ],
        "operationId": "post_v1_connections__connection__groups__group__invite_revoke",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          },
          {
            "name": "group",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id."
          }
        ],
        "responses": {
          "200": {
            "description": "The new link."
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/connections/{connection}/groups/{group}/leave": {
      "post": {
        "summary": "Leave a group",
        "description": "This number leaves the group.",
        "tags": [
          "Groups"
        ],
        "operationId": "post_v1_connections__connection__groups__group__leave",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          },
          {
            "name": "group",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Group id."
          }
        ],
        "responses": {
          "204": {
            "description": "Left."
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/connections/{connection}/presence": {
      "post": {
        "summary": "Show typing in a chat",
        "description": "Shows \"typing…\" or \"recording…\" to a person or group, or stops (`paused`). WhatsApp clears it by itself after a short while or when a message arrives. Nothing is stored.",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_connections__connection__presence",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "to": {
                    "anyOf": [
                      {
                        "type": "string",
                        "minLength": 5,
                        "maxLength": 40
                      },
                      {
                        "type": "object",
                        "properties": {
                          "phone": {
                            "type": "string",
                            "minLength": 5,
                            "maxLength": 40
                          }
                        },
                        "required": [
                          "phone"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "group": {
                            "type": "string",
                            "minLength": 5,
                            "maxLength": 40
                          }
                        },
                        "required": [
                          "group"
                        ],
                        "additionalProperties": false
                      }
                    ]
                  },
                  "state": {
                    "type": "string",
                    "enum": [
                      "typing",
                      "recording",
                      "paused"
                    ]
                  }
                },
                "required": [
                  "to",
                  "state"
                ],
                "additionalProperties": false
              },
              "example": {
                "to": "+447700900123",
                "state": "typing"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Shown."
          },
          "404": {
            "description": "No such connection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The connection is not ready.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "The connection's engine cannot show typing.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/messages/{id}/revoke": {
      "post": {
        "summary": "Delete a message for everyone",
        "description": "Removes a message this number sent from every phone in the chat, within WhatsApp's window of about two and a half days. The record stays in ChatRail, marked deleted, and the deletion is audited.",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_messages__id__revoke",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Message id."
          }
        ],
        "responses": {
          "200": {
            "description": "The message, with `deleted_at` set."
          },
          "404": {
            "description": "No such message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Not deletable: received, already deleted, or past the window.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/messages/{id}/reschedule": {
      "post": {
        "summary": "Move a scheduled message",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_messages__id__reschedule",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Message id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "send_at": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "timezone": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  }
                },
                "required": [
                  "send_at"
                ],
                "additionalProperties": false
              },
              "example": {
                "send_at": "2026-10-01T09:00:00Z",
                "timezone": "Europe/London"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rescheduled."
          },
          "409": {
            "description": "No longer scheduled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/messages/export": {
      "get": {
        "summary": "Export delivery metadata as CSV",
        "description": "Streamed row by row. **Message bodies are not included** — this is delivery metadata, not content.",
        "tags": [
          "Messages"
        ],
        "operationId": "get_v1_messages_export",
        "parameters": [
          {
            "name": "connection",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 40
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 20
            }
          },
          {
            "name": "direction",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "inbound",
                "outbound"
              ]
            }
          },
          {
            "name": "days",
            "in": "query",
            "required": false,
            "schema": {
              "default": 30,
              "type": "integer",
              "minimum": 1,
              "maximum": 365
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A CSV stream."
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:read"
            ]
          }
        ],
        "x-scopes": [
          "messages:read"
        ]
      }
    },
    "/v1/numbers/check": {
      "get": {
        "summary": "Check whether a number is on WhatsApp",
        "description": "Answers `checked: false` when the engine cannot say. Treat that as \"send anyway\": refusing a message because a check failed turns a missing provider feature into a delivery failure. `chat_id` is WhatsApp's own id for the chat when it gives one. An answer from the last 24 hours is reused (`cached: true`) without asking WhatsApp again. Lookups that do reach WhatsApp go through your connected number and are limited to 10 a minute per workspace, and 30 a day on Sandbox.",
        "tags": [
          "Messages"
        ],
        "operationId": "get_v1_numbers_check",
        "parameters": [
          {
            "name": "phone",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 5,
              "maxLength": 40
            }
          },
          {
            "name": "connection",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 40
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The answer, or `checked: false`."
          },
          "404": {
            "description": "No such connection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "No lookup budget left; `Retry-After` says how long to wait.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "X-RateLimit-Limit": {
                "description": "Requests allowed in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Requests left in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Seconds until the window resets.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:read"
            ]
          }
        ],
        "x-scopes": [
          "messages:read"
        ]
      },
      "post": {
        "summary": "Check up to 10 numbers",
        "description": "The same check for several numbers. Each gets its own line in `results`, in the order sent: a number that cannot be parsed has `reason: invalid_number`, and numbers a spent budget could not reach have `reason: minute_limit` or `daily_limit` instead of failing the request. Repeats in one request are looked up once.",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_numbers_check",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 40
                  },
                  "phones": {
                    "minItems": 1,
                    "maxItems": 10,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 40
                    }
                  }
                },
                "required": [
                  "connection",
                  "phones"
                ],
                "additionalProperties": false
              },
              "example": {
                "connection": "main",
                "phones": [
                  "+923001234567",
                  "+2348031234567"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One result per number."
          },
          "400": {
            "description": "No numbers, or more than 10.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such connection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:read"
            ]
          }
        ],
        "x-scopes": [
          "messages:read"
        ]
      }
    },
    "/v1/connections": {
      "post": {
        "summary": "Create a connection",
        "description": "Returns `callback_token` **exactly once**. It cannot be retrieved again; store it when you receive it. On the Team plan, add `proxy` to link this number through its own HTTP proxy instead of ChatRail's address: `server` is an IP address and port (not a hostname, and a public address), with an optional `username` and `password` that are stored encrypted and never returned. Use a fixed address, ideally in the same country as the number.",
        "tags": [
          "Connections"
        ],
        "operationId": "post_v1_connections",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "slug": {
                    "type": "string",
                    "pattern": "^[a-z0-9][a-z0-9-]{0,38}[a-z0-9]$"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "proxy": {
                    "type": "object",
                    "properties": {
                      "server": {
                        "type": "string",
                        "minLength": 9,
                        "maxLength": 64
                      },
                      "username": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 256,
                        "allOf": [
                          {
                            "pattern": "^[\\x21-\\x7e]+$"
                          },
                          {
                            "pattern": "^[^/?#%]+$"
                          },
                          {
                            "pattern": "^[^:]+$"
                          }
                        ]
                      },
                      "password": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 256,
                        "allOf": [
                          {
                            "pattern": "^[\\x21-\\x7e]+$"
                          },
                          {
                            "pattern": "^[^/?#%]+$"
                          }
                        ]
                      }
                    },
                    "required": [
                      "server"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "slug"
                ],
                "additionalProperties": false
              },
              "example": {
                "slug": "operations",
                "name": "Operations line"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created, with the one-time callback token."
          },
          "400": {
            "description": "The request is not valid, such as a proxy that is a hostname or a private address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "The plan has no room for another number, or does not include proxies.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "That slug is taken.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "The WhatsApp engine cannot use a proxy.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      },
      "get": {
        "summary": "List connections",
        "tags": [
          "Connections"
        ],
        "operationId": "get_v1_connections",
        "responses": {
          "200": {
            "description": "Every live connection in the workspace."
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:read"
            ]
          }
        ],
        "x-scopes": [
          "connections:read"
        ]
      }
    },
    "/v1/connections/{connection}/pair": {
      "post": {
        "summary": "Begin pairing",
        "description": "Issues a short-lived, single-use grant. By default it holds a QR; with `{\"method\": \"code\", \"phone\": \"+447700900123\"}` it holds a pairing code instead, which the person enters under Linked devices → Link with phone number (encoding `pairing-code`). Either is fetched once with the grant id: each is a pairing credential, so whoever uses it links *their* device to the number.",
        "tags": [
          "Connections"
        ],
        "operationId": "post_v1_connections__connection__pair",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "method": {
                    "default": "qr",
                    "type": "string",
                    "enum": [
                      "qr",
                      "code"
                    ]
                  },
                  "phone": {
                    "type": "string",
                    "minLength": 5,
                    "maxLength": 40
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "method": "code",
                "phone": "+447700900123"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A grant id and its expiry."
          },
          "409": {
            "description": "The connection cannot be paired from its current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "No transport is configured on this deployment.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/connections/{connection}/qr/{grantId}": {
      "get": {
        "summary": "Redeem a QR grant",
        "description": "Single use. A redeemed or expired grant is gone; ask for another.",
        "tags": [
          "Connections"
        ],
        "operationId": "get_v1_connections__connection__qr__grantId_",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          },
          {
            "name": "grantId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Grant id."
          }
        ],
        "responses": {
          "200": {
            "description": "The pairing payload."
          },
          "404": {
            "description": "Unknown, used or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/connections/{connection}/suspend": {
      "post": {
        "summary": "Suspend a connection",
        "tags": [
          "Connections"
        ],
        "operationId": "post_v1_connections__connection__suspend",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "responses": {
          "200": {
            "description": "Suspended."
          },
          "409": {
            "description": "Not in a suspendable state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/connections/{connection}/resume": {
      "post": {
        "summary": "Resume a suspended connection",
        "tags": [
          "Connections"
        ],
        "operationId": "post_v1_connections__connection__resume",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "responses": {
          "200": {
            "description": "Resumed."
          },
          "409": {
            "description": "Not suspended.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "connections:write"
            ]
          }
        ],
        "x-scopes": [
          "connections:write"
        ]
      }
    },
    "/v1/schedules": {
      "post": {
        "summary": "Create a recurring schedule",
        "description": "Daily, weekly or monthly, resolved in the given IANA timezone. A schedule that fell behind fires once and drops the backlog rather than delivering days of stale messages.",
        "tags": [
          "Schedules"
        ],
        "operationId": "post_v1_schedules",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "timezone": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  },
                  "recurrence": {
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "daily"
                          },
                          "hour": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 23
                          },
                          "minute": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 59
                          }
                        },
                        "required": [
                          "type",
                          "hour",
                          "minute"
                        ]
                      },
                      {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "weekly"
                          },
                          "hour": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 23
                          },
                          "minute": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 59
                          },
                          "days_of_week": {
                            "minItems": 1,
                            "maxItems": 7,
                            "type": "array",
                            "items": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 6
                            }
                          }
                        },
                        "required": [
                          "type",
                          "hour",
                          "minute",
                          "days_of_week"
                        ]
                      },
                      {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "monthly"
                          },
                          "hour": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 23
                          },
                          "minute": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 59
                          },
                          "day_of_month": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": 1,
                                "maximum": 31
                              },
                              {
                                "type": "number",
                                "const": -1
                              }
                            ]
                          }
                        },
                        "required": [
                          "type",
                          "hour",
                          "minute",
                          "day_of_month"
                        ]
                      }
                    ]
                  },
                  "message": {
                    "type": "object",
                    "properties": {},
                    "additionalProperties": {}
                  },
                  "starts_at": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "ends_at": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "max_occurrences": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10000
                  }
                },
                "required": [
                  "name",
                  "timezone",
                  "recurrence",
                  "message"
                ],
                "additionalProperties": false
              },
              "example": {
                "name": "Friday digest",
                "timezone": "Europe/London",
                "recurrence": {
                  "type": "weekly",
                  "hour": 9,
                  "minute": 0,
                  "days_of_week": [
                    5
                  ]
                },
                "message": {
                  "connection": "main",
                  "to": "+15551234567",
                  "body": "Your weekly digest is ready."
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created, with the resolved `next_run_at`."
          },
          "400": {
            "description": "Unknown timezone, or a recurrence that would never fire.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "The plan does not include scheduling.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "schedules:write"
            ]
          }
        ],
        "x-scopes": [
          "schedules:write"
        ]
      },
      "get": {
        "summary": "List schedules",
        "tags": [
          "Schedules"
        ],
        "operationId": "get_v1_schedules",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "paused",
                "completed",
                "canceled"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Every schedule in the workspace."
          }
        },
        "security": [
          {
            "apiKey": [
              "schedules:read"
            ]
          }
        ],
        "x-scopes": [
          "schedules:read"
        ]
      }
    },
    "/v1/schedules/{id}": {
      "get": {
        "summary": "Get a schedule",
        "tags": [
          "Schedules"
        ],
        "operationId": "get_v1_schedules__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Schedule id."
          }
        ],
        "responses": {
          "200": {
            "description": "The schedule."
          },
          "404": {
            "description": "No such schedule.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "schedules:read"
            ]
          }
        ],
        "x-scopes": [
          "schedules:read"
        ]
      }
    },
    "/v1/schedules/{id}/pause": {
      "post": {
        "summary": "Pause a schedule",
        "description": "Keeps the schedule and stops it firing.",
        "tags": [
          "Schedules"
        ],
        "operationId": "post_v1_schedules__id__pause",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Schedule id."
          }
        ],
        "responses": {
          "200": {
            "description": "The updated schedule."
          },
          "409": {
            "description": "Not in a state that allows it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "schedules:write"
            ]
          }
        ],
        "x-scopes": [
          "schedules:write"
        ]
      }
    },
    "/v1/schedules/{id}/resume": {
      "post": {
        "summary": "Resume a schedule",
        "description": "The next run is computed from now. A schedule paused for a month does not fire the month it missed.",
        "tags": [
          "Schedules"
        ],
        "operationId": "post_v1_schedules__id__resume",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Schedule id."
          }
        ],
        "responses": {
          "200": {
            "description": "The updated schedule."
          },
          "409": {
            "description": "Not in a state that allows it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "schedules:write"
            ]
          }
        ],
        "x-scopes": [
          "schedules:write"
        ]
      }
    },
    "/v1/schedules/{id}/cancel": {
      "post": {
        "summary": "Cancel a schedule",
        "description": "Permanent. A cancelled schedule cannot be restarted.",
        "tags": [
          "Schedules"
        ],
        "operationId": "post_v1_schedules__id__cancel",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Schedule id."
          }
        ],
        "responses": {
          "200": {
            "description": "The updated schedule."
          },
          "409": {
            "description": "Not in a state that allows it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "schedules:write"
            ]
          }
        ],
        "x-scopes": [
          "schedules:write"
        ]
      }
    },
    "/v1/facts": {
      "get": {
        "summary": "Get the business facts",
        "description": "What the AI may tell customers about the business: the saved facts page, the owner’s notes, and the sources (websites, documents) it was drafted from. The text read from a source is kept for drafting and never returned. Automations that answer questions answer only from the saved page, and AI replies read it on every reply, so a chat the customer starts can be answered without any `context` on a message.",
        "tags": [
          "Facts"
        ],
        "operationId": "get_v1_facts",
        "responses": {
          "200": {
            "description": "The facts page, notes and sources. `facts` is empty until one is saved."
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-scopes": []
      },
      "put": {
        "summary": "Save the facts page",
        "description": "Saves the page automations and AI replies answer customers from, replacing the last one. This is the only call that changes what customers are told. At most 20,000 characters.",
        "tags": [
          "Facts"
        ],
        "operationId": "put_v1_facts",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "facts": {
                    "type": "string",
                    "maxLength": 20000
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 20000
                  }
                },
                "required": [
                  "facts"
                ],
                "additionalProperties": false
              },
              "example": {
                "facts": "## Hours\nMon–Sat 9am to 6pm. Closed Sundays."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved facts."
          },
          "400": {
            "description": "The page is too long.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-scopes": []
      }
    },
    "/v1/facts/website": {
      "post": {
        "summary": "Read a website into the sources",
        "description": "Reads the home page and up to seven pages it links to that customers ask about (contact, prices, delivery, returns, FAQ). Only public https addresses are read; nothing on a private network is fetched. The text becomes a source for drafting, and changes nothing customers see.",
        "tags": [
          "Facts"
        ],
        "operationId": "post_v1_facts_website",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 500
                  }
                },
                "required": [
                  "url"
                ],
                "additionalProperties": false
              },
              "example": {
                "url": "kitchen.pk"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The facts, with `read` saying how many pages were read and skipped."
          },
          "400": {
            "description": "The address could not be read; `message` says why.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many reads this hour.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "X-RateLimit-Limit": {
                "description": "Requests allowed in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Requests left in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Seconds until the window resets.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-scopes": []
      }
    },
    "/v1/facts/file": {
      "post": {
        "summary": "Read a document into the sources",
        "description": "A PDF, Word (.docx) or text file of up to 8 MB, sent as base64. A scanned PDF has no text and is refused. The text becomes a source for drafting.",
        "tags": [
          "Facts"
        ],
        "operationId": "post_v1_facts_file",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "content_base64": {
                    "type": "string",
                    "minLength": 4
                  }
                },
                "required": [
                  "name",
                  "content_base64"
                ],
                "additionalProperties": false
              },
              "example": {
                "name": "prices.docx",
                "content_base64": "<base64 of the file>"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The facts, with the new source listed."
          },
          "400": {
            "description": "The file could not be read; `message` says why.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many reads this hour.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "X-RateLimit-Limit": {
                "description": "Requests allowed in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Requests left in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Seconds until the window resets.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-scopes": []
      }
    },
    "/v1/facts/sources/{id}": {
      "delete": {
        "summary": "Remove a source",
        "description": "Forgets what was read from it. The saved facts page is not changed.",
        "tags": [
          "Facts"
        ],
        "operationId": "delete_v1_facts_sources__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Source id."
          }
        ],
        "responses": {
          "200": {
            "description": "The facts, without that source."
          },
          "404": {
            "description": "No such source.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-scopes": []
      }
    },
    "/v1/facts/draft": {
      "post": {
        "summary": "Draft the facts page",
        "description": "The AI writes a facts page from the sources and the notes: headed sections, facts copied as written, nothing added, disagreements marked `CHECK:`. It is a draft and is not saved: read it, edit it and send it to `PUT /v1/facts`. Spends ChatRail’s own AI key, so it is rate limited per workspace.",
        "tags": [
          "Facts"
        ],
        "operationId": "post_v1_facts_draft",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "notes": {
                    "type": "string",
                    "maxLength": 20000
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "notes": "Closed on Sundays."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The draft, as `draft`."
          },
          "400": {
            "description": "There is nothing to draft from yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many drafts this hour.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "X-RateLimit-Limit": {
                "description": "Requests allowed in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Requests left in the current window.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Seconds until the window resets.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Drafting is not available right now.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-scopes": []
      }
    },
    "/v1/webhook-endpoints": {
      "post": {
        "summary": "Register a webhook endpoint",
        "description": "Returns the signing secret **exactly once**. Every delivery is signed with HMAC-SHA256 over the timestamp, a period, and the raw request body; verify it and reject stale timestamps. The URL is validated at registration and the connection pinned at delivery, so an endpoint pointing at a private address is refused. Works with an API key holding `webhooks:write`, so a deploy script can register its own endpoint; every change is audited.",
        "tags": [
          "Webhooks"
        ],
        "operationId": "post_v1_webhook-endpoints",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "maxLength": 2048,
                    "format": "uri"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "events": {
                    "minItems": 1,
                    "maxItems": 46,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "connection": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 40
                  }
                },
                "required": [
                  "url",
                  "events"
                ],
                "additionalProperties": false
              },
              "example": {
                "url": "https://example.com/hooks/chatrail",
                "events": [
                  "message.received",
                  "message.delivered",
                  "message.failed"
                ],
                "description": "Order updates"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created, with the one-time signing secret."
          },
          "400": {
            "description": "The URL is not publicly reachable over https.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Scoping to one connection is not on this plan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "webhooks:write"
            ]
          },
          {
            "session": []
          }
        ],
        "x-scopes": [
          "webhooks:write"
        ]
      },
      "get": {
        "summary": "List webhook endpoints",
        "tags": [
          "Webhooks"
        ],
        "operationId": "get_v1_webhook-endpoints",
        "responses": {
          "200": {
            "description": "Endpoints, without their signing secrets."
          }
        },
        "security": [
          {
            "apiKey": [
              "webhooks:read"
            ]
          },
          {
            "session": []
          }
        ],
        "x-scopes": [
          "webhooks:read"
        ]
      }
    },
    "/v1/webhook-endpoints/{id}": {
      "delete": {
        "summary": "Delete a webhook endpoint",
        "tags": [
          "Webhooks"
        ],
        "operationId": "delete_v1_webhook-endpoints__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Endpoint id."
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "404": {
            "description": "No such endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "webhooks:write"
            ]
          },
          {
            "session": []
          }
        ],
        "x-scopes": [
          "webhooks:write"
        ]
      }
    },
    "/v1/webhook-endpoints/{id}/enable": {
      "post": {
        "summary": "Re-enable a webhook endpoint",
        "description": "Turns back on an endpoint that was disabled after 50 failed deliveries in a row. The failure count restarts at zero and the signing secret is unchanged. Events skipped while it was disabled are not re-sent.",
        "tags": [
          "Webhooks"
        ],
        "operationId": "post_v1_webhook-endpoints__id__enable",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Endpoint id."
          }
        ],
        "responses": {
          "200": {
            "description": "The endpoint, now active."
          },
          "404": {
            "description": "No such endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "webhooks:write"
            ]
          },
          {
            "session": []
          }
        ],
        "x-scopes": [
          "webhooks:write"
        ]
      }
    },
    "/v1/opt-outs": {
      "get": {
        "summary": "List people who must not be messaged",
        "description": "Numbers on the workspace's opt-out list, oldest first. A number gets here two ways: the person wrote a stop word such as \"STOP\" in a direct chat (`source: inbound_keyword`), or you added it (`source: api`). Sends to a number on the list are refused with `RECIPIENT_OPTED_OUT`, and so are messages already queued or scheduled for it.",
        "tags": [
          "Opt-outs"
        ],
        "operationId": "get_v1_opt-outs",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "default": 100,
              "type": "integer",
              "minimum": 1,
              "maximum": 500
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of opt-outs, with `next_cursor` when there is more."
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:read"
            ]
          }
        ],
        "x-scopes": [
          "messages:read"
        ]
      },
      "post": {
        "summary": "Add a number to the opt-out list",
        "description": "For someone who has asked you, outside WhatsApp, to stop. Adding a number that is already on the list succeeds and changes nothing. Sending to it is refused from then on, including anything already queued or scheduled.",
        "tags": [
          "Opt-outs"
        ],
        "operationId": "post_v1_opt-outs",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "phone": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 40
                  }
                },
                "required": [
                  "phone"
                ],
                "additionalProperties": false
              },
              "example": {
                "phone": "+447700900123"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Already on the list."
          },
          "201": {
            "description": "Added."
          },
          "400": {
            "description": "Not a valid phone number.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/opt-outs/{phone}": {
      "delete": {
        "summary": "Remove a number from the opt-out list",
        "description": "Only for a person who has asked to hear from you again. If they write a stop word again they are opted out again.",
        "tags": [
          "Opt-outs"
        ],
        "operationId": "delete_v1_opt-outs__phone_",
        "parameters": [
          {
            "name": "phone",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The number in international form, with or without the leading +."
          }
        ],
        "responses": {
          "204": {
            "description": "Removed."
          },
          "400": {
            "description": "Not a valid phone number.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "That number is not on the list.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/ai/credentials": {
      "post": {
        "summary": "Store a model provider credential",
        "description": "Encrypted at rest and never returned. AI is off by default and enabled per connection.",
        "tags": [
          "AI"
        ],
        "operationId": "post_v1_ai_credentials",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "provider": {
                    "type": "string",
                    "enum": [
                      "openai_compatible",
                      "anthropic"
                    ]
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "api_key": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 8192
                  },
                  "base_url": {
                    "type": "string",
                    "format": "uri"
                  }
                },
                "required": [
                  "provider",
                  "label",
                  "api_key"
                ],
                "additionalProperties": false
              },
              "example": {
                "provider": "anthropic",
                "label": "Production key",
                "api_key": "sk-ant-replace-with-your-own-key"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stored."
          },
          "402": {
            "description": "AI is not on this plan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:write"
            ]
          }
        ],
        "x-scopes": [
          "ai:write"
        ]
      },
      "get": {
        "summary": "List credentials",
        "description": "Fingerprints and metadata only; the key itself is never returned.",
        "tags": [
          "AI"
        ],
        "operationId": "get_v1_ai_credentials",
        "responses": {
          "200": {
            "description": "Credential metadata."
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:read"
            ]
          }
        ],
        "x-scopes": [
          "ai:read"
        ]
      }
    },
    "/v1/ai/credentials/{id}": {
      "delete": {
        "summary": "Delete a credential",
        "tags": [
          "AI"
        ],
        "operationId": "delete_v1_ai_credentials__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Credential id."
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "404": {
            "description": "No such credential.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:write"
            ]
          }
        ],
        "x-scopes": [
          "ai:write"
        ]
      }
    },
    "/v1/ai/credentials/{id}/test": {
      "post": {
        "summary": "Test a credential",
        "description": "Makes one small call to the model provider with this credential and the given model, so a wrong key or model name shows up before a customer is waiting on a reply.",
        "tags": [
          "AI"
        ],
        "operationId": "post_v1_ai_credentials__id__test",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Credential id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  }
                },
                "required": [
                  "model"
                ]
              },
              "example": {
                "model": "openai/gpt-6-luna"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The provider answered."
          },
          "404": {
            "description": "No such credential.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "The provider refused or failed; the body says why.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:write"
            ]
          },
          {
            "session": []
          }
        ],
        "x-scopes": [
          "ai:write"
        ]
      }
    },
    "/v1/ai/policies/{connection}": {
      "put": {
        "summary": "Set the AI policy for a connection",
        "description": "Draft or auto mode, with token, rate and monthly cost ceilings. Absent policy means AI is off for that connection.",
        "tags": [
          "AI"
        ],
        "operationId": "put_v1_ai_policies__connection_",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "credential_source": {
                    "default": "byok",
                    "type": "string",
                    "enum": [
                      "byok",
                      "managed"
                    ]
                  },
                  "credential_id": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "uuid",
                        "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "enabled": {
                    "type": "boolean"
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "draft",
                      "auto"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "system_instruction": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000
                  },
                  "max_context_bytes": {
                    "default": 8192,
                    "type": "integer",
                    "minimum": 256,
                    "maximum": 32768
                  },
                  "max_output_tokens": {
                    "default": 300,
                    "type": "integer",
                    "minimum": 32,
                    "maximum": 2000
                  },
                  "include_history": {
                    "default": false,
                    "type": "boolean"
                  },
                  "humanize": {
                    "default": true,
                    "type": "boolean"
                  },
                  "human_takeover_minutes": {
                    "default": 1440,
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 43200
                  },
                  "reply_delay_seconds": {
                    "default": 5,
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 120
                  },
                  "group_replies": {
                    "default": "addressed",
                    "type": "string",
                    "enum": [
                      "off",
                      "addressed",
                      "all"
                    ]
                  },
                  "monthly_cost_limit_micros": {
                    "default": null,
                    "anyOf": [
                      {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 9007199254740991
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "input_cost_micros_per_million": {
                    "default": 0,
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "output_cost_micros_per_million": {
                    "default": 0,
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                },
                "required": [
                  "enabled",
                  "mode",
                  "system_instruction"
                ],
                "additionalProperties": false
              },
              "example": {
                "credential_id": "019bf4a1-0000-7000-8000-000000000000",
                "enabled": true,
                "mode": "draft",
                "model": "claude-sonnet-4-5",
                "system_instruction": "Answer only from the attached context. If the answer is not there, say so."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The policy."
          },
          "402": {
            "description": "AI is not on this plan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:write"
            ]
          }
        ],
        "x-scopes": [
          "ai:write"
        ]
      },
      "get": {
        "summary": "Get the AI policy for a connection",
        "description": "Absent policy means AI is off for that connection, which is the default.",
        "tags": [
          "AI"
        ],
        "operationId": "get_v1_ai_policies__connection_",
        "parameters": [
          {
            "name": "connection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Connection slug."
          }
        ],
        "responses": {
          "200": {
            "description": "The policy."
          },
          "404": {
            "description": "No policy is set.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:read"
            ]
          }
        ],
        "x-scopes": [
          "ai:read"
        ]
      }
    },
    "/v1/ai/runs": {
      "get": {
        "summary": "List AI runs",
        "description": "Usage, cost, outcome and the proposed reply. The assembled prompt is represented by its hash and the list of context keys that went into it, never reproduced.",
        "tags": [
          "AI"
        ],
        "operationId": "get_v1_ai_runs",
        "responses": {
          "200": {
            "description": "Recent runs."
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:read"
            ]
          }
        ],
        "x-scopes": [
          "ai:read"
        ]
      }
    },
    "/v1/ai/runs/{id}/send": {
      "post": {
        "summary": "Send an AI draft",
        "description": "Accepts the pending draft through the normal durable message outbox.",
        "tags": [
          "AI"
        ],
        "operationId": "post_v1_ai_runs__id__send",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "AI run id."
          }
        ],
        "responses": {
          "200": {
            "description": "The accepted message id."
          },
          "409": {
            "description": "The draft cannot be sent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:write"
            ]
          }
        ],
        "x-scopes": [
          "ai:write"
        ]
      }
    },
    "/v1/ai/runs/{id}/dismiss": {
      "post": {
        "summary": "Dismiss an AI draft",
        "description": "Removes a pending draft from the human review queue without sending it. Supply a reason where you know it: the counts are what make draft quality measurable, and `wrong_correlation` in particular is the only signal that a reply was matched to the wrong alert.",
        "tags": [
          "AI"
        ],
        "operationId": "post_v1_ai_runs__id__dismiss",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "AI run id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "enum": [
                      "wrong_context",
                      "wrong_correlation",
                      "inaccurate",
                      "tone",
                      "not_needed",
                      "needs_human",
                      "other"
                    ]
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "reason": "wrong_context"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Dismissed."
          },
          "409": {
            "description": "The draft cannot be dismissed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:write"
            ]
          }
        ],
        "x-scopes": [
          "ai:write"
        ]
      }
    },
    "/v1/messages/{id}/media": {
      "get": {
        "summary": "Download an inbound attachment",
        "description": "Streams the file from the transport through ChatRail. Inbound only: an outbound attachment's URL is one the caller supplied and already has. The response carries the stored content type, never the transport's, and is always served as an attachment. Answers 404 when the message has no attachment, when the transport reported a file it does not serve, or when it no longer holds it.",
        "tags": [
          "Messages"
        ],
        "operationId": "get_v1_messages__id__media",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Inbound message id."
          }
        ],
        "responses": {
          "200": {
            "description": "The file."
          },
          "404": {
            "description": "No downloadable media on this message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "This deployment cannot retrieve media from the transport.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:read"
            ]
          }
        ],
        "x-scopes": [
          "messages:read"
        ]
      }
    },
    "/v1/messages/{id}/correlation": {
      "post": {
        "summary": "Correct which message a reply answers",
        "description": "Re-points an inbound reply at the outbound message it actually answers, or unlinks it with `null`. The engine's original choice is preserved, so corrections measure the correlation rules rather than quietly overwriting them. The previously linked alert reopens for correlation; the newly linked one is marked answered.",
        "tags": [
          "Messages"
        ],
        "operationId": "post_v1_messages__id__correlation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Inbound message id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reply_to_message_id": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "uuid",
                        "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "reply_to_message_id"
                ],
                "additionalProperties": false
              },
              "example": {
                "reply_to_message_id": "019bf4a1-0000-7000-8000-000000000000"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The corrected link, and what it overruled."
          },
          "400": {
            "description": "The target is not an outbound message in the same conversation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Only an inbound message has a correlation to correct.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "x-scopes": [
          "messages:write"
        ]
      }
    },
    "/v1/ai/quality": {
      "get": {
        "summary": "Summarise what happened to AI drafts",
        "description": "Counts only, never text: drafts sent unchanged, sent after editing, or dismissed and why; runs that ran with no business context at all; and correlation corrections grouped by the rule that originally fired. Accepts `days` (default 30).",
        "tags": [
          "AI"
        ],
        "operationId": "get_v1_ai_quality",
        "responses": {
          "200": {
            "description": "The summary."
          }
        },
        "security": [
          {
            "apiKey": [
              "ai:read"
            ]
          }
        ],
        "x-scopes": [
          "ai:read"
        ]
      }
    },
    "/v1/whoami": {
      "get": {
        "summary": "Confirm a credential",
        "description": "Shows exactly what the presented credential can do. The first call to make.",
        "tags": [
          "Workspace"
        ],
        "operationId": "get_v1_whoami",
        "responses": {
          "200": {
            "description": "The principal, its scopes and its workspace."
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ]
      }
    },
    "/v1/workspace": {
      "get": {
        "summary": "Get the current workspace",
        "description": "Includes the plan and what has been used against it.",
        "tags": [
          "Workspace"
        ],
        "operationId": "get_v1_workspace",
        "responses": {
          "200": {
            "description": "The workspace, the caller role and the plan."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      },
      "patch": {
        "summary": "Rename the workspace",
        "description": "Changes the display name shown to members, on invitations and in emails. The slug does not change. Needs `workspace:update`.",
        "tags": [
          "Workspace"
        ],
        "operationId": "patch_v1_workspace",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "name"
                ],
                "additionalProperties": false
              },
              "example": {
                "name": "Kettle & Co"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The workspace id, slug and new name."
          },
          "400": {
            "description": "The name is empty or longer than 80 characters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/billing": {
      "get": {
        "summary": "Get the billing account",
        "description": "What Creem says about this workspace: customer, subscription, status and the current period. Distinct from the plan on `/v1/workspace`, which is what the workspace is actually entitled to and is never blocked on this being reachable.",
        "tags": [
          "Billing"
        ],
        "operationId": "get_v1_billing",
        "responses": {
          "200": {
            "description": "The billing account, or the free-tier default if there is none yet."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/billing/regional-price": {
      "get": {
        "summary": "The visitor's regional prices",
        "description": "For the public pricing pages: the regional monthly price of each plan in a country (`?country=NG`, else the visitor's location), or `regional: null` when there is none. It only shows the price; a workspace pays it once it pairs a WhatsApp number from that country.",
        "tags": [
          "Billing"
        ],
        "operationId": "get_v1_billing_regional-price",
        "responses": {
          "200": {
            "description": "The prices for the visitor's country, or `regional: null`."
          }
        },
        "security": []
      }
    },
    "/v1/billing/plans": {
      "get": {
        "summary": "List paid plans",
        "description": "The plans a checkout can be started for, with the price. `purchasable` is false when the plan has no Creem product configured yet. `regional` gives the plan's monthly price for workspaces that paired a WhatsApp number from a country with regional pricing. Before any number is paired it can be shown from the visitor's location with `requires_number: true`, meaning it applies only once a number from that country is paired. Null otherwise.",
        "tags": [
          "Billing"
        ],
        "operationId": "get_v1_billing_plans",
        "responses": {
          "200": {
            "description": "The paid plans, in the order shown on the pricing page."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/billing/checkout": {
      "post": {
        "summary": "Start a checkout",
        "description": "Returns a Creem-hosted checkout URL for the chosen paid plan. When the workspace has a paired number from a regional-pricing country, the checkout opens with that discount.",
        "tags": [
          "Billing"
        ],
        "operationId": "post_v1_billing_checkout",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "plan": {
                    "type": "string",
                    "enum": [
                      "core",
                      "core_ai",
                      "team"
                    ]
                  },
                  "return_path": {
                    "default": "/settings/billing",
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": [
                  "plan"
                ],
                "additionalProperties": false
              },
              "example": {
                "plan": "core_ai",
                "return_path": "/settings/billing"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The checkout id and URL to redirect the browser to."
          },
          "404": {
            "description": "Billing is not configured for this workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/billing/plan-change-check": {
      "post": {
        "summary": "Check whether a plan change is possible",
        "description": "Whether moving to the given plan is allowed, and if not, how many connected numbers would have to be disconnected first. A downgrade is refused rather than applied when it would strand a number over the target plan's limit, because the alternatives are a silently suspended number — whose linked device stops working and needs a QR re-scan — and a customer permanently exceeding the plan they pay for. Changes nothing and spends nothing, so it needs only `billing:read`.",
        "tags": [
          "Billing"
        ],
        "operationId": "post_v1_billing_plan-change-check",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "plan": {
                    "type": "string",
                    "enum": [
                      "core",
                      "core_ai",
                      "team"
                    ]
                  }
                },
                "required": [
                  "plan"
                ],
                "additionalProperties": false
              },
              "example": {
                "plan": "core"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`allowed: true`, or `allowed: false` with the limit, the current count and `mustDisconnect`."
          },
          "400": {
            "description": "The plan is not one that can be bought.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/billing/portal": {
      "post": {
        "summary": "Open the customer portal",
        "description": "A Creem-hosted page to update payment details or cancel — self-serve.",
        "tags": [
          "Billing"
        ],
        "operationId": "post_v1_billing_portal",
        "responses": {
          "200": {
            "description": "The portal URL to redirect the browser to."
          },
          "404": {
            "description": "This workspace has no billing account yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/billing/crypto": {
      "get": {
        "summary": "Crypto payment options",
        "description": "Whether crypto checkout is available, the accepted coins, the prepaid price of each plan for 3 and 12 months (12 months costs 10), and this workspace's prepaid period and newest unpaid order, if any. A crypto purchase is a prepaid block of months, not a subscription: a wallet cannot be charged again automatically. With a regional price, `price_usd` is the reduced price, `list_price_usd` the full one, and `regional` names the discount.",
        "tags": [
          "Billing"
        ],
        "operationId": "get_v1_billing_crypto",
        "responses": {
          "200": {
            "description": "Options and status. `available: false` when crypto is not configured."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/billing/crypto/checkout": {
      "post": {
        "summary": "Start a crypto checkout",
        "description": "Creates a NOWPayments invoice for a prepaid period and returns its URL. The plan is applied when NOWPayments reports the payment `finished`. Buying the same plan again extends the running period; a different plan, or a workspace paying by card, is refused.",
        "tags": [
          "Billing"
        ],
        "operationId": "post_v1_billing_crypto_checkout",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "plan": {
                    "type": "string",
                    "enum": [
                      "core",
                      "core_ai",
                      "team"
                    ]
                  },
                  "months": {
                    "anyOf": [
                      {
                        "type": "number",
                        "const": 3
                      },
                      {
                        "type": "number",
                        "const": 12
                      }
                    ]
                  },
                  "pay_currency": {
                    "type": "string",
                    "pattern": "^[a-z0-9]{2,20}$"
                  },
                  "return_path": {
                    "default": "/settings/billing",
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": [
                  "plan",
                  "months",
                  "pay_currency"
                ],
                "additionalProperties": false
              },
              "example": {
                "plan": "core_ai",
                "months": 12,
                "pay_currency": "usdttrc20",
                "return_path": "/dashboard/billing"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The order id and the invoice URL to redirect the browser to."
          },
          "400": {
            "description": "The plan, period or currency is not one that can be bought.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Crypto payments are not configured.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The workspace pays by card, or has a different plan prepaid.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "Usage counts",
        "description": "Counts only. A count of messages is not a message; no content is reachable here.",
        "tags": [
          "Workspace"
        ],
        "operationId": "get_v1_usage",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 365
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregated counts for the workspace."
          }
        },
        "security": [
          {
            "apiKey": [
              "usage:read"
            ]
          },
          {
            "session": []
          }
        ],
        "x-scopes": [
          "usage:read"
        ]
      }
    },
    "/v1/api-keys": {
      "post": {
        "summary": "Issue an API key",
        "description": "Returns the key **exactly once**. It is stored only as a hash and cannot be recovered. A key may never hold more than the person issuing it.",
        "tags": [
          "Workspace"
        ],
        "operationId": "post_v1_api-keys",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "scopes": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "messages:read",
                        "messages:write",
                        "connections:read",
                        "connections:write",
                        "webhooks:read",
                        "webhooks:write",
                        "schedules:read",
                        "schedules:write",
                        "ai:read",
                        "ai:write",
                        "mcp:read",
                        "mcp:write",
                        "usage:read"
                      ]
                    }
                  },
                  "environment": {
                    "default": "live",
                    "type": "string",
                    "enum": [
                      "live",
                      "test"
                    ]
                  }
                },
                "required": [
                  "name",
                  "scopes"
                ],
                "additionalProperties": false
              },
              "example": {
                "name": "Order service",
                "scopes": [
                  "messages:write",
                  "messages:read"
                ],
                "environment": "live"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The key, once."
          },
          "403": {
            "description": "Your role cannot grant those scopes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      },
      "get": {
        "summary": "List API keys",
        "tags": [
          "Workspace"
        ],
        "operationId": "get_v1_api-keys",
        "responses": {
          "200": {
            "description": "Key metadata and prefixes, never the keys."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/api-keys/{id}/revoke": {
      "post": {
        "summary": "Revoke an API key",
        "tags": [
          "Workspace"
        ],
        "operationId": "post_v1_api-keys__id__revoke",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Key id."
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked, immediately."
          },
          "404": {
            "description": "No such key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/api-keys/{id}/rotate": {
      "post": {
        "summary": "Rotate an API key",
        "description": "Issues a replacement and revokes the old one.",
        "tags": [
          "Workspace"
        ],
        "operationId": "post_v1_api-keys__id__rotate",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Key id."
          }
        ],
        "responses": {
          "200": {
            "description": "The new key, once."
          },
          "404": {
            "description": "No such key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/members": {
      "get": {
        "summary": "List members and pending invitations",
        "tags": [
          "Team"
        ],
        "operationId": "get_v1_members",
        "responses": {
          "200": {
            "description": "Members, invitations, and the roles this caller may assign."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/members/invitations": {
      "post": {
        "summary": "Invite somebody",
        "description": "Emails a single-use link bound to that address. The token is never returned in the response. Nobody may invite to a role above their own.",
        "tags": [
          "Team"
        ],
        "operationId": "post_v1_members_invitations",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "maxLength": 254,
                    "format": "email",
                    "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "owner",
                      "admin",
                      "developer",
                      "viewer",
                      "billing"
                    ]
                  }
                },
                "required": [
                  "email",
                  "role"
                ],
                "additionalProperties": false
              },
              "example": {
                "email": "colleague@company.com",
                "role": "viewer"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Invited."
          },
          "402": {
            "description": "Member management is not on this plan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "You cannot assign that role.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Already a member.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/members/invitations/{id}": {
      "delete": {
        "summary": "Revoke an invitation",
        "tags": [
          "Team"
        ],
        "operationId": "delete_v1_members_invitations__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Invitation id."
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked."
          },
          "404": {
            "description": "No such invitation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/members/invitations/{id}/resend": {
      "post": {
        "summary": "Resend an invitation",
        "description": "Emails the invitation again with a fresh link. Dashboard only.",
        "tags": [
          "Team"
        ],
        "operationId": "post_v1_members_invitations__id__resend",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Invitation id."
          }
        ],
        "responses": {
          "200": {
            "description": "Resent."
          },
          "404": {
            "description": "No such invitation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/members/accept": {
      "post": {
        "summary": "Accept an invitation",
        "description": "Requires a signed-in session whose address matches the invited one. Possessing the token is not enough — a forwarded invitation email must not be a way into a workspace.",
        "tags": [
          "Team"
        ],
        "operationId": "post_v1_members_accept",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "minLength": 20,
                    "maxLength": 200
                  }
                },
                "required": [
                  "token"
                ],
                "additionalProperties": false
              },
              "example": {
                "token": "the token from the invitation link"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Joined."
          },
          "401": {
            "description": "Sign in as the invited address first.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The invitation was sent to a different address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The invitation is not valid.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/members/{id}": {
      "patch": {
        "summary": "Change a member's role",
        "tags": [
          "Team"
        ],
        "operationId": "patch_v1_members__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "User id."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "owner",
                      "admin",
                      "developer",
                      "viewer",
                      "billing"
                    ]
                  }
                },
                "required": [
                  "role"
                ],
                "additionalProperties": false
              },
              "example": {
                "role": "developer"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated member."
          },
          "403": {
            "description": "You cannot assign or act on that role.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "A workspace must keep an owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      },
      "delete": {
        "summary": "Remove a member",
        "tags": [
          "Team"
        ],
        "operationId": "delete_v1_members__id_",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "User id."
          }
        ],
        "responses": {
          "204": {
            "description": "Removed."
          },
          "409": {
            "description": "A workspace must keep an owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/profile": {
      "get": {
        "summary": "Read the signed-in profile",
        "tags": [
          "Auth"
        ],
        "operationId": "get_v1_profile",
        "responses": {
          "200": {
            "description": "Personal account details."
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      },
      "patch": {
        "summary": "Update the display name",
        "tags": [
          "Auth"
        ],
        "operationId": "patch_v1_profile",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  }
                },
                "required": [
                  "name"
                ],
                "additionalProperties": false
              },
              "example": {
                "name": "Ada Lovelace"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated profile."
          },
          "400": {
            "description": "The name is empty or too long.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/profile/sessions": {
      "get": {
        "summary": "List active account sessions",
        "description": "Lists only the signed-in user’s live sessions and never exposes session tokens.",
        "tags": [
          "Auth"
        ],
        "operationId": "get_v1_profile_sessions",
        "responses": {
          "200": {
            "description": "Active device sessions, with the current session marked."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/profile/sessions/revoke-others": {
      "post": {
        "summary": "Sign out other devices",
        "tags": [
          "Auth"
        ],
        "operationId": "post_v1_profile_sessions_revoke-others",
        "responses": {
          "200": {
            "description": "The number of other sessions revoked."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/profile/sessions/{sessionId}": {
      "delete": {
        "summary": "Sign out a device",
        "description": "A session belonging to another user is reported as not found.",
        "tags": [
          "Auth"
        ],
        "operationId": "delete_v1_profile_sessions__sessionId_",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Session id."
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked."
          },
          "404": {
            "description": "No such active session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/profile/notification-preferences": {
      "get": {
        "summary": "Read notification preferences",
        "tags": [
          "Auth"
        ],
        "operationId": "get_v1_profile_notification-preferences",
        "responses": {
          "200": {
            "description": "The signed-in user’s email notification preferences."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      },
      "patch": {
        "summary": "Update notification preferences",
        "tags": [
          "Auth"
        ],
        "operationId": "patch_v1_profile_notification-preferences",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "security": {
                    "type": "boolean"
                  },
                  "connectionFailures": {
                    "type": "boolean"
                  },
                  "deliveryProblems": {
                    "type": "boolean"
                  },
                  "aiLimits": {
                    "type": "boolean"
                  },
                  "billingUsage": {
                    "type": "boolean"
                  },
                  "onboarding": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "deliveryProblems": false,
                "aiLimits": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated preferences."
          },
          "400": {
            "description": "The update was empty or unknown.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/profile/heard-from": {
      "put": {
        "summary": "Record how you heard about ChatRail",
        "description": "Asked once on the getting-started page. `skipped` records a dismissal so the question is not shown again. Answering again replaces the answer.",
        "tags": [
          "Auth"
        ],
        "operationId": "put_v1_profile_heard-from",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "source": {
                    "type": "string",
                    "enum": [
                      "google",
                      "ai_assistant",
                      "x",
                      "linkedin",
                      "youtube",
                      "reddit",
                      "github",
                      "n8n",
                      "friend",
                      "other",
                      "skipped"
                    ]
                  },
                  "detail": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": [
                  "source"
                ],
                "additionalProperties": false
              },
              "example": {
                "source": "linkedin",
                "detail": "A post about WhatsApp bots"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated profile."
          },
          "400": {
            "description": "The source was not one of the listed values.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/auth/request-code": {
      "post": {
        "summary": "Request a sign-in code",
        "description": "Always answers 202, whether or not the address has an account. It is not an existence check and must not be presented as one.",
        "tags": [
          "Auth"
        ],
        "operationId": "post_v1_auth_request-code",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "maxLength": 320,
                    "format": "email",
                    "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                  }
                },
                "required": [
                  "email"
                ],
                "additionalProperties": false
              },
              "example": {
                "email": "you@company.com"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "A code has been sent if that address has an account."
          }
        },
        "security": []
      }
    },
    "/v1/auth/verify": {
      "post": {
        "summary": "Exchange a code for a session",
        "description": "Every failure returns the same error — no code, wrong code, expired, too many attempts. Distinguishing them would reintroduce an oracle.",
        "tags": [
          "Auth"
        ],
        "operationId": "post_v1_auth_verify",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "maxLength": 320,
                    "format": "email",
                    "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                  },
                  "code": {
                    "type": "string",
                    "pattern": "^\\d{6}$"
                  }
                },
                "required": [
                  "email",
                  "code"
                ],
                "additionalProperties": false
              },
              "example": {
                "email": "you@company.com",
                "code": "123456"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A session cookie is set."
          },
          "401": {
            "description": "That code is not valid.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/v1/auth/session": {
      "get": {
        "summary": "Read the current session",
        "tags": [
          "Auth"
        ],
        "operationId": "get_v1_auth_session",
        "responses": {
          "200": {
            "description": "The signed-in user and workspace."
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/auth/logout": {
      "post": {
        "summary": "End the session",
        "tags": [
          "Auth"
        ],
        "operationId": "post_v1_auth_logout",
        "responses": {
          "204": {
            "description": "Signed out."
          }
        },
        "security": [
          {
            "session": []
          }
        ]
      }
    },
    "/v1/auth/providers": {
      "get": {
        "summary": "List sign-in providers",
        "description": "Which of Google and GitHub are switched on for this deployment, so a sign-in page only offers buttons that will work.",
        "tags": [
          "Auth"
        ],
        "operationId": "get_v1_auth_providers",
        "responses": {
          "200": {
            "description": "An object of provider name to boolean."
          }
        },
        "security": []
      }
    },
    "/v1/auth/oauth/{provider}/start": {
      "get": {
        "summary": "Start a Google or GitHub sign-in",
        "description": "A browser navigation, not an API call: redirects to the provider with a state value and a PKCE challenge held in a short-lived HttpOnly cookie. An optional same-origin `next` path is where the person lands afterwards.",
        "tags": [
          "Auth"
        ],
        "operationId": "get_v1_auth_oauth__provider__start",
        "parameters": [
          {
            "name": "provider",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "`google` or `github`."
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to the provider."
          },
          "404": {
            "description": "That provider is not configured.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/v1/auth/oauth/{provider}/callback": {
      "get": {
        "summary": "Finish a Google or GitHub sign-in",
        "description": "Where the provider sends the person back. Only an address the provider has verified is accepted; it lands in the same account an emailed code for that address would. Always redirects to the sign-in page — with a session cookie on success, or `auth_error` on failure.",
        "tags": [
          "Auth"
        ],
        "operationId": "get_v1_auth_oauth__provider__callback",
        "parameters": [
          {
            "name": "provider",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "`google` or `github`."
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to the sign-in page."
          }
        },
        "security": []
      }
    },
    "/v1/mcp": {
      "post": {
        "summary": "MCP endpoint",
        "description": "Model Context Protocol over a stateless streamable HTTP transport. OAuth 2.1 access tokens and workspace API keys are both accepted. Read-only by default; mutating tools preview and apply only when called again with `confirm: true`. No tool returns message content.",
        "tags": [
          "MCP"
        ],
        "operationId": "post_v1_mcp",
        "responses": {
          "200": {
            "description": "An MCP response."
          },
          "401": {
            "description": "Authentication is required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "MCP is not on this plan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": [
              "mcp:read"
            ]
          },
          {
            "oauth": [
              "mcp:read"
            ]
          }
        ],
        "x-scopes": [
          "mcp:read"
        ]
      }
    },
    "/v1/mcp/tools": {
      "get": {
        "summary": "List MCP tools",
        "description": "Available to dashboard sessions for setup and to API keys with `mcp:read`.",
        "tags": [
          "MCP"
        ],
        "operationId": "get_v1_mcp_tools",
        "responses": {
          "200": {
            "description": "The tools this credential may call."
          }
        },
        "security": [
          {
            "apiKey": []
          },
          {
            "session": []
          }
        ]
      }
    },
    "/healthz": {
      "get": {
        "summary": "Liveness",
        "description": "Never checks dependencies. Point a restart policy here, not a traffic probe.",
        "tags": [
          "Operational"
        ],
        "operationId": "get_healthz",
        "responses": {
          "200": {
            "description": "The process is alive."
          }
        },
        "security": []
      }
    },
    "/healthz/worker": {
      "get": {
        "summary": "Worker liveness",
        "description": "Whether the background worker has recorded a heartbeat in the last five minutes. For an external uptime monitor: the worker runs the other alerts, so it cannot report its own death.",
        "tags": [
          "Operational"
        ],
        "operationId": "get_healthz_worker",
        "responses": {
          "200": {
            "description": "The worker is alive."
          },
          "503": {
            "description": "No heartbeat in five minutes, or none ever recorded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/readyz": {
      "get": {
        "summary": "Readiness",
        "description": "Checks dependencies. Point the load balancer here.",
        "tags": [
          "Operational"
        ],
        "operationId": "get_readyz",
        "responses": {
          "200": {
            "description": "Ready."
          },
          "503": {
            "description": "A dependency is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/metrics": {
      "get": {
        "summary": "Prometheus metrics",
        "description": "Not registered unless `METRICS_TOKEN` is configured. No label carries a workspace, connection, number or session name.",
        "tags": [
          "Operational"
        ],
        "operationId": "get_metrics",
        "responses": {
          "200": {
            "description": "Exposition format."
          },
          "401": {
            "description": "Missing or wrong token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/v1/openapi.json": {
      "get": {
        "summary": "This document",
        "tags": [
          "Operational"
        ],
        "operationId": "get_v1_openapi_json",
        "responses": {
          "200": {
            "description": "The OpenAPI document."
          }
        },
        "security": []
      }
    }
  }
}
