{
 "openapi": "3.1.0",
 "info": {
  "title": "SendBuzzPro API",
  "version": "1.0.0",
  "description": "Email API for apps and AI agents with per-key budgets, approvals and a kill switch."
 },
 "servers": [
  {
   "url": "/v1"
  }
 ],
 "security": [
  {
   "bearer": []
  }
 ],
 "paths": {
  "/emails": {
   "post": {
    "summary": "Send one email",
    "description": "Body: from, to, cc, bcc, reply_to, subject, html, text, headers, tags, attachments [{filename, content (base64), content_type}], scheduled_at, request_approval, topic, unsubscribe, stream (transactional | marketing). Header: Idempotency-Key. Returns the email with its status: sent, queued, scheduled, held or suppressed.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/SendEmail"
       }
      }
     }
    },
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 200
      }
     }
    ]
   },
   "get": {
    "summary": "List emails",
    "description": "Query: status (comma separated), to, key_id, broadcast_id, stream, before, limit (≤100). Returns {data, has_more}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/batch": {
   "post": {
    "summary": "Send up to 500 emails",
    "description": "Body: an array of email objects. Returns {data, errors}; each email is accepted or refused on its own.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/streams": {
   "get": {
    "summary": "Message streams",
    "description": "transactional and marketing: paused or not (and why), health, sent / delivered / bounce / complaint numbers for 7 and 30 days, settings. An unsubscribe only blocks marketing.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/streams/{id}/pause": {
   "post": {
    "summary": "Pause a stream",
    "description": "Body: reason. New sends on it get 403 stream_paused, queued ones wait, the other stream keeps sending. API keys may pause (emails:send).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/streams/{id}/resume": {
   "post": {
    "summary": "Resume a stream",
    "description": "Console only (owner, admin). An automatic pause is 409 stream_auto_paused: appeal instead.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/streams/{id}/appeal": {
   "post": {
    "summary": "Appeal an automatic pause",
    "description": "Console only. Body: message (10+ characters). A person reviews it.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/streams/{id}": {
   "patch": {
    "summary": "Stream settings",
    "description": "Console only. Body: from_domain (only send this stream from that domain or its subdomains; empty clears it).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/{id}": {
   "get": {
    "summary": "Get an email",
    "description": "Status, reason and event timeline.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/{id}/raw": {
   "get": {
    "summary": "Raw message",
    "description": "The exact MIME message (message/rfc822).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/{id}/cancel": {
   "post": {
    "summary": "Cancel",
    "description": "Scheduled, queued or held emails.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/{id}/approve": {
   "post": {
    "summary": "Approve a held email",
    "description": "Console only (owner, admin or approver). Body: note (optional). Who approved it and the note are kept in the timeline and the audit log.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/{id}/reject": {
   "post": {
    "summary": "Reject a held email",
    "description": "Console only (owner, admin or approver). Body: note (the reason).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inboxes": {
   "post": {
    "summary": "Create an inbox",
    "description": "Body: username (optional; random if empty), domain (your verified domain with the receiving MX record, or empty for the shared domain), name. Use username \"*\" on your own domain for a catch-all.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "get": {
    "summary": "List inboxes",
    "description": "Addresses and unread conversation counts.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inboxes/{id}/threads": {
   "get": {
    "summary": "List conversations",
    "description": "Query: unread=true, limit, before.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inboxes/{id}/send": {
   "post": {
    "summary": "Start a conversation",
    "description": "Same body as /v1/emails; sent from the inbox address so replies come back to it.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/threads/{id}": {
   "get": {
    "summary": "Get a conversation",
    "description": "Every received and sent message, oldest first.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "patch": {
    "summary": "Mark read / unread",
    "description": "Body: {\"read\": true}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/messages/{id}": {
   "get": {
    "summary": "Get a received message",
    "description": "Text, HTML, attachments list, SPF/DKIM/DMARC/spam verdicts, is_auto (auto-replies, lists, bounces).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/messages/{id}/attachments/{index}": {
   "get": {
    "summary": "Download an attachment",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/messages/{id}/reply": {
   "post": {
    "summary": "Reply in the conversation",
    "description": "Body: text, html, reply_all, request_approval, attachments. Sets In-Reply-To and References. Same budgets as /v1/emails.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/budget": {
   "get": {
    "summary": "Remaining budget",
    "description": "This key's per-minute/hour/day/month use and limits, and the account plan.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/domains": {
   "get": {
    "summary": "List domains",
    "description": "With DNS records and per-record status.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/domains/{id}/check": {
   "post": {
    "summary": "Check DNS now",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/webhooks": {
   "get": {
    "summary": "List webhooks",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Add a webhook",
    "description": "Body: url, events (array, or [\"*\"]). Returns the signing secret once.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/webhooks/deliveries": {
   "get": {
    "summary": "Delivery log",
    "description": "Query: webhook_id, status (pending | delivered | dead).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/webhooks/replay": {
   "post": {
    "summary": "Replay deliveries",
    "description": "Body: delivery_id, or webhook_id to replay every dead delivery.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/contacts": {
   "post": {
    "summary": "Add or update a contact",
    "description": "Body: email, first_name, last_name, data, topics {topic_id: true|false}. Only people who opted in.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "get": {
    "summary": "List contacts",
    "description": "Query: search, topic, limit, offset.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/topics": {
   "get": {
    "summary": "List topics",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Create a topic",
    "description": "Body: name, description, default_in (true: everyone gets it unless they opt out; false: only people who subscribe).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts": {
   "get": {
    "summary": "List broadcasts",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Create a broadcast",
    "description": "Body: name, from, reply_to, subject, html, text, topic_id, and optionally template_id (a published template: its content is used and refreshed at send time), segment_id (only contacts in that segment), preview_text, ab_test {subjects: [2–3], percent (5–50), metric (opens | clicks), hours (1–72)} or null. Returns the broadcast with audience (how many would get it) and approval_required.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/suppressions": {
   "get": {
    "summary": "List suppressed addresses",
    "description": "Query: search, reason (bounce | complaint | unsubscribed | manual).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Suppress an address",
    "description": "Body: email.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/suppressions/{email}": {
   "delete": {
    "summary": "Remove a suppression",
    "description": "Console only (owner or admin); API keys get 403 console_only. URL-encode the address; confirm=true is required for a complaint.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/approvals": {
   "get": {
    "summary": "Recent approval decisions",
    "description": "Console only. Who approved or rejected each email, their role and note.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/members": {
   "get": {
    "summary": "List team members",
    "description": "Console only. Members, roles, pending invites and seats {used, limit}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Invite a member",
    "description": "Console only (owner or admin). Body: email, role (admin | developer | approver | viewer). Emails a one-time invite link, or returns invite_url when the server has no NOTIFY_FROM.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/members/{id}": {
   "patch": {
    "summary": "Change a role",
    "description": "Console only (owner or admin). Body: role. Applies to the member's sessions right away.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Remove a member",
    "description": "Console only (owner or admin). Signs them out everywhere.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/members/{id}/link": {
   "post": {
    "summary": "Resend an invite / sign-in link",
    "description": "Console only (owner or admin). Emailed, or returned as url when the server has no NOTIFY_FROM.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/login/email": {
   "post": {
    "summary": "Email me a sign-in link",
    "description": "No auth. Body: email. Same answer whether or not the address is a member.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/feedback": {
   "post": {
    "summary": "Send feedback",
    "description": "Signed in, signed out, or with an API key. Body: kind (problem | bug | idea | question), message (5–5000 characters), email (required when signed out; default: your email), page, ua, meta {viewport, theme, version}. Stored, then emailed to the SendBuzzPro team. Limits: 5 per IP an hour, 20 per workspace a day (429 feedback_rate_limited). MCP: send_feedback.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "get": {
    "summary": "Feedback you sent",
    "description": "Console only, owner. Your workspace's submissions, newest first: {data: [{id, kind, message, page, email, status, sent_by, created_at}]}. Query: limit (≤200).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/dashboard/layout": {
   "get": {
    "summary": "Your Overview layout",
    "description": "Console only, any role. Your own (owner or member) dashboard layout: {version: 1, range (7 | 14 | 30 | 90 days), widgets: [{id, size (1–3 columns), hidden}], customized, updated_at}. No saved layout: the default.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Save your Overview layout",
    "description": "Console only, any role. Body: {version: 1, range, widgets: [{id, size, hidden}]}, in display order. Unknown ids are dropped, sizes snap to what the widget allows, widgets left out are added hidden. At most 40 widgets and 8 KB (400 layout_too_large).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Reset your Overview layout",
    "description": "Console only. Back to the default layout.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/dashboard/stats": {
   "get": {
    "summary": "Dashboard stats",
    "description": "Console only. Query: days (7 | 14 | 30 | 90). {contacts: {total, unsubscribed, added, series: [{day, added, total}]}, templates: [{id, alias, name, sent}] (the 5 most-sent)}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/login/link": {
   "post": {
    "summary": "Use a sign-in link",
    "description": "No auth. Body: token. One use, 15 minutes. Sets the session cookie.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/config": {
   "get": {
    "summary": "Public settings",
    "description": "No auth. buyUrl, events, region, inboundDomain, and googleSignIn (true when Sign in with Google is set up; the sign-in page shows the button only then).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/auth/google/start": {
   "get": {
    "summary": "Sign in with Google",
    "description": "Browser only. Query: next (optional, a same-origin path such as /oauth/authorize?…; anything else is ignored). Redirects to Google with scope \"openid email profile\", PKCE S256 and a single-use state (10 minutes). 404 google_not_configured when the server has no Google client.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/auth/google/callback": {
   "get": {
    "summary": "Google sign-in: return",
    "description": "Browser only. Signs in as the person the Google account is linked to, else an active team member with that verified email (one workspace), else the license owner with that email; sets the session cookie and redirects to next. Otherwise redirects to #/login?google_error=no_account | unverified | several | state | denied | failed. Audited as auth.sign_in with method \"google\".",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/google": {
   "get": {
    "summary": "Linked Google account",
    "description": "Console only. The signed-in person's linked Google account: {linked: {email, linked_at, last_used} | null}. No Google tokens are stored.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Disconnect Google",
    "description": "Console only, any role. Unlinks your Google account; you keep your other sign-in methods.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/google/connect": {
   "post": {
    "summary": "Connect a Google account",
    "description": "Console only, any role. Returns {url}: open it to pick a Google account, which is then linked to you even if its email differs. A Google account can be linked to one person only (google_error=taken).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/invites/accept": {
   "post": {
    "summary": "Accept an invite",
    "description": "No auth. Body: token, name. One use, 7 days. Sets the session cookie.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/audit": {
   "get": {
    "summary": "Audit log",
    "description": "Console only (owner or admin); API keys have no scopes, so they can't read it. Query: action (e.g. key or key.created), actor, q, since, until (YYYY-MM-DD), before, limit (≤200), format=csv (up to 10,000 rows).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates": {
   "get": {
    "summary": "List templates",
    "description": "Query: search (name, alias or subject), status (published or draft), limit (≤200), offset. Returns {data, has_more}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Create a template",
    "description": "Body: name, alias (unique per account; made from the name if empty), subject, html, text, from (optional default), variables [{name, default?}], publish (true to publish right away). Merge tags: {{name}} or {{name|fallback}}; values are HTML-escaped in html and left as-is in text and subject. To send with it, POST /v1/emails (or a batch, or MCP send_email) with template (id or alias), variables {…} and optionally template_version (\"draft\" or a number; default: the published version); from is optional when the template has one, and subject, html or text you send override the template’s. A missing variable is refused with template_missing_variables.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}": {
   "get": {
    "summary": "Get a template",
    "description": "By id (tpl_…) or alias. The draft, declared and detected variables, and the published version.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "patch": {
    "summary": "Edit the draft",
    "description": "Any of name, alias, subject, html, text, from, variables. Sends keep using the published version until you publish.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Delete a template",
    "description": "Deletes the draft and every version. Sends that name it are refused with template_not_found.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/publish": {
   "post": {
    "summary": "Publish",
    "description": "Body: note (optional). Snapshots the draft as the next version number; sends use it from now on.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/versions": {
   "get": {
    "summary": "List versions",
    "description": "Newest first, with who published each one, the note and which one is current.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/versions/{n}": {
   "get": {
    "summary": "Get a version",
    "description": "The full content of version n (or \"published\" / \"latest\").",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/rollback": {
   "post": {
    "summary": "Roll back",
    "description": "Body: {\"version\": n}. Republishes version n as a new version number (history is never rewritten) and resets the draft to it.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/diff": {
   "get": {
    "summary": "Compare versions",
    "description": "Query: from, to (version numbers or \"draft\"; default: the latest version against the one before it). Returns {changed, fields: [{field, changed, from, to} or {field, changed, added, removed, lines: [{op: equal|add|remove, line, old, new}]}]}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/duplicate": {
   "post": {
    "summary": "Duplicate",
    "description": "Body: name, alias (both optional). Copies the draft into a new unpublished template.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/render": {
   "post": {
    "summary": "Render (preview)",
    "description": "Body: variables {…}, version (\"draft\" by default, \"published\" or a number), strict (true: refuse when a variable is missing). Returns {subject, html, text, missing_variables}. Sends nothing.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/contacts/{id}/properties": {
   "get": {
    "summary": "Get contact properties",
    "description": "Returns {contact_id, email, properties}. Values keep their type (string, number, boolean, object).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Set contact properties",
    "description": "Body: {properties: {key: value}}. Merges; a null value removes the key; replace: true drops keys you don't send. Keys: letters, numbers, _ . - (up to 64). Up to 100 per contact. Emits contact.updated.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/contacts/properties/batch": {
   "post": {
    "summary": "Set properties for many contacts",
    "description": "Body: {contacts: [{email, properties}], create_contact, consent} (up to 1,000). Unknown people are only added with create_contact and consent: true. Returns {updated, created, errors}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/events": {
   "post": {
    "summary": "Track a custom event",
    "description": "Body: name (e.g. trial.started), email, properties (≤8 KB; {{event.key}} in emails), create_contact, consent. Starts automations listening for the event. Returns {id, contact_id, automations_started, run_ids}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "get": {
    "summary": "List events",
    "description": "Query: contact_id, name, before, limit (≤200).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/segments": {
   "get": {
    "summary": "List segments",
    "description": "With rules and cached member counts.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Create a segment",
    "description": "Body: name, description, match (all | any), rules [{field, op, value, key?, days?}]. Fields: email (eq, contains, ends_with), email_domain (eq, neq), topic (subscribed, not_subscribed; value = topic id), property (eq, neq, contains, exists, not_exists, gt, lt; key), created_at (before, after, within_days), event (has, has_not; value = name, days optional), unsubscribed (is), suppressed (is).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/segments/preview": {
   "post": {
    "summary": "Preview rules",
    "description": "Body: {match, rules}. Returns {count, sample (up to 10)} without saving.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/segments/{id}": {
   "get": {
    "summary": "Get a segment",
    "description": "With a live member count.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "patch": {
    "summary": "Update a segment",
    "description": "Body: name, description, match, rules. People who now match get segment.joined; people who no longer do get segment.left.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Delete a segment",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/segments/{id}/contacts": {
   "get": {
    "summary": "Segment members",
    "description": "Query: limit (≤200), offset. Returns {data, total, has_more}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/automations": {
   "get": {
    "summary": "List automations",
    "description": "Status (draft | active | paused), trigger, steps, version and run counts.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Create an automation",
    "description": "Body: name, trigger, steps. Trigger: {type: \"contact.created\"} | {type: \"contact.subscribed\", topic_id} | {type: \"event\", event} | {type: \"segment.joined\", segment_id}; reentry: true lets a contact go through again after a finished run. Steps: wait {minutes|hours|days}, send_email {from, subject, html|text, reply_to?, topic_id?} or {template_id}, condition {match, rules, yes: [steps], no: [steps]}, add_to_topic / remove_from_topic {topic_id}, set_property {key, value}, webhook {data} (emits automation.step), end. Created as a draft.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/automations/{id}": {
   "get": {
    "summary": "Get an automation",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "patch": {
    "summary": "Update an automation",
    "description": "Body: name, description, trigger, steps. Once it has been on, a change makes a new version; running contacts finish on the version they started.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Delete an automation",
    "description": "Also deletes its runs.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/automations/{id}/enable": {
   "post": {
    "summary": "Turn on",
    "description": "Checks topics, segments and every email step (from domain verified, content). Only contacts who trigger it from now on start runs. Turned on with an API key, its emails count against that key's budgets.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/automations/{id}/disable": {
   "post": {
    "summary": "Pause",
    "description": "Running contacts wait where they are until it is turned on again.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/automations/{id}/duplicate": {
   "post": {
    "summary": "Duplicate",
    "description": "A draft copy.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/automations/{id}/runs": {
   "get": {
    "summary": "List runs",
    "description": "One run per contact. Query: status (running | completed | stopped | failed), before, limit.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/automations/{id}/runs/{run_id}": {
   "get": {
    "summary": "Get a run",
    "description": "Position, next step time and the step log (done, waiting, skipped, deferred, failed) with email ids.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/automations/{id}/stop-run/{run_id}": {
   "post": {
    "summary": "Stop a run",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/agents": {
   "get": {
    "summary": "Agents fleet",
    "description": "Console only. One row per API key: budgets (used, limit, percent per minute/hour/day/month), rate_ceiling, last_24h {sent, held, bounced, refused {total, by_code}}, waiting_approval, loop_guard {state: clear | recent | tripped, holds_24h, last_at}, state (active | paused | killed | stopped), killed {at, by, reason}, scopes, last_used. Plus the account’s plan budgets.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/agents/me": {
   "get": {
    "summary": "This key",
    "description": "With an API key: the same row for the key making the request, plus the account’s day and month use.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/agents/{id}/kill": {
   "post": {
    "summary": "Stop a key",
    "description": "Body: reason (optional). Sends with the key are refused (key_paused) and its queued or scheduled emails are held for a person. A key may stop itself (use id \"me\"), never another key. Audited and sent as agent.killed.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/agents/{id}/resume": {
   "post": {
    "summary": "Resume a key",
    "description": "Console only (owner or admin). A key can never resume itself. Emails held by the stop stay held until someone approves them. Audited and sent as agent.resumed.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/agents/kill-all": {
   "post": {
    "summary": "Stop every key",
    "description": "Console only (owner or admin). Turns on the account kill switch (same as POST /v1/account/kill-switch). Body: reason (optional).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/agents/resume-all": {
   "post": {
    "summary": "Resume every key",
    "description": "Console only (owner or admin). Turns the account kill switch off. Keys stopped one by one stay stopped.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/keys/{id}/scopes": {
   "get": {
    "summary": "A key’s scopes",
    "description": "Console only. [\"full\"] when no scopes were set.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Set a key’s scopes",
    "description": "Console only (owner, admin or developer). Body: scopes, any of emails:send, emails:read, inboxes:read, inboxes:write, contacts:read, contacts:write, templates:read, templates:write, automations:read, automations:write, domains:read, webhooks:read, webhooks:write, or full. A key without the scope a request needs gets scope_missing. MCP tools follow the same scopes.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/logs": {
   "get": {
    "summary": "Request log",
    "description": "API and MCP requests made with API keys: method, path, status, error_code, ms, at. Query: key_id, status (ok | error | 4xx | 429 | an error code), path (contains), method, before, limit (≤200). Returns {data, has_more, next_before}. A key sees its own requests unless it has the full scope. Kept for the plan’s history window.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/webhooks/{id}/dead-letters": {
   "get": {
    "summary": "Dead letters",
    "description": "Deliveries that used up every retry, with the payload and the last error. Replay them with POST /v1/webhooks/replay.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/webhooks/{id}/events": {
   "get": {
    "summary": "Event history",
    "description": "Every event sent to this endpoint. Query: type, status (pending | delivered | dead), before, limit. Returns {data, has_more, next_before}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/webhooks/{id}/rotate-secret": {
   "post": {
    "summary": "Rotate the signing secret",
    "description": "Console only. Returns the new secret once. The next delivery is signed with it; the old secret stops working right away.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/lint": {
   "post": {
    "summary": "Lint an email",
    "description": "Same body as /v1/emails. Returns {ok, problems, warnings, headroom}: each item has a code, a message and a fix (missing text part or unsubscribe, spammy words, all-caps subject, too many links, image-only HTML, size, unverified domain, suppressed recipients, budget headroom). Nothing is sent or counted.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/preflight": {
   "post": {
    "summary": "Preflight an email",
    "description": "Lint plus the verdict: {would: sent | scheduled | held | suppressed | simulated | refused, reason, code, fix, checks}. Runs every gate (validation, suppressions, kill switch, account health, key and plan budgets, approvals, loop guard) without sending or counting. Console callers can pass key_id to check a key’s budgets. Test mode: email to any address @test.sendbuzzpro.com (through POST /v1/emails, batch or MCP) is stored and gets real-looking events and webhooks, but never reaches SES and doesn’t count; delivered by default, bounce+…@ bounces, complaint+…@ complains. The kill switch and pauses still apply.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/{id}/explain": {
   "get": {
    "summary": "Explain an email",
    "description": "A plain-language story from the email’s events, reason and hold: {headline, story [{at, type, text}], bounce_class, next_steps}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/{id}/reschedule": {
   "post": {
    "summary": "Reschedule",
    "description": "Body: {scheduled_at} (ISO 8601, within 30 days). Only scheduled emails. Fires email.rescheduled.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails/bulk-cancel": {
   "post": {
    "summary": "Cancel many emails",
    "description": "Body: {ids: [...]} (up to 500), or {status: \"scheduled\" | \"held\"} with optional key_id. Returns {canceled, ids, not_cancelable}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/emails.csv": {
   "get": {
    "summary": "Export emails as CSV",
    "description": "Same filters as GET /v1/emails (status, to, key_id, broadcast_id, before) plus since and limit (≤10,000). Cells that start with = + - @ are prefixed with ' so spreadsheets don’t run them.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/why-not-sent": {
   "get": {
    "summary": "Why wasn’t this sent?",
    "description": "Query: to. The most recent refused, held, suppressed, failed or bounced email (or refusal) to that address, explained, plus its suppression entry.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/metrics": {
   "get": {
    "summary": "Metrics",
    "description": "Query: from, to (ISO, default the last 7 days, or 24 h for hours), interval (day | hour), key_id, domain. Returns {series [{start, sent, delivered, bounced, complained, opened, clicked, held, failed, rejected, suppressed, canceled, refused}], totals, rates}. Test-mode email is left out.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/deliverability": {
   "get": {
    "summary": "Deliverability by domain",
    "description": "For each sending domain over 7 and 30 days: sent, delivered, hard and soft bounces, complaints and rates; where it stands against the thresholds (ok, warning at 2% bounces or 0.05% complaints, at_risk at 4% or 0.08%); a daily trend; bounce types with fixes; DKIM, SPF and DMARC status (and the DMARC policy).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/deliverability/{domain}": {
   "get": {
    "summary": "Deliverability for one domain",
    "description": "The same, plus its 25 most recent bounces and complaints.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/oauth/grants": {
   "get": {
    "summary": "Connected AI apps",
    "description": "Console only. Apps connected to the MCP server with a sign-in (OAuth): name, who connected it, last use, and the API key it acts through (its budgets apply).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/oauth/grants/{client_id}": {
   "delete": {
    "summary": "Disconnect an AI app",
    "description": "Console only (owner or admin). Signs the app out everywhere (every token is revoked) and deletes its API key. Its past emails keep their history.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/.well-known/oauth-protected-resource": {
   "get": {
    "summary": "OAuth: resource metadata",
    "description": "No auth. RFC 9728 metadata for /mcp. /mcp answers 401 with WWW-Authenticate: Bearer resource_metadata=\"…\" when there is no key or sign-in.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/.well-known/oauth-authorization-server": {
   "get": {
    "summary": "OAuth: server metadata",
    "description": "No auth. RFC 8414 metadata: authorize, token, register and revoke endpoints; PKCE S256; public clients only.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/oauth/register": {
   "post": {
    "summary": "OAuth: register an app",
    "description": "No auth. RFC 7591 dynamic client registration. Body: client_name, redirect_uris (https, http://localhost or an app scheme). Returns client_id.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/oauth/authorize": {
   "get": {
    "summary": "OAuth: consent page",
    "description": "Query: response_type=code, client_id, redirect_uri, code_challenge, code_challenge_method=S256, state. Signed-out people sign in first. Owners, admins and developers can approve; the app gets its own API key with default budgets.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/oauth/token": {
   "post": {
    "summary": "OAuth: get tokens",
    "description": "Form or JSON. grant_type=authorization_code (code, client_id, redirect_uri, code_verifier) or grant_type=refresh_token. Access tokens (ml_oat_…) last 1 hour; refresh tokens rotate on every use and last 60 days.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/oauth/revoke": {
   "post": {
    "summary": "OAuth: revoke a token",
    "description": "RFC 7009. Body: token (access or refresh). Always 200.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/reports": {
   "get": {
    "summary": "Scheduled reports",
    "description": "Each schedule (frequency, weekday/monthday, send_time and timezone, recipients, member_ids, sections, format, branding, enabled, next_run_at) with its last run, the section ids you can pick (the dashboard widgets) and the workspace limits.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Create a scheduled report",
    "description": "Owner, admin or developer. Body: name, frequency (daily | weekly | monthly), weekday (0–6), monthday (1–28), send_time (HH:MM), timezone (IANA), recipients (emails), member_ids, sections, format (pdf | email), branding {client_name, logo_url, accent}, enabled. Each run covers the previous period (yesterday, the 7 days before, last month) in that time zone. At most 20 schedules, 20 recipients each and 50 in total.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/reports/{id}": {
   "patch": {
    "summary": "Change a report",
    "description": "Any of the fields above. DELETE /v1/reports/{id} deletes it and its history.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/reports/{id}/preview": {
   "get": {
    "summary": "Preview a report",
    "description": "The report as HTML for the last complete period. POST /v1/reports/preview previews an unsaved draft (same body as create).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/reports/{id}/send": {
   "post": {
    "summary": "Send a report now",
    "description": "Body: {test: true} sends only to you (the person signed in); otherwise it goes to every recipient for the last complete period. 10 by hand per report an hour.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/reports/{id}/runs": {
   "get": {
    "summary": "Report history",
    "description": "Every run: kind (scheduled | manual | test), period, status (pending | sending | sent | failed), attempts (failed runs retry up to 3 times), how many were sent. GET /v1/reports/runs/{run_id}/download?format=pdf|html downloads it again.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/reports/logo": {
   "post": {
    "summary": "Upload a logo",
    "description": "Body: {content (base64), content_type (image/png, jpeg, gif or webp)}, under 200 KB. Returns {url} for branding.logo_url or a portal.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/portals": {
   "get": {
    "summary": "Client portals",
    "description": "Owner or admin to change. A portal is a read-only page at /portal/{token} with chosen sections for chosen domains/tags. POST {name, logo_url, accent, scope {domains, tags [\"key:value\"]}, sections, password?, expires_at?} returns the link once (it is stored hashed). PATCH /v1/portals/{id}; POST …/revoke; POST …/rotate (new link); DELETE.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/approval-links": {
   "get": {
    "summary": "Client approval links",
    "description": "Requests for a client to approve a broadcast or template draft at /portal/approve/{token} without signing in. POST {kind: broadcast | template, target_id, client_name, expires_days} returns the link once. While a request is open, sending the broadcast or publishing the template is refused (client_approval_required) until it is approved; an edit after approval needs a new approval (changed_since_approval).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/approval-links/{id}/approve": {
   "post": {
    "summary": "Approve for the client",
    "description": "Console only, approver role or above. Body: {comment}. POST …/cancel cancels the request; GET …/events lists every view and decision with IP, browser and time.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/login/two-factor": {
   "post": {
    "summary": "Finish a two-step sign-in",
    "description": "No auth. When two-step verification is on, POST /v1/login, /v1/login/link, /v1/invites/accept and the Google callback don't start a session: they return {two_factor: \"verify\" | \"enroll\", pending} (Google redirects to #/login?two_factor=…&pending=…). Body: pending, code (6 digits from the authenticator app, or a recovery code). Sets the session cookie. Pending sign-ins work once, for 10 minutes and 5 tries; 5 wrong codes per account in 10 minutes → 429 two_factor_rate_limited.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/login/two-factor/setup": {
   "post": {
    "summary": "Set up two-step during sign-in",
    "description": "No auth. Body: pending (kind \"enroll\": the owner requires two-step for members). Returns {secret, secret_grouped, otpauth_uri}; then POST /v1/login/two-factor with a code turns it on and returns recovery_codes.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/two-factor": {
   "get": {
    "summary": "Your two-step verification",
    "description": "Console only, any role. {enabled, enabled_at, recovery_codes_left, required, policy: {require_members, can_change}}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/two-factor/setup": {
   "post": {
    "summary": "Start two-step setup",
    "description": "Console only. A new TOTP secret (RFC 6238, SHA-1, 6 digits, 30 s): {secret, secret_grouped, otpauth_uri}. Not on until enabled.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/two-factor/enable": {
   "post": {
    "summary": "Turn on two-step",
    "description": "Console only. Body: code. Returns 10 one-time recovery_codes (shown once, stored hashed). Audited as two_factor.enabled.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/two-factor/disable": {
   "post": {
    "summary": "Turn off two-step",
    "description": "Console only. Body: code (or a recovery code). Refused with two_factor_required while the owner requires it for members. Audited.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/two-factor/recovery-codes": {
   "post": {
    "summary": "New recovery codes",
    "description": "Console only. Body: code (from the app). The old codes stop working.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/two-factor/policy": {
   "get": {
    "summary": "Team two-step policy",
    "description": "Console only (owner or admin). {require_members, members: [{id, email, role, two_factor}]}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Require two-step for the team",
    "description": "Console only, owner. Body: {require_members: true|false}. Members without it set it up at their next sign-in.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/sessions": {
   "get": {
    "summary": "Your signed-in sessions",
    "description": "Console only. {data: [{id, current, ip, user_agent, method, created_at, last_used, expires_at}]}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/sessions/{id}": {
   "delete": {
    "summary": "Sign out a session",
    "description": "Console only. Audited as session.revoked.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/account/sessions/revoke-others": {
   "post": {
    "summary": "Sign out everywhere else",
    "description": "Console only. Every session of yours except this one.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/alerts": {
   "get": {
    "summary": "Alert destinations",
    "description": "Console only. Slack, Discord and webhook destinations (URLs masked) and the alert types: bounce_spike, domain_failed, kill_switch, webhook_failing, quota_80, quota_100.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Add an alert destination",
    "description": "Console only (owner, admin, developer). Body: kind (slack | discord | webhook), url (https://hooks.slack.com/services/…, https://discord.com/api/webhooks/…, or any public https URL), name, events [alert types], quiet_hours {start \"HH:MM\", end, timezone} | null, enabled. Up to 20.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/alerts/{id}": {
   "patch": {
    "summary": "Change an alert destination",
    "description": "Console only. Any field of POST.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Remove an alert destination",
    "description": "Console only.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/alerts/{id}/test": {
   "post": {
    "summary": "Send a test alert",
    "description": "Console only. Body: alert (optional type). Posts right away, ignoring quiet hours; returns the delivery.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/alerts/deliveries": {
   "get": {
    "summary": "Alert delivery log",
    "description": "Console only. The last 50: {id, destination, alert, title, status (pending | quiet | sent | failed), attempts, last_code, last_error, created_at, sent_at}. Query: destination_id. Failed posts retry 5 times over ~8 hours.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/status": {
   "get": {
    "summary": "Status page",
    "description": "Public HTML: API, sending, dashboard and webhooks with their current state (from the last 15 minutes of errors, the send queue and cron runs), open incidents and 90-day uptime bars.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/status.json": {
   "get": {
    "summary": "Status (JSON)",
    "description": "Public. {status, components [{id, name, status, detail}], incidents, recent_incidents, uptime {component: {percent, days [{day, status, uptime}]}}}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/admin/status/incidents": {
   "post": {
    "summary": "Post an incident",
    "description": "Instance owner: Authorization: Bearer STATUS_ADMIN_KEY. Body: title, message, status (investigating | identified | monitoring | resolved | scheduled | in_progress | completed), impact (minor | major | maintenance), components. Also GET (list), PATCH /admin/status/incidents/{id} {status, message} and DELETE.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/design": {
   "get": {
    "summary": "Visual design of a template",
    "description": "Returns {template_id, mode: \"visual\" | \"code\", design | null, updated_at}. The design is the visual builder’s JSON: {version: 1, settings: {width (320–800), background, content_background, brand_color, text_color, font}, blocks: [...]}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Save a visual design",
    "description": "Body: design, subject (optional), publish (optional), note. Renders table-based, inline-styled HTML (Outlook-safe width, mobile stacking, light/dark meta) and a plain-text version into the template’s draft, and keeps the JSON so it can be edited again. Block types: heading {text, level}, text {html: bold/italic/underline/links only}, button {label, url, button_color, button_text_color, radius}, image {src (https URL), alt, href, width}, divider {thickness, line_color}, spacer {height}, columns {columns: 2 or 3 lists of blocks}, social {links: [{network, url}]}, footer {html; use {{unsubscribe_url}} and {{preferences_url}}}, html {html}. Every block takes style {padding [t, r, b, l], align, color, background, font (Arial, Helvetica, Georgia, Times New Roman, Verdana, Tahoma, Trebuchet MS, Courier New), font_size}. Errors: invalid_design, design_too_large.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Back to the code editor",
    "description": "Drops the design; the HTML stays.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/design-preview": {
   "post": {
    "summary": "Render a design",
    "description": "Body: design, preview_text. Returns {html, text, react_email} without saving.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/react-email": {
   "get": {
    "summary": "Export as React Email",
    "description": "Returns {filename, code}: a .tsx file using @react-email/components. Merge tags stay as text.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/test": {
   "post": {
    "summary": "Send a test of the draft",
    "description": "Body: to (1–5 addresses), from (default: the template’s), variables. Subject gets “[Test]”. Budgets and suppressions apply.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts/{id}": {
   "patch": {
    "summary": "Edit a draft broadcast",
    "description": "Same fields; fields you leave out keep their value. Editing an approved draft needs a new approval.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts/{id}/send": {
   "post": {
    "summary": "Send or schedule a broadcast",
    "description": "Console only. Body: scheduled_at (optional), send_time (optional, see Send-time optimization; not with an A/B test). Every broadcast, however it was created (console, API, MCP or the Resend-compatible API), goes this way and every email gets List-Unsubscribe + List-Unsubscribe-Post (one-click, RFC 8058) and a footer linking the hosted preference center. Checks the from domain, the audience, your plan and the kill switch, then queues one email per contact (sent in batches each minute). When the team has an approver, the broadcast waits for approval instead (approval.status = pending; approvers are emailed). With an A/B test, the test group gets the subjects first (status testing) and the rest wait for the winner.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts/{id}/approve": {
   "post": {
    "summary": "Approve a broadcast",
    "description": "Console only (owner, admin or approver). Body: note. Sends (or schedules, with the send_time asked for) it right away. Refused with client_approval_required while a client approval link for it is open.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts/{id}/reject": {
   "post": {
    "summary": "Reject a broadcast",
    "description": "Console only (owner, admin or approver). Body: note (the reason). It stays a draft.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts/{id}/ab/decide": {
   "post": {
    "summary": "Pick the A/B winner now",
    "description": "Console only. Body: variant (optional; default: the best open or click rate so far). The rest of the audience gets that subject. The cron does this by itself after ab_test.hours.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts/{id}/cancel": {
   "post": {
    "summary": "Cancel a broadcast",
    "description": "Stops emails not sent yet, a running A/B test, or a pending approval.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts/{id}/test": {
   "post": {
    "summary": "Send a test copy",
    "description": "Body: to (1–5 addresses). Subject gets “[Test]”.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/broadcasts/{id}/report": {
   "get": {
    "summary": "Broadcast stats",
    "description": "Returns {sent, delivered, opened, clicked, unsubscribed, bounced, complained, failed, rates {delivery, open, click, unsubscribe, bounce, complaint} (percent), links: [{url, clicks, unique_clicks}], ab_test {metric, winner, variants: [{variant, subject, sent, opens, clicks, open_rate, click_rate}]}}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/p/{token}": {
   "get": {
    "summary": "Hosted preference center",
    "description": "No auth (signed link in every broadcast footer, merge tag {{preferences_url}}; {{unsubscribe_url}} opens it with ?unsubscribe=1). The recipient unsubscribes from all, picks topics, or fixes their name. Branded with your preference center settings.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/p/{token}/one-click": {
   "post": {
    "summary": "One-click unsubscribe (RFC 8058)",
    "description": "No auth. Body: List-Unsubscribe=One-Click. Every broadcast email has List-Unsubscribe: <…/p/{token}/one-click> and List-Unsubscribe-Post: List-Unsubscribe=One-Click. Unsubscribes from the broadcast’s topic, or from everything when it has none. Fires contact.unsubscribed.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/preference-center": {
   "get": {
    "summary": "Preference center branding",
    "description": "Returns {brand_name, logo_url, brand_color, footer, example_url}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Brand the preference center",
    "description": "Owner, admin or developer. Body: brand_name, logo_url (https), brand_color (#RRGGBB), footer (e.g. your postal address).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/topics/{id}": {
   "patch": {
    "summary": "Edit a topic",
    "description": "Body: name, description, default_in.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Delete a topic",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/contacts/{id}/topics": {
   "get": {
    "summary": "A contact’s topics",
    "description": "Returns {contact_id, email, unsubscribed, topics: [{id, name, description, default_in, subscribed, explicit}]}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Set a contact’s topics",
    "description": "Body: topics {topic_id: true | false}. Fires contact.topic_updated with what changed. Sends with \"topic\" (and broadcasts to a topic) only reach contacts subscribed to it; others are suppressed.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/contacts/{id}/preferences-url": {
   "get": {
    "summary": "A contact’s preference link",
    "description": "Returns {url}: their signed preference center link.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/domains": {
   "get": {
    "summary": "Inbound domains",
    "description": "Receiving domains for inbound parsing, with the MX records to add (default: 10 mx.sendbuzzpro.com, SendBuzzPro’s inbound mail server; operators can change it with INBOUND_MX_HOSTS), their status and the DMARC report address dmarc@<domain>.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Add an inbound domain",
    "description": "Owner or admin (developers too). Body: name (a subdomain you control, e.g. in.example.com), webhook_url (optional default endpoint). Returns the domain with its MX records.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/domains/{id}/check": {
   "post": {
    "summary": "Check MX records",
    "description": "Looks the MX records up over DNS; verified once one points at us.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/domains/{id}": {
   "patch": {
    "summary": "Update an inbound domain",
    "description": "Body: webhook_url, enabled.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Remove an inbound domain",
    "description": "Mail to it is refused from then on.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/domains/{id}/secret": {
   "get": {
    "summary": "Inbound signing secret",
    "description": "Console only. Each inbound POST has ml-signature: t=<unix>,v1=<hex HMAC-SHA256 of \"t.body\"> with this secret, like webhooks.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/routes": {
   "get": {
    "summary": "Routing rules",
    "description": "Query: domain_id. Rules are checked in order (position), first match wins; no match → the domain’s webhook_url.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Add a routing rule",
    "description": "Body: domain_id, pattern (local part or address with * wildcards: support, billing+*, *, *@in.example.com), url, position.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/routes/{id}": {
   "patch": {
    "summary": "Update a routing rule",
    "description": "Body: pattern, url, position, enabled.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Delete a routing rule",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/messages": {
   "get": {
    "summary": "Parsed inbound email",
    "description": "Query: domain_id, status (pending | delivered | failed | no_route | stored), before, limit. Each message: from, to, subject, attachments, is_spam, auth {spf, dkim, dmarc}, delivery status and attempts.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/messages/{id}": {
   "get": {
    "summary": "One parsed email",
    "description": "Plus payload: exactly what was POSTed (see “Inbound parsing” below).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/inbound/messages/{id}/redeliver": {
   "post": {
    "summary": "Redeliver",
    "description": "POSTs the stored payload again. Failed POSTs also retry by themselves 6 times over ~20 hours.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/ips/pools": {
   "get": {
    "summary": "IP pools",
    "description": "Dedicated IP pools: ips, the sending domains that use them (domains) and ready (IPs assigned).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Create an IP pool",
    "description": "Body: name, domains.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/ips/pools/{id}": {
   "patch": {
    "summary": "Update an IP pool",
    "description": "Body: name, domains (your sending domains; a domain belongs to one pool). Email from those domains goes out through the pool.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/ips/requests": {
   "get": {
    "summary": "Dedicated IP requests",
    "description": "Requests and their status: requested, provisioning, active, declined.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Request dedicated IPs",
    "description": "Console only, owner or admin, paid plans. Body: count (1–4), pool_name, note. SendBuzzPro leases the IPs in Amazon SES and fills the pool; a 30-day warmup starts by itself.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/warmup": {
   "get": {
    "summary": "Warmup plans",
    "description": "Each plan: target_type (pool | domain), target, curve (emails allowed per day), day, today {cap, sent, remaining, deferred, overflowed}, history and overflow.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Start a warmup",
    "description": "Body: target_type, target (pool id or domain), curve (array of daily volumes, optional), or days (5–60) and target_volume for a generated ramp; overflow: queue (send the rest tomorrow) or shared (send it through the shared pool). Enforced right before SES.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/warmup/{id}": {
   "patch": {
    "summary": "Change a warmup",
    "description": "Body: curve, overflow, status (active | paused).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Stop a warmup",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/blocklists": {
   "get": {
    "summary": "Blocklist status",
    "description": "Every verified sending domain and sending IP against Spamhaus ZEN/DBL, Barracuda, SpamCop, SORBS, Mailspike, PSBL, URIBL and SURBL: state (listed | clear | error | unchecked) per list, with removal links. Checked daily; a new listing fires deliverability.blocklisted and emails the owner.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/blocklists/check": {
   "post": {
    "summary": "Check blocklists now",
    "description": "At most every 10 minutes.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/dmarc": {
   "get": {
    "summary": "DMARC reports",
    "description": "Query: days (1–90), domain. Returns rua {address, record}, totals, series [{day, pass, fail}], sources [{source_ip, count, spf_pass, dkim_pass, dmarc_pass, status: authorized | partly_failing | unknown}], unknown_senders and the latest reports.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/send-time": {
   "get": {
    "summary": "Send-time overview",
    "description": "The workspace’s best hour (learned from opens and clicks in each person’s local time; 10:00 until there are enough), the hour histogram, timezone coverage and the default timezone.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/send-time/contacts/{email}": {
   "get": {
    "summary": "One person’s send time",
    "description": "timezone (contact field “timezone”, or inferred from the IP of past opens), best_hour, and when a send_time \"best\" email would go out.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/send-time/settings": {
   "put": {
    "summary": "Default timezone",
    "description": "Body: default_timezone (IANA, e.g. Europe/London), used for people whose timezone is unknown.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/send-time/preview": {
   "post": {
    "summary": "Preview a send time",
    "description": "Body: email, send_time. Returns send_at.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/contacts/{id}/engagement": {
   "get": {
    "summary": "A contact’s engagement",
    "description": "Returns engagement (hot | warm | cold | never_engaged | new), engagement_score (0–100), last_engaged_at, last_opened_at, last_clicked_at, opens_90d, clicks_90d, received_90d, list_health {state: reengaging | sunset | null}, recent opens and clicks (machine opens flagged), interests, top_interest and scores. GET /v1/contacts and GET /v1/contacts/{id} also carry engagement, engagement_score, last_engaged_at, sunset, interests and top_interest; GET /v1/contacts takes ?engagement=hot (or sunset) and ?interest=shoes.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/contacts/{id}/interests": {
   "get": {
    "summary": "A contact’s interests",
    "description": "Returns {interests, top_interest, scores: [{interest, score, last_at, source: click | event | manual}], half_life_days: 30}. Scores decay with a 30-day half-life.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Set a contact’s interests",
    "description": "Body: {interests: [...]} replaces the list, or {add: [...], remove: [...]}. Lower-case, up to 40 characters each. Also kept in the contact property “interests” (a JSON array) and the merge tags {{interests}} / {{top_interest}}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/engagement/settings": {
   "get": {
    "summary": "Engagement settings",
    "description": "Returns {ignore_machine_opens, thresholds {hot, warm, new_days}}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Change engagement settings",
    "description": "Owner, admin or developer. Body: ignore_machine_opens (opens within 2 s of delivery or from proxy / scanner user agents are flagged “machine:” and left out of open rules, open triggers and the score), thresholds {hot, warm (1 ≤ warm < hot ≤ 100), new_days}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/engagement/mix": {
   "get": {
    "summary": "Engagement mix",
    "description": "Subscribed contacts per level, plus sunset and reengaging counts.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/link-rules": {
   "get": {
    "summary": "Link rules",
    "description": "URL pattern → interests. ?url=… returns the interests a click on that URL would add.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Add a link rule",
    "description": "Body: op (contains | eq | prefix | matches_domain), pattern, interests. Up to 200.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/link-rules/{id}": {
   "patch": {
    "summary": "Edit a link rule",
    "description": "Body: op, pattern, interests.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Delete a link rule",
    "description": "",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/link-rules/by-url": {
   "put": {
    "summary": "Interests for one link",
    "description": "Body: url, interests (empty removes them). What the visual builder’s button settings use.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/link-rules/test": {
   "post": {
    "summary": "Test link rules",
    "description": "Body: url. Returns the interests a click would add.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/list-health": {
   "get": {
    "summary": "List health settings",
    "description": "Returns {enabled, days, min_received, sunset_days, automation, last_run_at}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "summary": "Set up list health",
    "description": "Body: enabled, days (7–730, default 90: no open, click or event for this long), min_received (default 5 emails), sunset_days (default 30), automation_id (empty: a “We miss you” flow is created and turned on — 2 emails 7 days apart with a Keep-me-subscribed button).",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/list-health/report": {
   "get": {
    "summary": "List health report",
    "description": "Engagement mix, enrolled / re-engaged / sunset in 90 days, and an estimate of the open and bounce + complaint rates without unengaged contacts.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/list-health/run": {
   "post": {
    "summary": "Run list health now",
    "description": "Console only, once a minute. It also runs every hour.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/preview": {
   "post": {
    "summary": "Preview as a contact",
    "description": "Viewers too. Body: contact_id or email (a real contact), or variables (sample data; leave everything out for Ada Lovelace), version (draft | published | n). Returns the exact subject, preview_text, html and text that person gets, missing_variables, context {interests, top_interest, engagement, engagement_score}, conditions [{line, kind, expr, matched, branch}] (which {{#if}} branches matched), segments [{ref, id, name, matched}] and events [{name, happened}].",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/templates/{id}/preview-segments": {
   "post": {
    "summary": "Preview segments",
    "description": "One render per interest (has_interest \"…\") and segment (in_segment \"…\") the template mentions, plus “Everyone else”, each with a real contact from that group when there is one (else sample data). Returns {data: [{label, kind, contact, subject, html, text, conditions}]}.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/personalization/preview": {
   "post": {
    "summary": "Preview unsaved content",
    "description": "Like the template preview, for content that isn’t saved yet. Body: subject, html, text, preview_text, or design (a visual-builder design), plus contact_id / email / variables.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/personalization/preview-segments": {
   "post": {
    "summary": "Compare unsaved content by segment",
    "description": "Body as above.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/personalization/validate": {
   "post": {
    "summary": "Check template syntax",
    "description": "Body: subject, html, text, ab_subjects. Returns {ok, variables, refs} or 400 template_syntax_error with the line, column and a fix.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/personalization/starters": {
   "get": {
    "summary": "Starter designs",
    "description": "The “Picked for you” visual design: a dynamic section by interest (shoes / bags / everyone else) with three product cards each. PUT it to /v1/templates/{id}/design.",
    "responses": {
     "200": {
      "description": "OK"
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer"
   }
  },
  "schemas": {
   "SendEmail": {
    "type": "object",
    "required": [
     "from",
     "to",
     "subject"
    ],
    "properties": {
     "from": {
      "type": "string"
     },
     "to": {
      "oneOf": [
       {
        "type": "string"
       },
       {
        "type": "array",
        "items": {
         "type": "string"
        }
       }
      ]
     },
     "cc": {
      "oneOf": [
       {
        "type": "string"
       },
       {
        "type": "array",
        "items": {
         "type": "string"
        }
       }
      ]
     },
     "bcc": {
      "oneOf": [
       {
        "type": "string"
       },
       {
        "type": "array",
        "items": {
         "type": "string"
        }
       }
      ]
     },
     "reply_to": {
      "oneOf": [
       {
        "type": "string"
       },
       {
        "type": "array",
        "items": {
         "type": "string"
        }
       }
      ]
     },
     "subject": {
      "type": "string"
     },
     "html": {
      "type": "string"
     },
     "text": {
      "type": "string"
     },
     "headers": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      }
     },
     "tags": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      }
     },
     "scheduled_at": {
      "type": "string",
      "format": "date-time"
     },
     "request_approval": {
      "type": "boolean"
     },
     "attachments": {
      "type": "array",
      "items": {
       "type": "object",
       "required": [
        "filename",
        "content"
       ],
       "properties": {
        "filename": {
         "type": "string"
        },
        "content": {
         "type": "string",
         "contentEncoding": "base64"
        },
        "content_type": {
         "type": "string"
        }
       }
      }
     }
    }
   },
   "Error": {
    "type": "object",
    "properties": {
     "error": {
      "type": "object",
      "properties": {
       "code": {
        "type": "string",
        "enum": [
         "agent_budget_exceeded",
         "plan_daily_limit",
         "plan_monthly_limit",
         "lifetime_pool_used",
         "sending_paused",
         "key_paused",
         "account_paused",
         "domain_not_added",
         "domain_not_verified",
         "invalid_from",
         "invalid_recipient",
         "missing_recipient",
         "too_many_recipients",
         "missing_subject",
         "subject_too_long",
         "missing_content",
         "invalid_header",
         "invalid_attachment",
         "message_too_large",
         "invalid_scheduled_at",
         "invalid_batch",
         "batch_too_large",
         "idempotency_conflict",
         "invalid_idempotency_key",
         "invalid_api_key",
         "unauthorized",
         "console_only",
         "role_forbidden",
         "seat_limit",
         "member_exists",
         "member_not_found",
         "owner_protected",
         "invalid_role",
         "invite_invalid",
         "link_invalid",
         "feedback_email_required",
         "feedback_too_short",
         "feedback_too_long",
         "invalid_feedback",
         "invalid_layout",
         "layout_too_large",
         "feedback_rate_limited",
         "invalid_email",
         "bad_origin",
         "not_held",
         "not_cancelable",
         "email_not_found",
         "provider_error",
         "invalid_domain",
         "domain_taken",
         "domain_limit",
         "domain_not_found",
         "invalid_webhook_url",
         "invalid_events",
         "consent_required",
         "invalid_contact_email",
         "empty_audience",
         "broadcast_locked",
         "complaint_suppression",
         "inbox_limit",
         "address_taken",
         "username_reserved",
         "invalid_username",
         "no_inbound_domain",
         "catch_all_shared",
         "thread_not_found",
         "message_not_found",
         "inbox_not_found",
         "attachment_not_found",
         "invalid_json",
         "not_found",
         "server_error",
         "template_not_found",
         "template_not_published",
         "template_missing_variables",
         "template_version_not_found",
         "template_alias_taken",
         "invalid_template_alias",
         "missing_template_name",
         "invalid_template_variables",
         "invalid_template",
         "invalid_template_version",
         "template_invalid",
         "template_unchanged",
         "template_too_large",
         "template_publish_conflict",
         "invalid_properties",
         "invalid_property",
         "too_many_properties",
         "unknown_contact",
         "contact_suppressed",
         "contact_not_found",
         "invalid_event_name",
         "event_too_large",
         "invalid_segment_rule",
         "segment_not_found",
         "segment_limit",
         "invalid_automation",
         "automation_not_found",
         "automation_limit",
         "run_not_found",
         "run_not_running",
         "templates_unavailable",
         "template_not_found",
         "key_revoked",
         "missing_name",
         "scope_missing",
         "invalid_scopes",
         "not_own_key",
         "not_a_key",
         "key_not_found",
         "mixed_test_recipients",
         "not_scheduled",
         "invalid_bulk_cancel",
         "invalid_interval",
         "invalid_range",
         "range_too_large",
         "key_not_found",
         "google_not_configured",
         "google_not_linked",
         "oauth_token_invalid",
         "grant_not_found",
         "missing_argument",
         "invalid_report",
         "invalid_timezone",
         "report_recipient_limit",
         "report_limit",
         "report_rate_limited",
         "email_not_configured",
         "client_approval_required",
         "changed_since_approval",
         "invalid_logo",
         "two_factor_invalid_code",
         "two_factor_expired",
         "two_factor_rate_limited",
         "two_factor_required",
         "two_factor_setup_first",
         "invalid_alert_url",
         "invalid_alert_events",
         "invalid_quiet_hours",
         "session_not_found",
         "invalid_incident",
         "invalid_design",
         "design_too_large",
         "no_design",
         "invalid_test_recipients",
         "invalid_ab_test",
         "broadcast_template_unusable",
         "approval_pending",
         "not_pending",
         "not_testing",
         "unknown_topic",
         "invalid_logo_url",
         "invalid_brand_color",
         "invalid_send_time",
         "send_time_conflict",
         "inbound_domain_not_found",
         "invalid_pattern",
         "no_route",
         "plan_required",
         "invalid_curve",
         "warmup_exists",
         "checked_recently",
         "invalid_thresholds",
         "invalid_interests",
         "invalid_link_rule",
         "link_rule_not_found",
         "link_rule_limit",
         "invalid_engagement_levels",
         "invalid_engagement",
         "invalid_list_health",
         "template_syntax_error",
         "template_render_limit",
         "contact_not_found",
         "no_provider",
         "provider_unsupported",
         "invalid_stream",
         "stream_mismatch",
         "stream_paused",
         "stream_from_domain",
         "stream_auto_paused",
         "not_auto_paused",
         "appeal_too_short",
         "stream_not_found"
        ]
       },
       "message": {
        "type": "string"
       },
       "fix": {
        "type": "string"
       },
       "docs_url": {
        "type": "string"
       }
      }
     }
    }
   }
  }
 }
}