{
  "openapi": "3.1.0",
  "info": {
    "title": "Hayyvn API",
    "version": "1.0",
    "description": "The Hayyvn workspace API for scripts and AI agents: publish posts, read stats, and read, moderate and reply to comments and DMs. Authenticate with a workspace API key (`Authorization: Bearer hvn_…`). A key acts as the member who created it, never above `moderator`, in its one workspace, and only on the routes listed here. Every other route refuses keys with `403 api_key_not_allowed`. Generated from the route code; see https://hayyvn.com/developers.",
    "contact": {
      "name": "Hayyvn support",
      "email": "support@hayyvn.com"
    }
  },
  "servers": [
    {
      "url": "https://app.hayyvn.com"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Key",
      "description": "The calling key itself."
    },
    {
      "name": "Accounts",
      "description": "Connected accounts and account groups."
    },
    {
      "name": "Media",
      "description": "Upload images and videos for posts."
    },
    {
      "name": "Posts",
      "description": "Drafts, scheduled posts and publishing."
    },
    {
      "name": "Insights",
      "description": "Per-post stats and the briefing."
    },
    {
      "name": "Comments",
      "description": "Read, moderate and reply to comments."
    },
    {
      "name": "DMs",
      "description": "Instagram direct messages and the opportunity pipeline."
    },
    {
      "name": "MCP",
      "description": "The Model Context Protocol endpoint for AI agents."
    }
  ],
  "paths": {
    "/api/api-keys/self": {
      "get": {
        "operationId": "getApiKeysSelf",
        "tags": [
          "Key"
        ],
        "summary": "Describe the calling key",
        "description": "Any valid key. Any valid key. Returns the workspace it belongs to, its name, effective scopes (held plus implied: `posts:publish` ⊃ `posts:schedule` ⊃ `posts:draft` ⊃ `posts:read`), reply mode (`draft` or `send`), role (never above `moderator`), expiry, connection, and effective account access (`{scope:\"all\"}` or `{scope:\"groups\", groups:[{id,name}], reason}`). `connection` is `{kind:\"key\"}` for a key made in Settings, or `{kind:\"oauth\", renewsAutomatically, connectedUntil}` for an app connected with Sign in with Hayyvn — its `expiresAt` is the 1-hour access token, renewed automatically until `connectedUntil`.",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-havyyn-scopes": [],
        "responses": {
          "200": {
            "description": "`{ workspaceId, workspaceName, keyName, expiresAt, connection, scopes, replyMode, role, access }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/mcp": {
      "post": {
        "operationId": "postMcp",
        "tags": [
          "MCP"
        ],
        "summary": "MCP endpoint (Model Context Protocol)",
        "description": "Any valid key. Remote MCP server for AI agents: Streamable HTTP transport, stateless, JSON responses, one JSON-RPC message per request (no batches). Any valid key; the agent sees only the tools its scopes allow, and each tool calls the same routes listed here, so every check still applies. Limited to 120 requests per minute per key (`429`, with `Retry-After`).",
        "security": [
          {
            "apiKey": []
          }
        ],
        "x-havyyn-scopes": [],
        "requestBody": {
          "required": true,
          "description": "One JSON-RPC 2.0 message.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "jsonrpc",
                  "method"
                ],
                "properties": {
                  "jsonrpc": {
                    "const": "2.0"
                  },
                  "id": {
                    "type": [
                      "string",
                      "integer"
                    ]
                  },
                  "method": {
                    "type": "string",
                    "examples": [
                      "initialize",
                      "tools/list",
                      "tools/call"
                    ]
                  },
                  "params": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One JSON-RPC 2.0 response.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/uploads": {
      "post": {
        "operationId": "postUploads",
        "tags": [
          "Media"
        ],
        "summary": "Upload media files",
        "description": "Scope: `posts:draft` (higher post scopes work too: `posts:schedule`, `posts:publish`). Upload one or more images or videos for a post (multipart form, one `file` field per file). Returns public URLs to pass as post media. Counts toward the workspace’s storage. Each file up to 95 MB (95,000,000 bytes), the whole request up to that plus 64 KiB; `Content-Length` is required. At most 2 of these in flight per caller and 4 per workspace (`429 uploads_in_progress`), and a server-wide limit on bytes in flight (`503 server_busy`); both carry `Retry-After`. For larger videos use the multipart upload below.",
        "security": [
          {
            "apiKey": [
              "posts:draft"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:draft"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "query",
            "required": true,
            "description": "The workspace the key belongs to.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "One or more `file` fields.",
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The stored files with their public URLs.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/uploads/multipart": {
      "post": {
        "operationId": "postUploadsMultipart",
        "tags": [
          "Media"
        ],
        "summary": "Start, complete or abort a multipart upload",
        "description": "Scope: `posts:draft` (higher post scopes work too: `posts:schedule`, `posts:publish`). For large videos. `action: \"create\"` (with `contentType` and `size`) returns `{ key, uploadId, partSize }`; PUT each part; then `action: \"complete\"` with every part’s `etag` returns `{ url }`, or `action: \"abort\"` discards it.",
        "security": [
          {
            "apiKey": [
              "posts:draft"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:draft"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "query",
            "required": true,
            "description": "The workspace the key belongs to.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "action": {
                        "type": "string",
                        "const": "create"
                      },
                      "filename": {
                        "type": "string",
                        "maxLength": 300
                      },
                      "contentType": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 100
                      },
                      "size": {
                        "type": "integer",
                        "minimum": 1
                      },
                      "target": {
                        "type": "string",
                        "enum": [
                          "staging",
                          "library"
                        ],
                        "default": "staging"
                      }
                    },
                    "required": [
                      "action",
                      "contentType",
                      "size"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "action": {
                        "type": "string",
                        "const": "complete"
                      },
                      "key": {
                        "type": "string"
                      },
                      "uploadId": {
                        "type": "string"
                      },
                      "parts": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "partNumber": {
                              "type": "integer",
                              "minimum": 1,
                              "maximum": 10000
                            },
                            "etag": {
                              "type": "string",
                              "minLength": 1
                            }
                          },
                          "required": [
                            "partNumber",
                            "etag"
                          ],
                          "additionalProperties": false
                        },
                        "minItems": 1
                      }
                    },
                    "required": [
                      "action",
                      "key",
                      "uploadId",
                      "parts"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "action": {
                        "type": "string",
                        "const": "abort"
                      },
                      "key": {
                        "type": "string"
                      },
                      "uploadId": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "action",
                      "key",
                      "uploadId"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "action": {
                        "type": "string",
                        "const": "sign"
                      },
                      "key": {
                        "type": "string"
                      },
                      "uploadId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 1024
                      },
                      "partNumbers": {
                        "type": "array",
                        "items": {
                          "type": "integer",
                          "minimum": 1,
                          "maximum": 10000
                        },
                        "minItems": 1,
                        "maxItems": 64
                      },
                      "size": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 167772160000
                      }
                    },
                    "required": [
                      "action",
                      "key",
                      "uploadId",
                      "partNumbers",
                      "size"
                    ],
                    "additionalProperties": false
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ key, uploadId, partSize }` (create), `{ url }` (complete) or `{ ok }` (abort).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "put": {
        "operationId": "putUploadsMultipart",
        "tags": [
          "Media"
        ],
        "summary": "Upload one part",
        "description": "Scope: `posts:draft` (higher post scopes work too: `posts:schedule`, `posts:publish`). Raw bytes of one part (every part but the last is exactly `partSize`). Failed parts can be retried on their own. At most 4 parts in flight per caller and 8 per workspace (`429 uploads_in_progress`, or `503 server_busy` when the server is full; wait `Retry-After`), and 600 parts a minute per caller.",
        "security": [
          {
            "apiKey": [
              "posts:draft"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:draft"
        ],
        "parameters": [
          {
            "name": "key",
            "in": "query",
            "required": true,
            "description": "The `key` from create.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "partNumber",
            "in": "query",
            "required": true,
            "description": "1-based part number.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "total",
            "in": "query",
            "description": "How many parts the upload will have.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "uploadId",
            "in": "query",
            "required": true,
            "description": "The `uploadId` from create.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "workspaceId",
            "in": "query",
            "required": true,
            "description": "The workspace the key belongs to.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "The part’s bytes.",
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ etag }` — keep it for complete.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/account-groups": {
      "get": {
        "operationId": "getAccountGroups",
        "tags": [
          "Accounts"
        ],
        "summary": "List account groups",
        "description": "Scopes: any of `posts:read`, `insights:read`, `comments:read`, `dms:read`. Any of `posts:read`, `insights:read`, `comments:read`, `dms:read`. The live groups `{ id, name, color, sortOrder, accountIds }`, so you can find names to pass as `group`. Creating and editing groups is for people in the app.",
        "security": [
          {
            "apiKey": [
              "posts:read",
              "insights:read",
              "comments:read",
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read",
          "insights:read",
          "comments:read",
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "The workspace’s live account groups.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/accounts/{accountId}/youtube/playlists": {
      "get": {
        "operationId": "getAccountsAccountIdYoutubePlaylists",
        "tags": [
          "Accounts"
        ],
        "summary": "List a YouTube channel’s playlists",
        "description": "Scope: `posts:draft` (higher post scopes work too: `posts:schedule`, `posts:publish`). The connected YouTube channel’s own playlists — `id`, `title`, `itemCount`, `privacyStatus` — for `youtubeOptions.playlistIds` and `POST media/{mediaId}/playlists`. `accountId` is a YouTube account’s id (`GET connections`). Needs `posts:draft`. Cached for 10 minutes (`?fresh=1` asks YouTube again; at most 60 fresh lists per hour per workspace). Uses 1 unit of the day’s YouTube quota per 50 playlists, nothing when cached (`429 youtube_quota_exhausted`); at most 200 playlists are listed (`truncated: true` beyond). YouTube only (`400 not_supported`); `404 not_found` for an unknown account or one the key can’t see; `400 account_or_token_missing` when the channel isn’t connected.",
        "security": [
          {
            "apiKey": [
              "posts:draft"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:draft"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "fresh",
            "in": "query",
            "description": "`1` = skip the 10-minute cache.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ accountId, playlists: [{ id, title, itemCount, privacyStatus }], truncated }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postAccountsAccountIdYoutubePlaylists",
        "tags": [
          "Accounts"
        ],
        "summary": "Create a YouTube playlist",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Creates a playlist on the connected YouTube channel. Body `{ title, privacyStatus? }` — `title` ≤ 150 characters, no `<` or `>` (`400 invalid_request`); `privacyStatus` `public` (default), `unlisted` or `private`. Needs `posts:schedule`. YouTube only (`400 not_supported`); `404 not_found` for an unknown account or one the key can’t see; `409` while the account is being handed back to its creator. Uses 50 units of the day’s YouTube quota (`429 youtube_quota_exhausted`); at most 10 per hour per workspace (`429 rate_limited`). Audited as `media.playlist_created`.",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "privacyStatus": {
                    "type": "string",
                    "enum": [
                      "public",
                      "unlisted",
                      "private"
                    ]
                  }
                },
                "required": [
                  "title"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ accountId, playlist: { id, title, itemCount, privacyStatus } }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/affiliate-links": {
      "get": {
        "operationId": "getAffiliateLinks",
        "tags": [
          "Insights"
        ],
        "summary": "List affiliate links",
        "description": "Scope: `insights:read`. The workspace’s tracked short links (`/r/{slug}`), newest first. Not available to a key limited to some account groups (`403 access_limited`); `404 affiliate_disabled` while the feature is off. A key gets `merchantDomain` (the destination site) — never the full destination URL, which can carry the creator’s affiliate tag, nor the affiliate account. Creating and editing links is for people in the app.",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ links: [{ id, slug, shortUrl, label, merchantDomain, network, active, disabledByOperator, clickCount, createdAt }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/affiliate-links/stats": {
      "get": {
        "operationId": "getAffiliateLinksStats",
        "tags": [
          "Insights"
        ],
        "summary": "Affiliate link clicks",
        "description": "Scope: `insights:read`. Clicks per link: all time, from in-app browsers, and in the last 30 days. Same access as `GET affiliate-links`.",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ totalClicks, perLink: [{ linkId, clicks, inAppClicks, clicksLast30d }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/assist-level": {
      "get": {
        "operationId": "getAssistLevel",
        "tags": [
          "Comments"
        ],
        "summary": "Assist level: what Hayyvn does on its own",
        "description": "Scope: `comments:read`. Needs `comments:read`. How much the workspace lets Hayyvn act without a person: `level` is `ask_first` (everything waits for the creator), `obvious` (clear spam and hate are hidden, simple thank-yous get a reply on their own; the rest waits) or `custom` (individual automation levels were tuned in the app). `chosen` / `chosenAt` say whether and when someone picked it; `autoRepliesLive` is false while auto-replies are switched off for Hayyvn, in which case thank-you replies wait too. Workspace-wide, so a key limited to some account groups is refused. Changing it is for an owner or admin in the app — no key can.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ level, chosen, chosenAt, autoRepliesLive }`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/auto-dm": {
      "get": {
        "operationId": "getAutoDm",
        "tags": [
          "DMs"
        ],
        "summary": "List auto-DM campaigns",
        "description": "Scope: `dms:read`. Comment-to-DM campaigns, newest first. A key limited to some account groups sees only its accounts’ campaigns. A key never receives the DM text (`dmVariants`, `publicReply`). Campaigns are changed by people in the app — no key can edit, pause or switch them.",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "stats",
            "in": "query",
            "description": "`1` = add `sentLast7d`: DMs the campaign sent in the last 7 days.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ campaigns: [{ id, name, platformAccountId, scopeMediaIds, triggerKeywords, offerId, active, activeUntil, maxSends, mode, matchedCount, sentCount, createdAt, sentLast7d? }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/block-suggestions": {
      "get": {
        "operationId": "getBlockSuggestions",
        "tags": [
          "Comments"
        ],
        "summary": "List block suggestions",
        "description": "Scope: `comments:read`. People Hayyvn suggests ghost-blocking because their comments keep getting moderated, highest score first (up to 50 pending), with the receipts (the hidden/deleted comments behind each) and the feature’s `mode`. A key limited to some account groups sees a person only when all of their comments and DMs are on its own accounts, with receipts from those accounts. A key never receives the platform user id or the `note` a person left; `targetUsername` is the handle without `@`, or null when only the user id is known.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ mode, suggestions: [{ id, status, platform, targetUsername, targetDisplayName, score, reasonSummary, hiddenCount, deletedCount, ruleHitCount, distinctPosts, avgSentiment, avgToxicity, lastActionAt, isAlsoSuperfan, aiSummary, aiRecommendation, receipts: [{ externalId, text, at }] }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/block-suggestions/{suggestionId}": {
      "delete": {
        "operationId": "deleteBlockSuggestionsSuggestionId",
        "tags": [
          "Comments"
        ],
        "summary": "Dismiss a block suggestion",
        "description": "Scope: `comments:moderate`. Needs `comments:moderate`. Marks the suggestion “not interested” — nothing reaches a platform, and it takes no moderation slot; the person is suggested again only if their behaviour gets clearly worse. Not available to a key limited to some account groups (`403 access_limited`). `409 already_decided` when it was already accepted or dismissed; `404 not_found`. People can restore it in the app.",
        "security": [
          {
            "apiKey": [
              "comments:moderate"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:moderate"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "suggestionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/block-suggestions/{suggestionId}/accept": {
      "post": {
        "operationId": "postBlockSuggestionsSuggestionIdAccept",
        "tags": [
          "Comments"
        ],
        "summary": "Accept a block suggestion",
        "description": "Scope: `comments:moderate`. Needs `comments:moderate`. Ghost-blocks the person (their comments are silently hidden on every account of that platform) and marks the suggestion accepted. Each accept takes one slot of the key’s 200-per-hour moderation cap (`429 agent_moderation_limit`, nothing done). Not available to a key limited to some account groups (`403 access_limited`). `409 already_decided` when it was already accepted or dismissed; `409 trusted` for someone on the Trusted people list; `400 cannot_block_self`; `404 not_found` (also for a person whose activity is only on disconnected accounts — `GET block-suggestions` never lists them). People undo it by removing the ghost block in the app (it can be restored).",
        "security": [
          {
            "apiKey": [
              "comments:moderate"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:moderate"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "suggestionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true, entryId }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/briefing": {
      "get": {
        "operationId": "getBriefing",
        "tags": [
          "Insights"
        ],
        "summary": "Briefing: how the accounts are doing",
        "description": "Scope: `insights:read`. Per account: followers and change, recent posts against the account’s usual. Comment, DM and opportunity sections appear only when the key also has `comments:read` / `dms:read`; upcoming posts and `nothingScheduled` only with `posts:read`. Without `group`, a workspace with groups also gets a per-group `groups[]` breakdown.",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "hours",
            "in": "query",
            "description": "Look-back window in hours (1–168, default 24).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 168
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The briefing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/comments": {
      "get": {
        "operationId": "getComments",
        "tags": [
          "Comments"
        ],
        "summary": "List comments",
        "description": "Scope: `comments:read`. Comments across the workspace’s connected accounts, newest first, with their latest moderation status. Keys get no `fromUserId` (the commenter’s platform user id) and no `assigneeUserId` — `assignee: { role }` instead (null role = no longer a member; `assignee: null` = unassigned) — and a regex rule over 60 characters comes as `rulePattern: null` plus `rulePatternLength`.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "Only this connected account (an `id` from `GET connections`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "assigned",
            "in": "query",
            "description": "`me` = only items assigned to the member the key acts as (its creator).",
            "schema": {
              "type": "string",
              "enum": [
                "me"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Opaque cursor from the previous page’s `nextCursor`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size (default 50, max 200).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          },
          {
            "name": "mediaId",
            "in": "query",
            "description": "Only comments on these posts (comma-separated platform media ids).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "platform",
            "in": "query",
            "description": "Only this platform.",
            "schema": {
              "type": "string",
              "enum": [
                "instagram",
                "youtube",
                "tiktok"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Text search over the comment and its post’s caption.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sinceDays",
            "in": "query",
            "description": "Only comments seen in the last N days (default 30, max 365; 0 = all time).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "description": "`recent` (default) or `toxic` (most toxic first).",
            "schema": {
              "type": "string",
              "enum": [
                "recent",
                "toxic"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Moderation status.",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "hidden",
                "deleted",
                "review",
                "unmoderated"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ items, nextCursor, total }`. Each item says which post it is on: `mediaId` (Hayyvn’s media id, null when the post isn’t stored), `platformMediaId` (the platform’s media/video id, null when unknown or for live chat) and `permalink` (null when unknown).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/comments/{commentId}/notes": {
      "get": {
        "operationId": "getCommentsCommentIdNotes",
        "tags": [
          "Comments"
        ],
        "summary": "Read a comment’s internal notes",
        "description": "Scope: `comments:read`. Needs `comments:read`. The team’s internal notes on the comment (never posted), oldest first. Keys see live notes only; `author` is \"Agent · <key name>\" for a note an API key wrote, otherwise the writer’s role (\"Teammate · admin\") or \"Former member\" — never an email or user id. Teammate mentions read as `@label` in `body`, and `mentions` lists them as `{ ref, label, role }`.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "commentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ notes: [{ id, body, author, byAgent, createdAt, mentions: [{ ref, label, role }] }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postCommentsCommentIdNotes",
        "tags": [
          "Comments"
        ],
        "summary": "Add an internal note to a comment",
        "description": "Scope: `comments:moderate`. Needs `comments:moderate`. An internal note for the team (1–2,000 characters after trimming) — never posted to the platform. It shows as \"Agent · <key name>\"; people can remove and restore it in the app. Keys: at most 60 notes per key per hour across comment, DM and opportunity notes (`429 agent_note_limit`, fails closed). Plan 49: a note may mention teammates with `<@ref>` tokens (refs from `GET …/notes/mentionables`); they are told in Hayyvn. At most 10 per note; anyone who can’t see this account fails the whole note (`422 mention_not_eligible`, nothing saved; `422 too_many_mentions` past 10). Mentions count against the same hourly cap. `assign` (plan 49 P8: a `tm_` ref the note mentions — `400 assign_not_mentioned` otherwise, nothing saved) also assigns the comment to that teammate after the note is saved; if they can’t be assigned (a viewer, or no access) the note stays and `assignError` says why. The assignee is told once — the mention’s alert says both.",
        "security": [
          {
            "apiKey": [
              "comments:moderate"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:moderate"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "commentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "`{ \"body\": \"<the note>\", \"assign\"?: \"<tm_ ref>\" }` — body trimmed, then 1–2,000 characters.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "assign": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "A teammate ref (`tm_…`) this note mentions — also assign them the comment."
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ ok: true, note: { id, body, author, byAgent, createdAt, mentions: [{ ref, label, role }] }, assigned?: { changed }, assignError?: { error, message } }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/comments/{commentId}/notes/mentionables": {
      "get": {
        "operationId": "getCommentsCommentIdNotesMentionables",
        "tags": [
          "Comments"
        ],
        "summary": "List teammates who can be mentioned on a comment",
        "description": "Scope: `comments:read`. Needs `comments:read`. The teammates who can be @-mentioned in a note on this comment — members who can see its account (never clients). Each is `{ ref, label, role, canAssign, isSelf }`: `ref` is an opaque, stable `tm_…` id for this workspace (write `<@ref>` in a note to mention them), `label` the short name Hayyvn shows (the part of their email before the @), `role` their workspace role, `canAssign` whether they could be assigned the thread. Never a user id or an email (`isSelf` marks the person who created the key). `404 not_found` while teammate mentions are off for the workspace.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "commentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ teammates: [{ ref, label, role, canAssign, isSelf }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/comments/{commentId}/react": {
      "post": {
        "operationId": "postCommentsCommentIdReact",
        "tags": [
          "Comments"
        ],
        "summary": "Like or pin a comment",
        "description": "Scope: `comments:reply`. Body `{ action: \"like\" | \"unlike\" | \"pin\" | \"unpin\" }`. TikTok (other platforms are refused, `platform_unsupported`). Keys need `comments:reply`; 60 per key per hour (`429 agent_reaction_limit`); audited with the key.",
        "security": [
          {
            "apiKey": [
              "comments:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "commentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "like",
                      "unlike",
                      "pin",
                      "unpin"
                    ]
                  }
                },
                "required": [
                  "action"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok, action }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/comments/{commentId}/reply": {
      "post": {
        "operationId": "postCommentsCommentIdReply",
        "tags": [
          "Comments"
        ],
        "summary": "Reply to a comment",
        "description": "Scope: `comments:reply`. Follows the key’s reply mode. `draft` (default): the reply waits in the Engage queue for a person to send (`202 {status:\"drafted\", entryId}`); `send`: posted directly, at most 30 per key per hour. The key’s disclosure is appended; the platform’s length limit is checked against the final text (TikTok 150, Instagram 2,200, YouTube 10,000). Refused: `409 comment_hidden`, `409 reply_already_pending`, `409 reply_already_sent`, `429 agent_draft_limit` (60 drafts/hour), `429 agent_draft_backlog` (100 pending), `429 agent_send_limit`. Send mode never posts the same reply twice: pass `idempotencyKey` (any string ≤ 200, one per reply you mean to send) and reuse it on retry — a repeat returns the first result with `replayed: true`; without one, the same text to the same target within 5 minutes counts as a repeat. `409 send_in_progress` while another send to it is going out; `422 idempotency_key_reused` for a key already used on a different reply. `504 outcome_unknown` (`outcomeUnknown: true`): the platform didn’t answer in time and the reply may be live — a retry is checked against the platform first, and refused with `409 outcome_unknown` while that can’t be confirmed. When the platform refuses a send: `409 needs_reconnect`, `404 not_found`, `429 rate_limited` / `quota_exhausted`, `422 invalid_input`, `502 provider_error` (c650).",
        "security": [
          {
            "apiKey": [
              "comments:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "commentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 10000
                  },
                  "replyDraftId": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "idempotencyKey": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  }
                },
                "required": [
                  "message"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "`{ status: \"drafted\", entryId }` in draft mode; the sent reply in send mode (200).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/comments/{commentId}/thread": {
      "get": {
        "operationId": "getCommentsCommentIdThread",
        "tags": [
          "Comments"
        ],
        "summary": "Get a comment’s thread",
        "description": "Scope: `comments:read`. Instagram only. Cached 90 seconds for keys; at most 30 live fetches per hour per account. When the live fetch is refused or the account is backing off, the stored thread is returned with `source: \"stored\"`; otherwise `429 rate_limited` with `Retry-After`. A failed live fetch answers `409 needs_reconnect` (with `platform` + `accountName`), `404 not_found` or `502 platform_error` — never the platform’s own error text. Keys get no platform user ids: each comment carries `byAccount` (written by the connected account) instead of `fromUserId`, and there is no `accountExternalId`.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "commentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The thread, with `source` = `live`, `cache` or `stored`, and the post it is on (`mediaId`, `platformMediaId`, `permalink`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/comments/bulk-action": {
      "post": {
        "operationId": "postCommentsBulkAction",
        "tags": [
          "Comments"
        ],
        "summary": "Moderate comments",
        "description": "Scope: `comments:read`. hide, unhide, hold_for_review, block_user, unblock_user need `comments:moderate`; `delete` needs `comments:delete` (on comments the account doesn’t own, platforms only allow a hide, so it hides). Keys: at most 25 comments per call (`400 too_many_comments`) and 200 per key per hour (`429 agent_moderation_limit`). YouTube writes reserve quota first; if none is left nothing is done (`429`/`503 youtube_quota_exhausted`).",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "commentExternalIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "minItems": 1,
                    "maxItems": 200
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "hide",
                      "unhide",
                      "delete",
                      "hold_for_review",
                      "block_user",
                      "unblock_user"
                    ]
                  },
                  "restrictAuthor": {
                    "type": "boolean"
                  },
                  "restoreBlock": {
                    "type": "object",
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "deletedAt": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "deletedByUserId": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "maxLength": 200
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "reason": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "maxLength": 500
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "deletedAt",
                            "deletedByUserId",
                            "reason"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "propertyNames": {
                      "minLength": 1
                    }
                  }
                },
                "required": [
                  "commentExternalIds",
                  "action"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok, appliedCount, failedCount, results }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/comments/hold-negatives": {
      "post": {
        "operationId": "postCommentsHoldNegatives",
        "tags": [
          "Comments"
        ],
        "summary": "Hold negative comments on a post",
        "description": "Scope: `comments:moderate`. Holds every clearly negative, still-visible comment on one post (`mediaId` = the platform media id) for review; they stay up on the platform and land in the review queue. Comments that already have a review entry (`alreadyHeld` pending, `alreadyDecided` approved/rejected/expired) or that a person marked safe are skipped and cost nothing. Keys need `comments:moderate`; every comment held counts toward the 200-per-hour moderation cap. With fewer slots left than candidates, the most negative are held and the rest come back as `notHeldOverLimit` (a partial hold); with none left, nothing is held (`429 agent_moderation_limit`).",
        "security": [
          {
            "apiKey": [
              "comments:moderate"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:moderate"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "mediaId": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "mediaId"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok, held, alreadyHeld, alreadyDecided, notHeldOverLimit }` — `held` counts entries actually created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/competitors": {
      "get": {
        "operationId": "getCompetitors",
        "tags": [
          "Insights"
        ],
        "summary": "Benchmarks watchlist",
        "description": "Scope: `insights:read`. The creators the workspace watches on Benchmarks, each with its last 30 daily snapshots (followers, media count, engagement rate, posts per week, audience overlap — aggregates only, never who), the workspace’s own accounts for comparison (disconnected ones hidden), its live groups and the watchlist cap. Stored snapshots only — no platform call. Not available to keys limited to account groups. Keys get no `notes`.",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "group",
            "in": "query",
            "description": "Only creators (and own accounts) compared with this group: a group id, its name, or \"none\".",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The watchlist.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/composes": {
      "get": {
        "operationId": "getComposes",
        "tags": [
          "Posts"
        ],
        "summary": "List drafts",
        "description": "Scope: `posts:read`. Unscheduled drafts, each in the same shape `POST composes` accepts.",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mine",
            "in": "query",
            "description": "`1` = only the ones this API key created.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ drafts }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postComposes",
        "tags": [
          "Posts"
        ],
        "summary": "Create a post or draft",
        "description": "Scope: `posts:draft` (higher post scopes work too: `posts:schedule`, `posts:publish`). With `publishAt`: scheduled to every account in `platformAccountIds`. Without it: saved as a draft (`posts:draft` is enough). With `draftId`: replaces that draft’s content (the key’s own drafts only) and schedules it if `publishAt` is set. A `publishAt` at least 5 minutes ahead needs `posts:schedule`; sooner (now) needs `posts:publish` — otherwise `403 api_key_missing_scope` naming the scope. A YouTube target can carry `youtubeOptions.tags` (up to 30 tags, each ≤ 100 characters, ≤ 500 in total counting YouTube’s quotes and commas, no `<` or `>`; a leading `#` is dropped and duplicates removed — `400 invalid_youtube_tags` otherwise). A YouTube target can carry `youtubeOptions.playlistIds` (≤ 5 of the channel’s own playlist ids — `GET accounts/{accountId}/youtube/playlists`; `400 invalid_youtube_playlists` for a malformed id, `400 unknown_playlist` for one that isn’t the channel’s): the video is added to them right after it goes live, 50 YouTube units each, never failing the publish (c569); on a post to several channels each video goes only into its own channel’s playlists — the other channels’ ids are skipped. Accounts in a group with an approval policy create a post waiting for approval. Media are URLs from the upload routes. A YouTube target can carry subtitle tracks, `youtubeOptions.captions: [{ ref, language, name? }]` — ≤ 5, one per language (BCP-47, e.g. `en`, `es-419`), each `ref` a Hayyvn upload of an SRT or WebVTT file (`POST uploads` with `application/x-subrip` / `text/vtt`, ≤ 1 MB; library files can’t be used yet) — `400 invalid_captions` otherwise; a subtitle file is never a post’s media (`400 incompatible_plan`). They are added right after the upload (400 YouTube units each, from the workspace’s publish allowance); a refusal is retried later and never fails the publish — the job records `captionsError` (c568). A YouTube target can carry a custom thumbnail, `youtubeOptions.thumbnailRef`: a Hayyvn image URL (an upload or a library item’s `url`), JPEG or PNG, ≤ 2 MB, at least 640×360 (`400 invalid_thumbnail` otherwise). It is set right after the upload and never fails the publish — a channel not verified for custom thumbnails keeps YouTube’s own frame (c565). `youtubeOptions.firstComment` (≤ 2,000 characters, no `<` `>`; `400 invalid_youtube_first_comment`) is posted as the channel right after the video goes live — it never fails the publish; comments off on the video (or a made-for-kids video, skipped without a call) → the job records `firstCommentError: comments_disabled`. YouTube can’t pin it through the API (c570). An API key setting a first comment is sending a comment: it also needs `comments:reply` (`403 api_key_missing_scope`) and **send** reply mode (`403 draft_mode_cannot_send`), and the text is stored with the key’s disclosure (R2-F1).",
        "security": [
          {
            "apiKey": [
              "posts:draft"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:draft"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "contentKind": {
                    "type": "string",
                    "enum": [
                      "short_video",
                      "long_video",
                      "photo",
                      "story"
                    ]
                  },
                  "platformAccountIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "minItems": 1
                  },
                  "defaultCaption": {
                    "type": "string",
                    "maxLength": 4000,
                    "default": ""
                  },
                  "defaultMediaRefs": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 2000
                    },
                    "maxItems": 20,
                    "default": []
                  },
                  "overrides": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "caption": {
                          "type": "string",
                          "maxLength": 4000
                        },
                        "hashtags": {
                          "type": "string",
                          "maxLength": 1000
                        }
                      },
                      "additionalProperties": false
                    },
                    "propertyNames": {
                      "enum": [
                        "instagram",
                        "youtube",
                        "tiktok"
                      ]
                    }
                  },
                  "tiktokOptions": {
                    "type": "object",
                    "properties": {
                      "privacyLevel": {
                        "type": "string",
                        "enum": [
                          "PUBLIC_TO_EVERYONE",
                          "MUTUAL_FOLLOW_FRIENDS",
                          "FOLLOWER_OF_CREATOR",
                          "SELF_ONLY"
                        ]
                      },
                      "title": {
                        "type": "string",
                        "maxLength": 90
                      },
                      "disableComment": {
                        "type": "boolean"
                      },
                      "disableDuet": {
                        "type": "boolean"
                      },
                      "disableStitch": {
                        "type": "boolean"
                      },
                      "isBrandOrganic": {
                        "type": "boolean"
                      },
                      "isBrandedContent": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "privacyLevel"
                    ],
                    "additionalProperties": false
                  },
                  "youtubeOptions": {
                    "type": "object",
                    "properties": {
                      "captions": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "ref": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 2000
                            },
                            "language": {
                              "type": "string",
                              "maxLength": 40
                            },
                            "name": {
                              "type": "string",
                              "maxLength": 200
                            }
                          },
                          "required": [
                            "ref",
                            "language"
                          ],
                          "additionalProperties": false
                        },
                        "maxItems": 20
                      },
                      "privacyStatus": {
                        "type": "string",
                        "enum": [
                          "public",
                          "unlisted",
                          "private"
                        ]
                      },
                      "tags": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "maxLength": 500
                        },
                        "maxItems": 100
                      },
                      "title": {
                        "type": "string",
                        "maxLength": 1000
                      },
                      "madeForKids": {
                        "type": "boolean"
                      },
                      "firstComment": {
                        "type": "string",
                        "maxLength": 10000
                      },
                      "containsSyntheticMedia": {
                        "type": "boolean"
                      },
                      "categoryId": {
                        "type": "string",
                        "enum": [
                          "1",
                          "2",
                          "10",
                          "15",
                          "17",
                          "19",
                          "20",
                          "22",
                          "23",
                          "24",
                          "25",
                          "26",
                          "27",
                          "28",
                          "29"
                        ]
                      },
                      "defaultLanguage": {
                        "type": "string"
                      },
                      "defaultAudioLanguage": {
                        "type": "string"
                      },
                      "thumbnailRef": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 2000
                      },
                      "playlistIds": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "maxLength": 100
                        },
                        "maxItems": 20
                      }
                    },
                    "additionalProperties": false
                  },
                  "instagramOptions": {
                    "type": "object",
                    "properties": {
                      "collaborators": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "maxLength": 60
                        },
                        "maxItems": 10
                      }
                    },
                    "additionalProperties": false
                  },
                  "publishAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "draftId": {
                    "type": "string",
                    "pattern": "^[a-z0-9]{8,40}$"
                  },
                  "studioClipId": {
                    "type": "string",
                    "pattern": "^[a-z0-9]{8,40}$"
                  }
                },
                "required": [
                  "contentKind",
                  "platformAccountIds"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The created post or draft.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/composes/{composeId}": {
      "delete": {
        "operationId": "deleteComposesComposeId",
        "tags": [
          "Posts"
        ],
        "summary": "Delete a draft",
        "description": "Scope: `posts:draft` (higher post scopes work too: `posts:schedule`, `posts:publish`). Removes an unscheduled draft. The key can only act on posts and drafts it created itself (`403 api_key_not_post_owner` / `api_key_not_draft_owner`).",
        "security": [
          {
            "apiKey": [
              "posts:draft"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:draft"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "composeId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "permanent",
            "in": "query",
            "description": "Not for API keys (`403 people_only`): removed drafts can be restored in the app for 30 days, and only people delete them for good there.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/connections": {
      "get": {
        "operationId": "getConnections",
        "tags": [
          "Accounts"
        ],
        "summary": "List connected accounts",
        "description": "Scope: `posts:read`. The workspace’s connected Instagram, YouTube and TikTok accounts, each with `nickname`, `group` (`{ id, name, color }` or null) and `connectionType` (Instagram: `instagram_login` or `facebook_login` — only `facebook_login` can delete comments, like or block in DMs; null on YouTube / TikTok).",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ accounts: [{ id, platform, externalId, displayName, nickname, group, status, connectionType, connectedAt, lastSeenAt, tokenExpiresAt }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/dms": {
      "get": {
        "operationId": "getDms",
        "tags": [
          "DMs"
        ],
        "summary": "List DM conversations",
        "description": "Scope: `dms:read`. Direct-message conversations, most recent first. `q` is a windowed search: each call examines the next 500 conversations in scope, so a page can be short or empty with a `nextCursor` — keep paging. Keys: 360 `q` calls per key per hour — every page counts, since each examines up to 500 conversations (`429 agent_search_limit`, fails closed); no `participantUserId` (the person’s platform user id) and no `assigneeUserId` — `assignee: { role }` instead; `assigned=me` means threads assigned to the person who created the key.",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "Only this connected account (an `id` from `GET connections`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "archived",
            "in": "query",
            "description": "`1`/`true` = only archived conversations; `0`/`false` = only unarchived. Omit for both.",
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "0",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "assigned",
            "in": "query",
            "description": "`me` = only items assigned to the member the key acts as (its creator).",
            "schema": {
              "type": "string",
              "enum": [
                "me"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Opaque cursor from the previous page’s `nextCursor`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "flagged",
            "in": "query",
            "description": "`1`/`true` = only flagged conversations; `0`/`false` = only unflagged. Omit for both.",
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "0",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size (1–100, default 100).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Search, case-insensitive: the person’s handle or name, or the text of a message in the thread (unsent messages excluded). A leading `@` is ignored.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "snoozed",
            "in": "query",
            "description": "`1`/`true` = only conversations snoozed right now (`snoozedUntil` in the future); `0`/`false` = only ones not snoozed. Omit for both.",
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "0",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "unread",
            "in": "query",
            "description": "`1`/`true` = only conversations with unread messages; `0`/`false` = only read ones.",
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "0",
                "true",
                "false"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The conversations and `nextCursor` (null on the last page).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/dms/{conversationId}": {
      "get": {
        "operationId": "getDmsConversationId",
        "tags": [
          "DMs"
        ],
        "summary": "Get a conversation",
        "description": "Scope: `dms:read`. One conversation’s messages, newest page first, with `platformAccountId`, `participantName` and `lastInboundAt` (Instagram allows replies only within 24 hours of the person’s last message). Keys get no `participantUserId` or `accountExternalId` (platform user ids). c545: keys also get no signed story media URLs on messages (`replyToStoryMediaUrl`, `storyMentionMediaUrl`, `storyMediaThumbUrl` are absent; `replyToStoryId` / `storyMention` stay), `attachments` as `{ type, label }` (no url) and `reactions` as `{ emoji }` (no `actorId`).",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "conversationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "before",
            "in": "query",
            "description": "Cursor: return messages older than this one.",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Messages per page.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The conversation and a page of messages.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "operationId": "patchDmsConversationId",
        "tags": [
          "DMs"
        ],
        "summary": "Flag, archive or snooze a conversation",
        "description": "Scope: `dms:reply`. Needs `dms:reply`. Keys may send only `flagged`, `archived` and/or `snoozedUntil` (all reversible; nothing is sent to Instagram). `snoozedUntil` (ISO-8601 with offset, 1 minute to 1 year ahead; `null` = unsnooze) takes the thread out of the inbox until then — it comes back marked unread, or sooner when the person writes; snoozing unarchives, archiving unsnoozes, and both in one call is `400`. `markRead` or any other field is `403 people_only` — marking a thread read clears the unread signal a person relies on. `404 not_found` for an unknown id or another group’s conversation.",
        "security": [
          {
            "apiKey": [
              "dms:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "conversationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "At least one of `flagged` / `archived` / `snoozedUntil`.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "properties": {
                  "flagged": {
                    "type": "boolean"
                  },
                  "archived": {
                    "type": "boolean"
                  },
                  "snoozedUntil": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok: true }` (plus `snoozedUntil` when it was sent)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/dms/{conversationId}/ai-pause": {
      "post": {
        "operationId": "postDmsConversationIdAiPause",
        "tags": [
          "DMs"
        ],
        "summary": "Pause the AI on a conversation",
        "description": "Scope: `dms:reply`. Needs `dms:reply`. `{ action: \"pause\", preset: \"4h\" | \"24h\" | \"indefinite\" }` stops Hayyvn’s autonomous sends (auto-reply, Auto-DM, deal vetting and follow-ups) on this thread until then — drafts still appear for a person. `indefinite` lasts until a person turns it back on. `{ action: \"resume\" }` is people-only: a key gets `403 people_only`. `404 not_found` for an unknown id or another group’s conversation.",
        "security": [
          {
            "apiKey": [
              "dms:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "conversationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "`preset` is required with `pause`.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "action"
                ],
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "pause",
                      "resume"
                    ]
                  },
                  "preset": {
                    "type": "string",
                    "enum": [
                      "4h",
                      "24h",
                      "indefinite"
                    ]
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ aiPausedUntil, aiPauseReason, indefinite }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/dms/{conversationId}/notes": {
      "get": {
        "operationId": "getDmsConversationIdNotes",
        "tags": [
          "DMs"
        ],
        "summary": "Read a conversation’s internal notes",
        "description": "Scope: `dms:read`. Needs `dms:read`. The team’s internal notes on the thread (never sent to Instagram), oldest first. Keys see live notes only; `author` is \"Agent · <key name>\" for a note an API key wrote, otherwise the writer’s role (\"Teammate · admin\") or \"Former member\" — never an email or user id. Teammate mentions read as `@label` in `body`, and `mentions` lists them as `{ ref, label, role }`.",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "conversationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ notes: [{ id, body, author, byAgent, createdAt, mentions: [{ ref, label, role }] }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postDmsConversationIdNotes",
        "tags": [
          "DMs"
        ],
        "summary": "Add an internal note to a conversation",
        "description": "Scope: `dms:reply`. Needs `dms:reply`. An internal note for the team (1–2,000 characters after trimming) — never sent to Instagram. It shows as \"Agent · <key name>\"; people can remove and restore it in the app. Keys: at most 60 notes per key per hour across comment, DM and opportunity notes (`429 agent_note_limit`, fails closed). Plan 49: a note may mention teammates with `<@ref>` tokens (refs from `GET …/notes/mentionables`); they are told in Hayyvn. At most 10 per note; anyone who can’t see this account fails the whole note (`422 mention_not_eligible`, nothing saved; `422 too_many_mentions` past 10). Mentions count against the same hourly cap. `assign` (plan 49 P8: a `tm_` ref the note mentions — `400 assign_not_mentioned` otherwise, nothing saved) also assigns the conversation to that teammate after the note is saved; if they can’t be assigned (a viewer, or no access) the note stays and `assignError` says why. The assignee is told once — the mention’s alert says both.",
        "security": [
          {
            "apiKey": [
              "dms:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "conversationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "`{ \"body\": \"<the note>\", \"assign\"?: \"<tm_ ref>\" }` — body trimmed, then 1–2,000 characters.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "assign": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "A teammate ref (`tm_…`) this note mentions — also assign them the conversation."
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ ok: true, note: { id, body, author, byAgent, createdAt, mentions: [{ ref, label, role }] }, assigned?: { changed }, assignError?: { error, message } }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/dms/{conversationId}/notes/mentionables": {
      "get": {
        "operationId": "getDmsConversationIdNotesMentionables",
        "tags": [
          "DMs"
        ],
        "summary": "List teammates who can be mentioned on a conversation",
        "description": "Scope: `dms:read`. Needs `dms:read`. The teammates who can be @-mentioned in a note on this DM thread — members who can see its account (never clients). Each is `{ ref, label, role, canAssign, isSelf }`: `ref` is an opaque, stable `tm_…` id for this workspace (write `<@ref>` in a note to mention them), `label` the short name Hayyvn shows (the part of their email before the @), `role` their workspace role, `canAssign` whether they could be assigned the thread. Never a user id or an email (`isSelf` marks the person who created the key). `404 not_found` while teammate mentions are off for the workspace.",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "conversationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ teammates: [{ ref, label, role, canAssign, isSelf }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/dms/{conversationId}/reply": {
      "post": {
        "operationId": "postDmsConversationIdReply",
        "tags": [
          "DMs"
        ],
        "summary": "Reply to a DM",
        "description": "Scope: `dms:reply`. Instagram only, and only within 24 hours of the person’s last message (`409 outside_messaging_window`). Follows the key’s reply mode like comment replies (send mode: at most 20 per key per hour). `humanAgent` is refused for keys (`403 human_agent_not_for_keys`). Send mode never posts the same reply twice: pass `idempotencyKey` (any string ≤ 200, one per reply you mean to send) and reuse it on retry — a repeat returns the first result with `replayed: true`; without one, the same text to the same target within 5 minutes counts as a repeat. `409 send_in_progress` while another send to it is going out; `422 idempotency_key_reused` for a key already used on a different reply. `504 outcome_unknown` (`outcomeUnknown: true`): the platform didn’t answer in time and the reply may be live — a retry is checked against the platform first, and refused with `409 outcome_unknown` while that can’t be confirmed. When Instagram refuses a send: `502 needs_reconnect` (the connection expired), `422 outside_window` / `invalid_recipient`, `429 rate_limited`, `502 provider_error` — each with a readable `message`, never Instagram’s own error text (c650).",
        "security": [
          {
            "apiKey": [
              "dms:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "conversationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  },
                  "humanAgent": {
                    "type": "boolean",
                    "default": false
                  },
                  "humanProof": {
                    "type": "object",
                    "properties": {
                      "focusedAt": {
                        "type": "integer"
                      },
                      "lastKeystrokeAt": {
                        "type": "integer"
                      }
                    },
                    "required": [
                      "focusedAt",
                      "lastKeystrokeAt"
                    ],
                    "additionalProperties": false
                  },
                  "replyDraftId": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "idempotencyKey": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  }
                },
                "required": [
                  "text"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "`{ status: \"drafted\", entryId }` in draft mode; the sent message in send mode (200).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/engage-queue": {
      "get": {
        "operationId": "getEngageQueue",
        "tags": [
          "Comments"
        ],
        "summary": "List reply drafts waiting for approval",
        "description": "Scopes: any of `comments:read`, `dms:read`. Pending reply drafts. Comment and mention drafts need `comments:read`; DM drafts need `dms:read`. People send or dismiss them in the app; `createdByThisKey` marks the ones this key drafted, which it may dismiss (`POST engage-queue/{entryId}`).",
        "security": [
          {
            "apiKey": [
              "comments:read",
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read",
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "assigned",
            "in": "query",
            "description": "`me` = only items assigned to the member the key acts as (its creator).",
            "schema": {
              "type": "string",
              "enum": [
                "me"
              ]
            }
          },
          {
            "name": "channel",
            "in": "query",
            "description": "Only one kind of draft.",
            "schema": {
              "type": "string",
              "enum": [
                "comment",
                "mention",
                "dm"
              ]
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size (1–50, default 20).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The pending drafts. Each says what it answers by id — `commentId`, `conversationId` or `mentionId` (the others null) — with `platformAccountId` and `fromDisplayName`. A comment draft’s `answering` carries the post it is on (`mediaId`, `platformMediaId`, `permalink`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/engage-queue/{entryId}": {
      "post": {
        "operationId": "postEngageQueueEntryId",
        "tags": [
          "Comments"
        ],
        "summary": "Dismiss a reply draft this key created",
        "description": "Scopes: any of `comments:reply`, `dms:reply`. Takes back a draft the key put in the Engage queue (a reply in `draft` mode) before anyone sends it — it is never posted. Keys may only `dismiss`, and only their own drafts (`createdByThisKey` in `GET engage-queue`): `403 people_only` for any other action, `403 api_key_not_draft_owner` for another key’s or a Hayyvn-written draft. A comment or mention draft needs `comments:reply`, a DM draft `dms:reply`. `404 not_found` unknown id; `409 already_resolved` when it was already sent or dismissed.",
        "security": [
          {
            "apiKey": [
              "comments:reply",
              "dms:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:reply",
          "dms:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "entryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "`{ \"action\": \"dismiss\" }` — the only action open to API keys.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "action"
                ],
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "dismiss"
                    ]
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok: true, status: \"dismissed\" }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/engage-queue/expired": {
      "get": {
        "operationId": "getEngageQueueExpired",
        "tags": [
          "Comments"
        ],
        "summary": "List expired reply drafts",
        "description": "Scopes: any of `comments:read`, `dms:read`. Reply drafts that expired unsent, newest first (up to 200). A key sees only the kinds its scopes cover: comment and mention drafts with `comments:read`, DM and private-reply drafts with `dms:read`.",
        "security": [
          {
            "apiKey": [
              "comments:read",
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read",
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ total, items: [{ id, platform, channel, text, author, createdAt, expiredAt }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postEngageQueueExpired",
        "tags": [
          "Comments"
        ],
        "summary": "Reopen expired reply drafts",
        "description": "Scopes: any of `comments:reply`, `dms:reply`. Puts expired drafts back in the Engage queue as ordinary drafts — a person still sends them; they never auto-send. Keys pass `ids` (at most 25, `400 too_many_ids`); `{ all: true }` is people-only (`403 people_only`). A key reopens only the kinds its reply scopes cover (`comments:reply` / `dms:reply`).",
        "security": [
          {
            "apiKey": [
              "comments:reply",
              "dms:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:reply",
          "dms:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "ids": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1
                        },
                        "minItems": 1,
                        "maxItems": 500
                      }
                    },
                    "required": [
                      "ids"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "all": {
                        "type": "boolean",
                        "const": true
                      }
                    },
                    "required": [
                      "all"
                    ],
                    "additionalProperties": false
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok, reopened }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/faqs": {
      "get": {
        "operationId": "getFaqs",
        "tags": [
          "Comments"
        ],
        "summary": "List FAQs",
        "description": "Scopes: any of `comments:read`, `dms:read`. The creator’s saved FAQs: question (`title`), canonical `answer`, trigger keywords, accounts (`accountIds` empty = every account; `scopeLost` = its accounts were removed and it applies to none). Needs `comments:read` or `dms:read`. A key limited to some account groups sees every-account FAQs and FAQs naming only its accounts (one that also names another group’s account is hidden); never a lost-scope FAQ, and nothing at all when its groups give it no accounts. FAQs are changed by people in the app.",
        "security": [
          {
            "apiKey": [
              "comments:read",
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read",
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "stats",
            "in": "query",
            "description": "`1` = add `matchedCount`: reply drafts the FAQ produced (from the caller’s accounts when limited).",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ faqs: [{ id, title, answer, triggerKeywords, accountIds, active, scopeLost, autoAnswer, answerDms, createdAt, matchedCount? }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/ghost-block": {
      "get": {
        "operationId": "getGhostBlock",
        "tags": [
          "Comments"
        ],
        "summary": "List ghost blocks",
        "description": "Scope: `comments:read`. People whose comments are silently hidden, newest first (up to 500). Not available to a key limited to some account groups (`403 access_limited`). A key never receives the platform user id or the `note` a person left; `targetUsername` is the handle without `@`, or null when only the user id is known. Adding and removing ghost blocks is for people in the app.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "counts",
            "in": "query",
            "description": "`1` = add `commentsHidden` per entry and `countsWindowDays` (90): how many of each person’s comments the ghost block hid in that window that are still hidden (later unhides don’t count).",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ entries: [{ id, platform, targetUsername, targetDisplayName, reason, addedAt, commentsHidden? }], countsWindowDays? }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/insights": {
      "get": {
        "operationId": "getInsights",
        "tags": [
          "Insights"
        ],
        "summary": "Account insights (the Analytics page)",
        "description": "Scope: `insights:read`. Per connected account (active only): follower/subscriber history from daily snapshots (`followers`, 90 days, with Instagram follows vs unfollows), Instagram account insights (`instagram`: reach, accounts engaged, interactions, views, profile link taps — 30 days; `error: \"insights_unavailable\"` when Instagram didn’t answer), YouTube channel analytics (`youtube`: views, engaged views, minutes watched, subscribers gained/lost, traffic sources — 28 days), TikTok account + video totals (`tiktok`, stored data), recent Instagram stories, and group rollups (`groups`, when the workspace uses groups and no `account` is given). Instagram and YouTube numbers are cached about an hour. Keys: up to 30 calls an hour per key. Unknown group → 404 `group_not_found`; `account` naming only accounts outside the scope → 404 `account_not_found`.",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "account",
            "in": "query",
            "description": "Only these accounts (comma-separated account ids). Ids outside the group / your access are ignored.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Only this account group: a group id, its name, or \"none\" for accounts in no group.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The insights.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/library": {
      "get": {
        "operationId": "getLibrary",
        "tags": [
          "Media"
        ],
        "summary": "List library items",
        "description": "Scope: `posts:read`. The workspace’s content library (saved images and videos) plus its folders. Each asset’s `url` is a media ref `POST composes` accepts in `defaultMediaRefs`. A key limited to some account groups sees only its groups’ folders (never the root). Without `limit` the listing is the app’s (root or one folder, up to 200); with it, newest first + `nextCursor`.",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "`nextCursor` from the previous page, unchanged (needs `limit`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "everywhere",
            "in": "query",
            "description": "`1` = every folder and the root at once.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          },
          {
            "name": "folderId",
            "in": "query",
            "description": "Only this folder’s assets (default: the root).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "kind",
            "in": "query",
            "description": "Only images or only videos.",
            "schema": {
              "type": "string",
              "enum": [
                "image",
                "video"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size, 1–100 (enables `nextCursor`).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Search titles and captions across all folders.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "removed",
            "in": "query",
            "description": "`1` = the Removed list instead.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ assets: [{ id, kind, url, title, bytes, contentType, durationSec, width, height, defaultCaption, folderId, timesPublished, lastPublishedAt, createdAt }], folders: [{ id, parentId, name, groupId, groupName, assetCount }], groups, lens, rootWritable, nextCursor? }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media": {
      "get": {
        "operationId": "getMedia",
        "tags": [
          "Insights"
        ],
        "summary": "List published posts",
        "description": "Scope: `insights:read`. Every post the connected accounts published, as Hayyvn has stored it (not only posts Hayyvn scheduled), newest first, with cached numbers: likes/comments as of `countsUpdatedAt`, views/reach/saves/shares as of `insightsUpdatedAt`. No platform call — use `media-stats` with the `mediaId` for fresh numbers. A YouTube video also carries `playlists: [{ id, title }]` — the playlists Hayyvn put it in (null on other platforms) — change them with `POST` / `DELETE media/{mediaId}/playlists` (c569). A YouTube video also carries `youtube: { title, tags, firstComment: { posted } }` — title and tags as Hayyvn last saw them (both null when not known yet; `youtube` is null on other platforms) — change them with `PATCH media/{mediaId}/details`; `firstComment.posted` says whether Hayyvn posted the channel’s first comment (c570). A YouTube video also carries `captions: [{ language, name }]` — the subtitle tracks Hayyvn put on it (never YouTube’s caption ids; null on other platforms) — change them with `POST` / `DELETE media/{mediaId}/captions` (c568). `type=story` lists Instagram stories instead (views, reach, replies, `expiresAt`). Disconnected accounts are left out unless `accountId` names one. A YouTube video YouTube rejected or removed after upload is not live and is left out (it stays on its post, under the failed job — `GET scheduled-posts`).",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "Only this connected account.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "`nextCursor` from the previous page, unchanged.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size, 1–100 (default 25).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "platform",
            "in": "query",
            "description": "Only this platform.",
            "schema": {
              "type": "string",
              "enum": [
                "instagram",
                "youtube",
                "tiktok"
              ]
            }
          },
          {
            "name": "since",
            "in": "query",
            "description": "Only posts published at or after this ISO date/time.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "type",
            "in": "query",
            "description": "`photo`, `video` (incl. reels), `carousel`, or `story`.",
            "schema": {
              "type": "string",
              "enum": [
                "photo",
                "video",
                "carousel",
                "story"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ posts: [{ mediaId, platformMediaId, platform, type, permalink, caption, postedAt, firstSeenAt, views, likes, comments, shares, saves, reach, countsUpdatedAt, insightsUpdatedAt, visibility, thumbnail, account: { id, name } }], nextCursor }` — `visibility` is a YouTube video’s `public` / `unlisted` / `private` as Hayyvn last saw it (null on other platforms or when not known yet). `thumbnail` is `{ custom }` on a YouTube video — whether Hayyvn set a custom thumbnail on it — and null elsewhere.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media-kit": {
      "get": {
        "operationId": "getMediaKit",
        "tags": [
          "Insights"
        ],
        "summary": "List media kits",
        "description": "Scope: `insights:read`. The workspace’s media kits (public page `/kit/{slug}` when `published`). A key limited to some account groups sees only kits that follow one of its groups or show only its accounts. A key never receives `contactEmail`, and gets `audience`, `rateCard` and `brands` only for a published kit (what its public page shows). Editing kits is for people in the app.",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ kits: [{ id, title, slug, published, displayName, tagline, bio, niche, location, avatarUrl, coverUrl, highlights, rateCardId, platformAccountIds, channelScope, groupId, acceptInquiries, showDemographics, showFollowerChart, updatedAt, audience?, rateCard?, brands? }] }` (`audience` / `rateCard` / `brands` on published kits only).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media-stats": {
      "get": {
        "operationId": "getMediaStats",
        "tags": [
          "Insights"
        ],
        "summary": "Per-post stats",
        "description": "Scope: `insights:read`. Views, likes, comments, shares, saves, reach and average view % for up to 50 YouTube, Instagram or TikTok posts. Items are our `mediaId`s (from `GET media`), platform media ids or public links (`youtube.com/shorts/<id>`, `youtu.be/<id>`, `instagram.com/reel/<code>/`, `tiktok.com/@<name>/video/<id>` …). `accountId` is optional when the items identify their account (a `mediaId`, or a post Hayyvn has stored); an item it can’t place gets `error: \"account_required\"`. TikTok numbers are the stored ones (refreshed by Hayyvn’s scans, no platform call). Answers are cached (1 hour for posts under 48 hours old, up to 24 hours for older ones), so polling is cheap. A failing item sets its own `error` without failing the call. Limits: 60 requests per minute per key and 300 per hour per workspace (`429 rate_limited`, `Retry-After`); at most 5 accounts per call (`too_many_accounts`).",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "The connected account the posts belong to (optional when the items identify it).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "items",
            "in": "query",
            "required": true,
            "description": "Comma-separated mediaIds, media ids or links (max 50).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ cached, items: [{ key, mediaId, accountId, platform, externalId, permalink, views, likes, comments, shares, saves, reach, avgViewPct, fetchedAt, error }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media/{mediaId}/captions": {
      "delete": {
        "operationId": "deleteMediaMediaIdCaptions",
        "tags": [
          "Posts"
        ],
        "summary": "Remove a YouTube subtitle track",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Removes the subtitle track Hayyvn put on a published YouTube video in `?language=` (deleted on YouTube; adding it back needs the file again). `404 caption_not_found` when Hayyvn hasn’t put that language there; a track already removed in YouTube Studio counts as removed. Needs `posts:schedule`; same gates as `POST`. Uses 50 units of the day’s YouTube quota. Audited as `media.captions_changed` (`action: removed`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "language",
            "in": "query",
            "description": "The track’s language code, as `GET` lists it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ mediaId, action: \"removed\", captions: [{ language, name, uploadedAt }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "get": {
        "operationId": "getMediaMediaIdCaptions",
        "tags": [
          "Posts"
        ],
        "summary": "List a YouTube video’s subtitles",
        "description": "Scope: `posts:read`. The subtitle tracks Hayyvn put on a published YouTube video — language, name and when — never YouTube’s caption ids. `mediaId` is Hayyvn’s id (`GET media` → `mediaId`); the YouTube video id is accepted too. Needs `posts:read`. YouTube only (`400 not_supported`); `404 not_found` for an unknown post or one on an account the key can’t see.",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ mediaId, captions: [{ language, name, uploadedAt }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postMediaMediaIdCaptions",
        "tags": [
          "Posts"
        ],
        "summary": "Add or replace a YouTube subtitle track",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Adds a subtitle track to a published YouTube video, or — when Hayyvn already put one in that language there — replaces its file (the track keeps its name). Body `{ ref, language, name? }`: `ref` a Hayyvn upload (`POST uploads`) of an SRT or WebVTT file, ≤ 1 MB, with real cues; `language` a code like `en`, `es-419`; `name` ≤ 150 characters, no `<` `>` (`400 invalid_captions` otherwise). Up to 5 tracks per video (`400 too_many_captions`). Needs `posts:schedule`. YouTube only (`400 not_supported`); `404 not_found` for an unknown post or one on an account the key can’t see; `409` while the account is being handed back to its creator; `400 account_or_token_missing` when the channel isn’t connected; `404 video_not_found` when YouTube no longer has it. Each upload uses 400 units of the day’s YouTube quota — a large share (`429 youtube_quota_exhausted`, nothing changed); at most 10 changes per hour per workspace (`429 rate_limited`). Audited as `media.captions_changed` (`language`, `action`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ref": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "language": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 40
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": [
                  "ref",
                  "language"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ mediaId, action: \"added\" | \"replaced\", captions: [{ language, name, uploadedAt }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media/{mediaId}/details": {
      "patch": {
        "operationId": "patchMediaMediaIdDetails",
        "tags": [
          "Posts"
        ],
        "summary": "Edit a YouTube video’s details",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Changes a published YouTube video’s title, description and/or tags without re-uploading it. Body `{ title?, description?, tags? }` — at least one; only what you send changes. `title` ≤ 100 characters; `description` ≤ 5,000 bytes and replaces the whole description; `tags` replaces the whole list (≤ 30, each ≤ 100 characters, ≤ 500 in total; `[]` removes them); no `<` or `>` in any (`400 invalid_youtube_title` / `invalid_youtube_description` / `invalid_youtube_tags`). Everything else on the video (category, languages) is kept: Hayyvn reads the current details and sends them back with only these changed. `mediaId` is Hayyvn’s id (`GET media` → `mediaId`, or a YouTube job’s `mediaId` in `GET scheduled-posts`); the YouTube video id is accepted too. Needs `posts:schedule`. YouTube only (`400 not_supported`); `404 not_found` for an unknown post or one on an account the key can’t see; `400 account_or_token_missing` when the channel isn’t connected; `404 video_not_found` when YouTube no longer has it. YouTube is always read first (what Hayyvn stored may be stale): already that way there → `200` with `unchanged: true`, nothing changed (1 unit used). An account being handed back to its creator → `409`. Each edit reserves 51 units of the day’s YouTube quota (`429 youtube_quota_exhausted`, nothing changed); at most 30 edits per hour per workspace (`429 rate_limited`). Audited as `media.details_changed` (which fields, never their text).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 20000
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 500
                    },
                    "maxItems": 100
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ mediaId, title, description, tags }` (null when Hayyvn doesn’t know a field yet; plus `unchanged: true` when nothing changed)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media/{mediaId}/first-comment": {
      "get": {
        "operationId": "getMediaMediaIdFirstComment",
        "tags": [
          "Comments"
        ],
        "summary": "Get a YouTube video’s first comment",
        "description": "Scope: `comments:read`. Whether Hayyvn posted the channel’s first comment on this published YouTube video, and which. `mediaId` is Hayyvn’s id (`GET media` → `mediaId`); the YouTube video id is accepted too. Needs `comments:read`. YouTube only (`400 not_supported`); `404 not_found` for an unknown post or one on an account the key can’t see. `text` is the comment as Hayyvn last read it (null until it’s ingested); `error` says why the one set at publish wasn’t posted (`comments_disabled`, `quota` — retrying —, `gave_up`, `account_unavailable`, `unknown`, …). `unconfirmed: true` = a send got no answer from YouTube, so it may be live: nothing posts again until a person checks YouTube and clears it in Hayyvn.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ mediaId, posted, unconfirmed, commentId, postedAt, url, text, error }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postMediaMediaIdFirstComment",
        "tags": [
          "Comments"
        ],
        "summary": "Post a YouTube video’s first comment",
        "description": "Scope: `comments:reply`. Posts the channel’s own top-level comment on a published YouTube video (usually a link — `GET affiliate-links` has the short links). Body `{ text }`: trimmed, ≤ 2,000 characters including the key’s disclosure, no `<` `>` (`400 invalid_first_comment`). One per video: a video that has one → `409 already_posted` with its `commentId` (also while another send is posting it). Needs `comments:reply` and a key in **send** mode — a draft-mode key gets `403 draft_mode_cannot_send` (there is no queue entry to draft a top-level comment into); a send counts against the key’s hourly direct-send cap (`429 agent_send_limit`) and carries its disclosure. YouTube only (`400 not_supported`); `404 not_found` for an unknown post or one on an account the key can’t see; `400 account_or_token_missing` when the channel isn’t connected; `404 video_not_found` when YouTube no longer has it; comments off on the video (made for kids, or turned off) → `409 comments_disabled`; `409` while the account is being handed back to its creator. Pinning has no API — pin it in YouTube Studio. Each post uses 50 units of the day’s YouTube quota (`429 youtube_quota_exhausted`, nothing posted); at most 10 per hour per workspace (`429 rate_limited`). The key’s send slot is spent only once the video is claimed and the quota reserved. When YouTube gives no answer (timeout / network / 5xx) the comment may be live: `502 result_unknown`, and every later send gets `409 first_comment_unconfirmed` until a person checks YouTube and clears it in Hayyvn. Audited as `media.first_comment_posted`.",
        "security": [
          {
            "apiKey": [
              "comments:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "maxLength": 10000
                  }
                },
                "required": [
                  "text"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ mediaId, posted: true, commentId, postedAt, url, text }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media/{mediaId}/playlists": {
      "get": {
        "operationId": "getMediaMediaIdPlaylists",
        "tags": [
          "Posts"
        ],
        "summary": "List a YouTube video’s playlists",
        "description": "Scope: `posts:read`. The playlists Hayyvn put a published YouTube video in (at publish or with `POST`) — `{ id, title }` only. Playlists it was added to in YouTube Studio aren’t known here. `mediaId` is Hayyvn’s id (`GET media` → `mediaId`); the YouTube video id is accepted too. Needs `posts:read`. `404 not_found` for an unknown post or one on an account the key can’t see.",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ mediaId, playlists: [{ id, title }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postMediaMediaIdPlaylists",
        "tags": [
          "Posts"
        ],
        "summary": "Add a YouTube video to a playlist",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Adds a published YouTube video to one of its channel’s playlists. Body `{ playlistId }` (from `GET accounts/{accountId}/youtube/playlists`; `400 unknown_playlist` when it isn’t the channel’s). Already added by Hayyvn → `200` with `unchanged: true`, nothing sent (YouTube would add it a second time). Needs `posts:schedule`. YouTube only (`400 not_supported`); `404 not_found` for an unknown post or one on an account the key can’t see; `400 account_or_token_missing` when the channel isn’t connected; `409` while the account is being handed back to its creator. Uses 50 units of the day’s YouTube quota (`429 youtube_quota_exhausted`, nothing changed); at most 30 playlist changes per hour per workspace (`429 rate_limited`). Audited as `media.playlist_changed`.",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "playlistId": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{10,64}$"
                  }
                },
                "required": [
                  "playlistId"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ mediaId, playlists: [{ id, title }] }` (plus `unchanged: true` when it was already in it)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media/{mediaId}/playlists/{playlistId}": {
      "delete": {
        "operationId": "deleteMediaMediaIdPlaylistsPlaylistId",
        "tags": [
          "Posts"
        ],
        "summary": "Remove a YouTube video from a playlist",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Takes a published YouTube video out of a playlist Hayyvn put it in; add it back with `POST`. `404 not_in_playlist` when Hayyvn has no record of it (added in YouTube Studio — remove it there). Needs `posts:schedule`. Same gates as `POST`: YouTube only, the key’s accounts, `409` during a hand-back; 50 units of the day’s YouTube quota; 30 changes per hour per workspace. Audited as `media.playlist_changed`.",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "playlistId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ mediaId, playlists: [{ id, title }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media/{mediaId}/thumbnail": {
      "patch": {
        "operationId": "patchMediaMediaIdThumbnail",
        "tags": [
          "Posts"
        ],
        "summary": "Set a YouTube video’s thumbnail",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Sets or changes a published YouTube video’s custom thumbnail without re-uploading it. Body `{ thumbnailRef }`: a Hayyvn image URL — an upload (`POST uploads`) or a library item’s `url` — JPEG or PNG, ≤ 2 MB, at least 640×360 (1280×720 is best); `400 invalid_thumbnail` otherwise. `mediaId` is Hayyvn’s id (`GET media` → `mediaId`, or a YouTube job’s `mediaId` in `GET scheduled-posts`); the YouTube video id is accepted too. Needs `posts:schedule`. The channel must be verified for custom thumbnails: `409 channel_not_verified` (with `verifyUrl`) otherwise. YouTube only (`400 not_supported`); `404 not_found` for an unknown post or one on an account the key can’t see; `400 account_or_token_missing` when the channel isn’t connected; `404 video_not_found` when YouTube no longer has it; `409` while the account is being handed back to its creator. A successful change also clears a thumbnail that didn’t take at publish. Each change uses 50 units of the day’s YouTube quota (`429 youtube_quota_exhausted`, nothing changed); at most 30 changes per hour per workspace (`429 rate_limited`). Audited as `media.thumbnail_changed`.",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "thumbnailRef": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  }
                },
                "required": [
                  "thumbnailRef"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ mediaId, customThumbnail: true }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/media/{mediaId}/visibility": {
      "patch": {
        "operationId": "patchMediaMediaIdVisibility",
        "tags": [
          "Posts"
        ],
        "summary": "Change a YouTube video’s visibility",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Changes a published YouTube video to `public`, `unlisted` or `private` without re-uploading it — e.g. publish unlisted for review, make it public later. `mediaId` is Hayyvn’s id (`GET media` → `mediaId`, or `GET scheduled-posts` → a YouTube job’s `mediaId`); the YouTube video id is accepted too. Making a video **public** is publishing it, so a key needs `posts:publish` for that value (`403 api_key_missing_scope` naming it); `unlisted` and `private` need `posts:schedule`. YouTube only (`400 not_supported` for an Instagram or TikTok post); `404 not_found` for an unknown post or one on an account the key can’t see; `400 account_or_token_missing` when the channel isn’t connected; `404 video_not_found` when YouTube no longer has it. YouTube is always read first (what Hayyvn stored may be stale): already at that value there → `200` with `unchanged: true`, nothing changed (1 unit used). An account being handed back to its creator → `409`. Each change reserves 51 units of the day’s YouTube quota (`429 youtube_quota_exhausted`, nothing changed); at most 30 changes per hour per workspace (`429 rate_limited`). Audited as `media.visibility_changed`.",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "privacyStatus": {
                    "type": "string",
                    "enum": [
                      "public",
                      "unlisted",
                      "private"
                    ]
                  }
                },
                "required": [
                  "privacyStatus"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ mediaId, privacyStatus }` (plus `unchanged: true` when it already had that value)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/mentions": {
      "get": {
        "operationId": "getMentions",
        "tags": [
          "Comments"
        ],
        "summary": "List mentions",
        "description": "Scope: `comments:read`. Where people @-mention the creator (captions, comments, replies, stories), unhandled first then newest. `404` while mentions are turned off for Hayyvn. A key limited to some account groups sees only its accounts’ mentions. No platform user ids or avatar URLs.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "Only this connected account (an `id` from `GET connections`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "The previous page’s `nextCursor`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size (1–100, default 50).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "platform",
            "in": "query",
            "description": "Only this platform.",
            "schema": {
              "type": "string",
              "enum": [
                "instagram",
                "tiktok",
                "youtube"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Search the mention text and the author’s handle (at most 200 characters).",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "tab",
            "in": "query",
            "description": "`unhandled`, `collab` or `complaints` (default: all).",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "unhandled",
                "collab",
                "complaints"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ total, unhandled, nextCursor, mentions: [{ id, platform, account {id, name}, text, fromUsername, mentionType, intent, priority, sentiment, opportunityId, permalink, hasDraft, replyable, handled, at }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "operationId": "patchMentions",
        "tags": [
          "Comments"
        ],
        "summary": "Mark a mention handled",
        "description": "Scope: `comments:reply`. Body `{ id, handled }`. Local to Hayyvn — nothing changes on the platform. Keys need `comments:reply`; audited with the key (`mention.handled_changed`).",
        "security": [
          {
            "apiKey": [
              "comments:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/mentions/{mentionId}/notes": {
      "get": {
        "operationId": "getMentionsMentionIdNotes",
        "tags": [
          "Comments"
        ],
        "summary": "Read a mention’s internal notes",
        "description": "Scope: `comments:read`. Needs `comments:read`. The team’s internal notes on a mention (never posted), oldest first. Keys see live notes only; `author` is \"Agent · <key name>\" for a note an API key wrote, otherwise the writer’s role (\"Teammate · admin\") or \"Former member\" — never an email or user id. Teammate mentions read as `@label` in `body`, and `mentions` lists them as `{ ref, label, role }`. `404` while mentions or teammate mentions are turned off.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mentionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ notes: [{ id, body, author, byAgent, createdAt, mentions: [{ ref, label, role }] }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postMentionsMentionIdNotes",
        "tags": [
          "Comments"
        ],
        "summary": "Add an internal note to a mention",
        "description": "Scope: `comments:moderate`. Needs `comments:moderate`. An internal note for the team (1–2,000 characters after trimming) — never posted to the platform. It shows as \"Agent · <key name>\"; people can remove and restore it in the app. Keys: at most 60 notes per key per hour across comment, DM, mention and opportunity notes (`429 agent_note_limit`, fails closed). Mention teammates with `<@ref>` tokens (refs from `GET …/mentions/{mentionId}/notes/mentionables`); at most 10 per note, and anyone who can’t see this account fails the whole note (`422 mention_not_eligible`, nothing saved; `422 too_many_mentions` past 10). `assign` (a `<@ref>` this note mentions) also assigns the mention’s pending reply draft — when there is none the note is still saved and `assignError` says why. `404` while mentions or teammate mentions are turned off.",
        "security": [
          {
            "apiKey": [
              "comments:moderate"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:moderate"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mentionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "`{ \"body\": \"<the note>\", \"assign\"?: \"<tm_ ref>\" }` — body trimmed, then 1–2,000 characters.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "assign": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "A teammate ref (`tm_…`) this note mentions — assign them the mention’s pending reply draft too."
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ ok: true, note: { id, body, author, byAgent, createdAt, mentions: [{ ref, label, role }] }, assigned?: { changed }, assignError?: { error, message } }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/mentions/{mentionId}/notes/mentionables": {
      "get": {
        "operationId": "getMentionsMentionIdNotesMentionables",
        "tags": [
          "Comments"
        ],
        "summary": "List teammates who can be mentioned on a mention",
        "description": "Scope: `comments:read`. Needs `comments:read`. The teammates who can be @-mentioned in a note on this platform mention — members who can see its account (never clients). Each is `{ ref, label, role, canAssign, isSelf }`: `ref` is an opaque, stable `tm_…` id for this workspace (write `<@ref>` in a note to mention them), `label` the short name Hayyvn shows, `role` their workspace role, `canAssign` whether they could be assigned the mention’s pending reply draft (always false when it has none). Never a user id or an email. `404` while mentions or teammate mentions are turned off.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mentionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ teammates: [{ ref, label, role, canAssign, isSelf }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/mentions/{mentionId}/reply": {
      "post": {
        "operationId": "postMentionsMentionIdReply",
        "tags": [
          "Comments"
        ],
        "summary": "Draft a reply to a mention",
        "description": "Scope: `comments:reply`. For a key this is ALWAYS a draft, whatever its reply mode: the reply waits in the Engage queue for a person to send (`202 {status:\"drafted\", entryId}`); a key never posts on someone else’s post. Instagram comment and caption mentions only (`400 not_replyable`); the key’s disclosure and the mentioner’s @handle must fit 2,200 characters (`400 too_long`). Refused like comment drafts: `409 reply_already_pending`, `409 reply_already_sent`, `429 agent_draft_limit`, `429 agent_draft_backlog`.",
        "security": [
          {
            "apiKey": [
              "comments:reply"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:reply"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "mentionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2200
                  },
                  "idempotencyKey": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  }
                },
                "required": [
                  "message"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "`{ ok, status: \"drafted\", entryId, replacedExistingDraft }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/moderation-audit": {
      "get": {
        "operationId": "getModerationAudit",
        "tags": [
          "Comments"
        ],
        "summary": "Moderation history",
        "description": "Scope: `comments:read`. What was done to comments (and, with `dms:read`, DMs), newest first: hide, delete, block_user, hold_for_review…, to what (comment id, a short excerpt, author handle, account), whether it worked and who did it — `rule:<rule>`, `autonomy`, `person` (with their role) or `agent:<key name>`, never an email or user id. Replies, DMs sent and likes are not in it (`400`). A key limited to some account groups sees only its accounts’ rows; another group’s `accountId` is `404`. Keys get no raw error text and no platform user id.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "Only this connected account.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "action",
            "in": "query",
            "description": "Only this action, e.g. `hide`, `delete`, `block_user`, `hold_for_review`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "authorHandle",
            "in": "query",
            "description": "Only actions on this person’s comments (a leading `@` is ignored).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "commentId",
            "in": "query",
            "description": "Our comment id (from `GET comments`) or the platform comment id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "`nextCursor` from the previous page, unchanged.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size (1–100, default 50).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "since",
            "in": "query",
            "description": "Only actions at or after this ISO date/time.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ items: [{ id, at, action, target: { kind, commentId, platformCommentId, excerpt, authorHandle, platform, account: { id, name } }, outcome, simulated, actor, ruleId, reason }], nextCursor }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/offers": {
      "get": {
        "operationId": "getOffers",
        "tags": [
          "DMs"
        ],
        "summary": "List offers",
        "description": "Scope: `dms:read`. The creator’s offers (discount / link / pitch) with the `code` and `url` meant for fans, accounts (`accountIds` empty = every account) and `campaignsUsing` (live auto-DM campaigns using it). A key limited to some account groups sees every-account offers and offers naming only its accounts (an offer also scoped to another group’s account is hidden — its code and text were written for both; `campaignsUsing` counts only its accounts’ campaigns); never a lost-scope offer, and nothing when its groups give it no accounts. Offers are changed by people in the app.",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ offers: [{ id, name, kind, body, code, url, accountIds, active, scopeLost, createdAt, campaignsUsing }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/opportunities": {
      "get": {
        "operationId": "getOpportunities",
        "tags": [
          "DMs"
        ],
        "summary": "List opportunities",
        "description": "Scope: `dms:read`. The deal pipeline built from DMs. Each deal carries `accountId` (its own account, else its conversation’s). A deal counts for a group through its account or its conversation’s account; unattributed deals appear only without `group`.",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size (default 20).",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "maybes",
            "in": "query",
            "description": "`1` = the low-confidence tier instead.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Default `open`. `all` leaves archived deals out; `archived` lists only those.",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "won",
                "lost",
                "archived",
                "all"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The opportunities.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/opportunities/{oppId}": {
      "get": {
        "operationId": "getOpportunitiesOppId",
        "tags": [
          "DMs"
        ],
        "summary": "Get an opportunity",
        "description": "Scope: `dms:read`. Needs `dms:read`. One deal in full: stage, category, brand, summary, confidence, deal value + currency, due date, next follow-up, `conversationId`, `from`, `followUpDraft` (the parked AI follow-up, or null), `notes` (authors as \"Agent · <key name>\" or \"Teammate · <role>\" — never an email or user id; teammate mentions as `@label` plus `mentions: [{ ref, label, role }]`) and `timeline`. Never the contact email or the commission split. `404 not_found` for an unknown id, another group’s or an unattributed deal (group-limited keys), or a deal on a disconnected account.",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "oppId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ opportunity: { id, status, …, notes: [{ id, body, author, byAgent, createdAt }], timeline: [{ at, kind, by, … }] } }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postOpportunitiesOppId",
        "tags": [
          "DMs"
        ],
        "summary": "Move an opportunity to another stage",
        "description": "Scope: `opportunities:write`. Needs `opportunities:write`. Keys may send only `{ \"action\": \"status\", \"status\": … }` with `new`, `qualifying`, `negotiating`, `lost` or `archived`. `won`, moving a deal that is already won (both touch the commission) and every other action (`send_question`, `approve_follow_up`, `dismiss_follow_up`) are `403 people_only`. The same stage again is `200` with `unchanged: true` and changes nothing. The move only lands if the deal is still in the stage the key read: a deal a person moved (or marked won) in between is `409 deal_changed`, nothing written. A key’s close records no person as `resolvedBy`; the audit carries the key. Local to Hayyvn. `404 not_found` as for GET (including a deal on a disconnected account).",
        "security": [
          {
            "apiKey": [
              "opportunities:write"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "opportunities:write"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "oppId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true, status }` (plus `unchanged: true` when it was already there)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/opportunities/{oppId}/notes": {
      "post": {
        "operationId": "postOpportunitiesOppIdNotes",
        "tags": [
          "DMs"
        ],
        "summary": "Add a note to an opportunity",
        "description": "Scope: `opportunities:write`. Needs `opportunities:write`. A note for the team (1–2,000 characters after trimming) — never sent to the brand. It shows as \"Agent · <key name>\". `404 not_found` as for GET (including a deal on a disconnected account). At most 60 notes per key per hour across comment, DM and opportunity notes (`429 agent_note_limit`, fails closed; a note that fails to save gives its slot back). Plan 49: mention teammates with `<@ref>` tokens (refs from `GET …/opportunities/{oppId}/notes/mentionables`); at most 10 per note, and anyone who can’t see every account the deal names fails the whole note (`422 mention_not_eligible`, nothing saved).",
        "security": [
          {
            "apiKey": [
              "opportunities:write"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "opportunities:write"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "oppId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  }
                },
                "required": [
                  "body"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok: true, note: { id, body, author, byAgent, createdAt } }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/opportunities/{oppId}/notes/mentionables": {
      "get": {
        "operationId": "getOpportunitiesOppIdNotesMentionables",
        "tags": [
          "DMs"
        ],
        "summary": "List teammates who can be mentioned on an opportunity",
        "description": "Scope: `dms:read`. Needs `dms:read`. The teammates who can be @-mentioned in a note on this deal — members who can see every account it names (its own and its DM thread’s; an unattributed deal: members with access to every account). `canAssign` is always false (deals have no assignee). Each is `{ ref, label, role, canAssign, isSelf }`: `ref` is an opaque, stable `tm_…` id for this workspace (write `<@ref>` in a note to mention them), `label` the short name Hayyvn shows (the part of their email before the @), `role` their workspace role. Never a user id or an email (`isSelf` marks the person who created the key). `404 not_found` while teammate mentions are off for the workspace. `404 not_found` as for GET opportunity.",
        "security": [
          {
            "apiKey": [
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "oppId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ teammates: [{ ref, label, role, canAssign: false, isSelf }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/people/{platform}/{userId}": {
      "get": {
        "operationId": "getPeoplePlatformUserId",
        "tags": [
          "Comments"
        ],
        "summary": "Get a person",
        "description": "Scope: `comments:read`. Everything about one commenter on one platform: who they are, their standing (`trusted`, `blocked`, `restricted` or `normal`) with its detail (for a restriction: comments kept hidden, approvals in a row, when it lifts and who put it on — `you`, `teammate`, `rule`, `agent`, `import` or `automatic`), pending Review items, superfan tier (needs `insights:read`), a pending block suggestion, their newest 20 comments (status `visible` / `hidden` / `deleted`, account, post) with counters over the last 18 months, and the newest 20 moderation-history rows (the `GET moderation-audit` row). A key asks by handle: `{userId}` is then the handle (with or without `@`) and `by=handle` — keys never hold platform user ids (`409 ambiguous_handle` when two people used it). A key limited to some account groups gets only its accounts’ comments, counters and history; the standing, lists, pending, superfan and block-suggestion fields are `null` for it, and the person is `404 not_found` unless they commented on its accounts. Keys get no `person.userId`, no avatar, no trusted note or block reason, the trimmed history row, and `canAct` all false. At most 120 reads per minute per caller (`429 rate_limited`).",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "platform",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "by",
            "in": "query",
            "description": "`handle` = `{userId}` is the person’s handle, not the platform user id.",
            "schema": {
              "type": "string",
              "enum": [
                "handle"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ person: { platform, username, displayName, avatarUrl, firstSeenAt, lastSeenAt, ownAccount }, counts: { comments, hidden, deleted, visible }, standing, standingDetail, lists, pending: { restrictedWaiting, reviewWaiting }, superfan: { tier, score, rank, lastActiveAt }, blockSuggestion: { id, status, reasons }, comments: [{ id, platformCommentId, text, at, status, account: { id, name }, post: { mediaId, permalink, caption }, aiToxicity, aiSentiment }], commentsNextCursor, history, canAct }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/personas": {
      "get": {
        "operationId": "getPersonas",
        "tags": [
          "Comments"
        ],
        "summary": "List personas",
        "description": "Scope: `comments:read`. The reply voices. A key gets each live persona’s `name`, a style summary of at most 300 characters (tone, formality, emoji, length and signature only — never the free-text extra instructions or guardrails) and what it `covers`: platform defaults (`slots`), per-account overrides (`accounts`) and group voices (`groups`), per channel — never the voice settings, knowledge, lessons or training examples. A key limited to some account groups sees personas covering its accounts, its groups, or a platform it has an account on, with coverage trimmed to its own. Personas are changed by people in the app.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "For a key: `{ personas: [{ id, name, styleSummary, covers: { slots: [{ platform, channelType }], accounts: [{ platformAccountId, platform, name, channelType }], groups: [{ groupId, name, channelType }] } }], parked: [], removed: [] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/posting-schedules": {
      "get": {
        "operationId": "getPostingSchedules",
        "tags": [
          "Posts"
        ],
        "summary": "List auto-post schedules",
        "description": "Scope: `posts:read`. Recurring auto-post schedules (posting from the library): cadence, accounts, status + `pausedReason`, `nextAt`, `pending` drafts waiting to be scheduled (each with `composeId`, `occurrenceAt`, `caption`, `asset { assetId, title, kind, removed }`), `lastMaterializedAt`. Creating, switching on and changing schedules are people-only; a `posts:schedule` key can schedule or skip `pending` drafts (below). A limited key sees only schedules whose every account is its own.",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "removed",
            "in": "query",
            "description": "`1` = the Removed list instead.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ schedules, meta }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/posting-schedules/{scheduleId}/pending/{composeId}/schedule": {
      "post": {
        "operationId": "postPostingSchedulesScheduleIdPendingComposeIdSchedule",
        "tags": [
          "Posts"
        ],
        "summary": "Schedule a pending auto-post draft",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Schedules a draft an auto-post schedule prepared (`composeId` from `GET posting-schedules` → `pending`) to the schedule’s accounts, with its stored caption and media. The draft was made by the schedule, so any key that sees the schedule may use it; the post records the key (it can then reschedule / cancel it). A `publishAt` at least 5 minutes ahead needs `posts:schedule`; sooner (now) needs `posts:publish` — otherwise `403 api_key_missing_scope` naming the scope. Monthly post limit, approval policies and platform rules apply as for `POST composes`. A schedule paused for a plan or limit reason (`plan`, `quota`, `daily_cap`, `kill_switch`) is `409 schedule_paused` for keys. While auto-posting is turned off for maintenance, every call is `409 auto_post_off`. A limited key: the draft’s library items must still be in its groups’ folders (`400 library_item_not_available`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "scheduleId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "composeId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "publishAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "publishAt"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ ok: true, scheduledPostId }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/posting-schedules/{scheduleId}/pending/{composeId}/skip": {
      "post": {
        "operationId": "postPostingSchedulesScheduleIdPendingComposeIdSkip",
        "tags": [
          "Posts"
        ],
        "summary": "Skip a pending auto-post draft",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Passes on a draft an auto-post schedule prepared: it stops waiting and stays in the drafts list (nothing is deleted). `404` when it is no longer waiting.",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "scheduleId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "composeId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/posting-times": {
      "get": {
        "operationId": "getPostingTimes",
        "tags": [
          "Insights"
        ],
        "summary": "Recommended posting times",
        "description": "Scope: `insights:read`. Per connected Instagram, YouTube and TikTok account (disconnected ones hidden): suggested days and times to post, per kind of post (Instagram reel, photo, carousel, story; YouTube short, long; TikTok video), in the workspace time zone (`timezone`; `timezoneIsDefault: true` while it is still UTC). Each kind has a `basis` — `personal` (the creator’s own results), `same_time_habit` (they always post at one time, so there is nothing to compare yet), `audience_online` (when followers are online; not YouTube), `starting_point` (no history yet: a general starting point from what the account posts about — never a measured result, and its slots carry no numbers) or `none` — plus `slots`, `tryInstead`, `pace` (`typicalPerWeek`, `suggestedPerWeek`), `reason` (`key` + `values` for building your own sentence) and `nextSlots` (the next free instants, ISO, skipping any time within 2 hours of a post already scheduled on that account). `lift` is only set for the creator’s own results backed by enough posts. `status: \"pending\"` = nothing computed yet. Stored results only — no platform or AI call. No plan needed. Keys: up to 60 calls an hour per key; keys get no `starter.audienceSummary`. Unknown group → 404 `group_not_found`; `account` naming only accounts outside the scope → 404 `account_not_found`.",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "account",
            "in": "query",
            "description": "Only these accounts (comma-separated account ids). Ids outside the group / your access are ignored.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Only this account group: a group id, its name, or \"none\" for accounts in no group.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "description": "Only this kind of post.",
            "schema": {
              "type": "string",
              "enum": [
                "reel",
                "photo",
                "carousel",
                "story",
                "short",
                "long",
                "video"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The suggested posting times, per account and kind.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/publish-jobs/{jobId}": {
      "post": {
        "operationId": "postPublishJobsJobId",
        "tags": [
          "Posts"
        ],
        "summary": "Retry a failed publish",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Retries one failed publish job (a post to one account). A post still waiting for approval is refused (`409 approval_open`). A post created for a later time retries with `posts:schedule`; one created to publish at once (its `publishAt` under 5 minutes after it was created) needs `posts:publish`. When the last attempt reached the platform but no answer came back and there is nothing to check it against (a TikTok upload with no publish id), a plain retry is refused with `409 outcome_unknown` — the post may already be live; check, and only if it is not there send `{ confirmNotPublished: true }`. The key can only act on posts and drafts it created itself (`403 api_key_not_post_owner` / `api_key_not_draft_owner`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/publish-jobs/{jobId}/dismiss": {
      "delete": {
        "operationId": "deletePublishJobsJobIdDismiss",
        "tags": [
          "Posts"
        ],
        "summary": "Take back a dismissed failure",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Un-dismisses a publish failure, so it counts as unresolved again. A job that changed in between is `409 job_changed`, nothing written. The key can only act on posts and drafts it created itself (`403 api_key_not_post_owner` / `api_key_not_draft_owner`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true }` (or `alreadyActive: true`)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postPublishJobsJobIdDismiss",
        "tags": [
          "Posts"
        ],
        "summary": "Dismiss a publish failure",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Marks one FAILED publish job as acknowledged, so it stops counting as an unresolved failure. Bookkeeping only: the job keeps its error and stays listed; `DELETE` on the same path takes it back. A job that hasn’t failed is `409 not_dismissable`; a job retried or (un)dismissed in between is `409 job_changed` (with its current `status` / `dismissed`), nothing written. A key’s dismiss records no user; the audit carries the key. The key can only act on posts and drafts it created itself (`403 api_key_not_post_owner` / `api_key_not_draft_owner`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true }` (or `alreadyDismissed: true`)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/rate-cards": {
      "get": {
        "operationId": "getRateCards",
        "tags": [
          "Insights"
        ],
        "summary": "List rate cards",
        "description": "Scopes: any of `insights:read`, `dms:read`. The workspace’s rate cards (public page `/rates/{slug}` when `published`). Needs `insights:read` or `dms:read`. A key limited to some account groups sees only cards that follow one of its groups or show only its accounts (the media-kit rule). A key never receives `contactEmail`, and gets the prices (`content`: items, packages, add-ons, terms) only for a published card. Editing cards is for people in the app.",
        "security": [
          {
            "apiKey": [
              "insights:read",
              "dms:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read",
          "dms:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ rateCards: [{ id, title, slug, published, displayName, tagline, avatarUrl, acceptInquiries, showStats, platformAccountIds, channelScope, groupId, content? }] }` (`content` on published cards only, for a key).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/review-queue": {
      "get": {
        "operationId": "getReviewQueue",
        "tags": [
          "Comments"
        ],
        "summary": "List the review queue",
        "description": "Scope: `comments:read`. Held-for-review comments waiting on a decision, oldest first (the /review queue): `entryId`, why it was held (`source`, `reason`, `ruleId`, `wouldDo`), `expiresAt`, and the comment with its account and post (`mediaId`, `platformMediaId`, `permalink`).",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Opaque cursor from the previous page’s `nextCursor`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size (default 50, max 100).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "source",
            "in": "query",
            "description": "`restricted` = only comments from restricted people (already hidden; `keep` shows them). Any other value is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "enum": [
                "restricted"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ items, nextCursor, total }` (`total` on the first page only).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/review-queue/bulk-resolve": {
      "post": {
        "operationId": "postReviewQueueBulkResolve",
        "tags": [
          "Comments"
        ],
        "summary": "Resolve review items",
        "description": "Scope: `comments:read`. `keep`, `hide`, `block_user` need `comments:moderate`; `delete` needs `comments:delete`; `mark_safe` is people-only (`403 people_only`). Keys: at most 25 entries per call (`400 too_many_comments`), each counts toward the 200-per-hour moderation cap (`429 agent_moderation_limit`), YouTube writes reserve quota first (`429`/`503 youtube_quota_exhausted`); entries all already decided → `409 already_resolved` (`409 expired` when they aged out); an entry on a disconnected account → `404 not_found` for the whole batch (`GET review-queue` never lists those).",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "entries": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "minLength": 1
                        },
                        "action": {
                          "type": "string",
                          "enum": [
                            "keep",
                            "mark_safe",
                            "hide",
                            "delete",
                            "block_user"
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "action"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "maxItems": 200
                  },
                  "restrictAuthor": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "entries"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ results }`: per entry `{ id, ok, error?, downgraded? }`; a failed platform call leaves the entry pending.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/review-queue/expired": {
      "get": {
        "operationId": "getReviewQueueExpired",
        "tags": [
          "Comments"
        ],
        "summary": "List expired review items",
        "description": "Scope: `comments:read`. Held comments that aged out of the review queue, newest first (up to 200).",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ total, items }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postReviewQueueExpired",
        "tags": [
          "Comments"
        ],
        "summary": "Reopen expired review items",
        "description": "Scope: `comments:moderate`. Puts expired items back in the review queue. Keys need `comments:moderate` and pass `ids` (at most 25); `{ all: true }` is people-only (`403 people_only`).",
        "security": [
          {
            "apiKey": [
              "comments:moderate"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:moderate"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "ids": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1
                        },
                        "minItems": 1,
                        "maxItems": 500
                      }
                    },
                    "required": [
                      "ids"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "all": {
                        "type": "boolean",
                        "const": true
                      }
                    },
                    "required": [
                      "all"
                    ],
                    "additionalProperties": false
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok, reopened }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/rule-suggestions": {
      "get": {
        "operationId": "getRuleSuggestions",
        "tags": [
          "Comments"
        ],
        "summary": "List rule suggestions",
        "description": "Scope: `comments:read`. Moderation rules Hayyvn suggests from the workspace’s comments, strongest first (up to 100). Read-only for keys — people accept or dismiss them in the app. Not available to a key limited to some account groups.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "status",
            "in": "query",
            "description": "`pending` (default), `accepted`, `dismissed`, `superseded` or `all`.",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "accepted",
                "dismissed",
                "superseded",
                "all"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ suggestions: [{ id, proposedPattern, proposedAction, reason, matchedCount, confidence, status, createdAt, resolvedAt }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/rules": {
      "get": {
        "operationId": "getRules",
        "tags": [
          "Comments"
        ],
        "summary": "List moderation rules",
        "description": "Scope: `comments:read`. Live moderation rules (up to 500) with what they match, their action, platform, group scope (`groupId` null = every account) and starter pack. A key limited to some account groups sees every-account rules and its own groups’ rules, with hit stats from its accounts only. For a key, a regular expression longer than 60 characters comes back as `pattern: null` with `patternLength`. Rules are changed by people in the app — no key can edit them.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "stats",
            "in": "query",
            "description": "`1` = add `hitCount` and `lastFiredAt` per rule.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ rules: [{ id, platform, pattern, patternLength?, matchMode, threshold, action, severity, enabled, groupId, groupName, groupRemoved, createdAt, appliesTo, packId, packName, patternUnsafe, hitCount?, lastFiredAt? }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/rules/preview": {
      "post": {
        "operationId": "postRulesPreview",
        "tags": [
          "Comments"
        ],
        "summary": "Preview a moderation rule",
        "description": "Scope: `comments:read`. Dry-runs a rule against recent comments (up to 2,000) and returns matching samples. Nothing is saved — rules are created by people in the app. Not available to a key limited to some account groups. 60 previews per key per hour (`429 agent_preview_limit`); an unsafe regular expression is `400 invalid_pattern`.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pattern": {
                    "type": "string",
                    "maxLength": 200,
                    "default": ""
                  },
                  "matchMode": {
                    "type": "string",
                    "enum": [
                      "substring",
                      "word_boundary",
                      "obfuscated",
                      "regex",
                      "link_present",
                      "link_domain",
                      "username_pattern",
                      "all_caps",
                      "emoji_only"
                    ]
                  },
                  "sinceDays": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365,
                    "default": 30
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 200,
                    "default": 50
                  },
                  "groupId": {
                    "anyOf": [
                      {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 64
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "matchMode"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ totalScanned, matches: [{ externalId, text, fromUsername, platform, externalMediaId, externalTimestamp }], truncated, timedOut, groupInactive? }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/scheduled-posts": {
      "get": {
        "operationId": "getScheduledPosts",
        "tags": [
          "Posts"
        ],
        "summary": "List scheduled and published posts",
        "description": "Scope: `posts:read`. Posts with their per-account publish jobs, approval state (`approvalState`, `approvalHeld`, this round’s `approvals`), newest first. A YouTube job also carries `mediaId` (for `PATCH media/{mediaId}/visibility`) and `visibility` (`public`, `unlisted`, `private`, or null when not known yet), plus `youtube: { uploadStatus, failureReason }` — YouTube keeps processing a video after the upload, and can still reject it: `uploaded` (still processing), `processed`, `rejected` / `failed` (stopped by YouTube after upload — the job is then `failed` with a plain-words `error`, e.g. a copyright match; a retry re-uploads and may be refused again), `deleted` (the video is no longer on YouTube — the job is `failed` with “This video was removed from YouTube.” and already dismissed), `unknown` (Hayyvn stopped checking after ~2 days), or null (not checked). `failureReason` is YouTube’s token (`copyright`, `duplicate`, `codec`, …; `removed` when the video is gone); left out for client members.",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "before",
            "in": "query",
            "description": "Cursor: posts scheduled before this ISO time.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "beforeId",
            "in": "query",
            "description": "Cursor tie-breaker: the last post id of the previous page.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "description": "Account group: its id, its name (case-insensitive) or `none` (accounts in no group). Intersects with `accountId`. An empty group returns an empty list (never every account); an unknown or removed group is `404 group_not_found`; over 100 characters is `400 invalid_request`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "ids",
            "in": "query",
            "description": "Only these post ids (comma-separated).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "mine",
            "in": "query",
            "description": "`1` = only the ones this API key created.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Only posts in this status (`400 invalid_status` lists the allowed values).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ posts }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/scheduled-posts/{postId}": {
      "get": {
        "operationId": "getScheduledPostsPostId",
        "tags": [
          "Posts"
        ],
        "summary": "Get a post",
        "description": "Scope: `posts:read`. One post, with its content in the same shape `POST composes` accepts, its publish jobs and approval state.",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "postId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The post.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "operationId": "patchScheduledPostsPostId",
        "tags": [
          "Posts"
        ],
        "summary": "Edit a waiting post",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Same body and checks as `POST composes`, plus optional `publishAt` (A `publishAt` at least 5 minutes ahead needs `posts:schedule`; sooner (now) needs `posts:publish` — otherwise `403 api_key_missing_scope` naming the scope.). Content type and accounts can’t change (`400 targets_locked`); once publishing has started it’s `409 not_editable`. The key can only act on posts and drafts it created itself (`403 api_key_not_post_owner` / `api_key_not_draft_owner`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "postId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "contentKind": {
                    "type": "string",
                    "enum": [
                      "short_video",
                      "long_video",
                      "photo",
                      "story"
                    ]
                  },
                  "platformAccountIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "minItems": 1
                  },
                  "defaultCaption": {
                    "type": "string",
                    "maxLength": 4000,
                    "default": ""
                  },
                  "defaultMediaRefs": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 2000
                    },
                    "maxItems": 20,
                    "default": []
                  },
                  "overrides": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "caption": {
                          "type": "string",
                          "maxLength": 4000
                        },
                        "hashtags": {
                          "type": "string",
                          "maxLength": 1000
                        }
                      },
                      "additionalProperties": false
                    },
                    "propertyNames": {
                      "enum": [
                        "instagram",
                        "youtube",
                        "tiktok"
                      ]
                    }
                  },
                  "tiktokOptions": {
                    "type": "object",
                    "properties": {
                      "privacyLevel": {
                        "type": "string",
                        "enum": [
                          "PUBLIC_TO_EVERYONE",
                          "MUTUAL_FOLLOW_FRIENDS",
                          "FOLLOWER_OF_CREATOR",
                          "SELF_ONLY"
                        ]
                      },
                      "title": {
                        "type": "string",
                        "maxLength": 90
                      },
                      "disableComment": {
                        "type": "boolean"
                      },
                      "disableDuet": {
                        "type": "boolean"
                      },
                      "disableStitch": {
                        "type": "boolean"
                      },
                      "isBrandOrganic": {
                        "type": "boolean"
                      },
                      "isBrandedContent": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "privacyLevel"
                    ],
                    "additionalProperties": false
                  },
                  "youtubeOptions": {
                    "type": "object",
                    "properties": {
                      "captions": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "ref": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 2000
                            },
                            "language": {
                              "type": "string",
                              "maxLength": 40
                            },
                            "name": {
                              "type": "string",
                              "maxLength": 200
                            }
                          },
                          "required": [
                            "ref",
                            "language"
                          ],
                          "additionalProperties": false
                        },
                        "maxItems": 20
                      },
                      "privacyStatus": {
                        "type": "string",
                        "enum": [
                          "public",
                          "unlisted",
                          "private"
                        ]
                      },
                      "tags": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "maxLength": 500
                        },
                        "maxItems": 100
                      },
                      "title": {
                        "type": "string",
                        "maxLength": 1000
                      },
                      "madeForKids": {
                        "type": "boolean"
                      },
                      "firstComment": {
                        "type": "string",
                        "maxLength": 10000
                      },
                      "containsSyntheticMedia": {
                        "type": "boolean"
                      },
                      "categoryId": {
                        "type": "string",
                        "enum": [
                          "1",
                          "2",
                          "10",
                          "15",
                          "17",
                          "19",
                          "20",
                          "22",
                          "23",
                          "24",
                          "25",
                          "26",
                          "27",
                          "28",
                          "29"
                        ]
                      },
                      "defaultLanguage": {
                        "type": "string"
                      },
                      "defaultAudioLanguage": {
                        "type": "string"
                      },
                      "thumbnailRef": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 2000
                      },
                      "playlistIds": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "maxLength": 100
                        },
                        "maxItems": 20
                      }
                    },
                    "additionalProperties": false
                  },
                  "instagramOptions": {
                    "type": "object",
                    "properties": {
                      "collaborators": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "maxLength": 60
                        },
                        "maxItems": 10
                      }
                    },
                    "additionalProperties": false
                  },
                  "publishAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "contentKind",
                  "platformAccountIds"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated post.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/scheduled-posts/{postId}/cancel": {
      "post": {
        "operationId": "postScheduledPostsPostIdCancel",
        "tags": [
          "Posts"
        ],
        "summary": "Cancel a post",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Cancels a post that hasn’t published yet. Posts already live stay up (deleting live posts is for people in the app). The key can only act on posts and drafts it created itself (`403 api_key_not_post_owner` / `api_key_not_draft_owner`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "postId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true, … }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/scheduled-posts/{postId}/reschedule": {
      "post": {
        "operationId": "postScheduledPostsPostIdReschedule",
        "tags": [
          "Posts"
        ],
        "summary": "Reschedule a post",
        "description": "Scope: `posts:schedule` (higher post scopes work too: `posts:publish`). Moves a waiting post to a new time. A `publishAt` at least 5 minutes ahead needs `posts:schedule`; sooner (now) needs `posts:publish` — otherwise `403 api_key_missing_scope` naming the scope. The key can only act on posts and drafts it created itself (`403 api_key_not_post_owner` / `api_key_not_draft_owner`).",
        "security": [
          {
            "apiKey": [
              "posts:schedule"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:schedule"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "postId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "publishAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "publishAt"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ ok: true, publishAt }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/standing": {
      "get": {
        "operationId": "getStanding",
        "tags": [
          "Comments"
        ],
        "summary": "List restricted people",
        "description": "Scope: `comments:read`. People who are restricted, newest first (up to 500), workspace-wide per platform: their new comments are hidden the moment they arrive and wait in Review until a person approves them (approving shows the comment). Per person: `strikes` = comments kept hidden while restricted, `approvals` = approvals in a row, `liftAt` = when the restriction lifts by itself (enough approvals in a row lift it sooner). Not available to a key limited to some account groups (`403 access_limited`). A key never receives the platform user id or the note a person left; `targetUsername` is the handle without `@`, or null when only the user id is known.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "handle",
            "in": "query",
            "description": "Only this person, by handle (with or without `@`, case-insensitive; needs `platform`).",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "platform",
            "in": "query",
            "description": "Only this platform (`instagram`, `youtube`, `tiktok`, `facebook`). Required with `targetUserId` or `handle`.",
            "schema": {
              "type": "string",
              "enum": [
                "instagram",
                "youtube",
                "tiktok",
                "facebook"
              ]
            }
          },
          {
            "name": "removed",
            "in": "query",
            "description": "`1` = the Removed list (lifted or unrestricted people — people only; a key always gets the live list).",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          },
          {
            "name": "targetUserId",
            "in": "query",
            "description": "Only this person, by the platform’s own user id (needs `platform`).",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ entries: [{ id, platform, targetUsername, targetDisplayName, restrictedAt, restrictedBy, restrictedByLabel, strikes, approvals, liftAt, removedAt, liftedReason, liftedReasonLabel }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "postStanding",
        "tags": [
          "Comments"
        ],
        "summary": "Restrict a person",
        "description": "Scope: `comments:moderate`. Needs `comments:moderate`. Restricts someone on one platform, on every account of it: from now on their new comments are hidden on arrival and wait in Review for a person’s approval. Give `targetUserId` or `handle` (someone who has commented on the workspace’s accounts with it — `404 person_not_found` when no one has, `409 ambiguous_handle` when two people have). Each call takes one slot of the key’s 200-per-hour moderation cap (`429 agent_moderation_limit`, nothing done), and the workspace allows 120 restrictions per hour (`429 rate_limited`). Not available to a key limited to some account groups (`403 access_limited`). `409 trusted` for someone on the Trusted people list, `409 blocked` for someone already ghost-blocked, `409 own_account` for one of the workspace’s own accounts. A `note` from a key is not stored. Already restricted → `200 { alreadyRestricted: true }`, nothing changes.",
        "security": [
          {
            "apiKey": [
              "comments:moderate"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:moderate"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "platform": {
                    "type": "string",
                    "enum": [
                      "instagram",
                      "youtube",
                      "tiktok",
                      "facebook"
                    ]
                  },
                  "targetUserId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "handle": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "targetUsername": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "targetDisplayName": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 500
                  }
                },
                "required": [
                  "platform"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ entry: { id, platform, targetUsername, targetDisplayName, restrictedAt, restrictedBy, strikes, approvals, liftAt } }` (200 with `alreadyRestricted: true` when they already were)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/standing/{standingId}": {
      "delete": {
        "operationId": "deleteStandingStandingId",
        "tags": [
          "Comments"
        ],
        "summary": "Unrestrict a person",
        "description": "Scope: `comments:moderate`. Needs `comments:moderate`. Lifts a restriction (`id` from `GET standing`): their new comments show normally again; comments already hidden stay as they are. Idempotent. Not available to a key limited to some account groups (`403 access_limited`); `404 not_found` for an unknown id; the workspace allows 120 restrict/unrestrict changes per hour (`429 rate_limited`). People can restore it from the Removed list in the app.",
        "security": [
          {
            "apiKey": [
              "comments:moderate"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:moderate"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "standingId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ ok: true }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/superfans": {
      "get": {
        "operationId": "getSuperfans",
        "tags": [
          "Insights"
        ],
        "summary": "Top fans",
        "description": "Scope: `insights:read`. The highest-ranked fans across platforms (`top`), or a handle search (`q`, 8 matches). Platforms with no connected account are left out. Fans are per platform, not per account, so a key limited to some account groups is refused (`403 access_limited`).",
        "security": [
          {
            "apiKey": [
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "q",
            "in": "query",
            "description": "Handle search instead of `top`: up to 8 matches.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "top",
            "in": "query",
            "description": "Return the N (1–50) highest-ranked fans: `{ fans: [{ rank, platform, username, tier, score, commentCount, mentionCount, lastActiveAt }] }`.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ fans }` with `top`; `{ matches }` with `q`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/tasks": {
      "get": {
        "operationId": "getTasks",
        "tags": [
          "Insights"
        ],
        "summary": "Tasks: what needs the creator, ranked",
        "description": "Scopes: any of `comments:read`, `dms:read`, `posts:read`, `insights:read`. One ranked to-do list over the queues that already exist — brand opportunities, reply drafts, mentions, review holds grouped per account, pending auto-posts, publish failures, block suggestions, reconnects, items expiring within 24h — plus `handled`: what automation did alone in the window. Each task carries `actions[]` pointing at the existing routes. Kinds the key may not read are left out (comment kinds need `comments:read`, DM/opportunity kinds `dms:read`, publish kinds `posts:read`). Trust-ramp cards are for signed-in owners/admins only.",
        "security": [
          {
            "apiKey": [
              "comments:read",
              "dms:read",
              "posts:read",
              "insights:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read",
          "dms:read",
          "posts:read",
          "insights:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "group",
            "in": "query",
            "description": "Only this account group: a group id, its name, or \"none\" for accounts in no group.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "hours",
            "in": "query",
            "description": "Window for `handled` and expiry, in hours (1–168, default 24).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 168
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The ranked tasks.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/tiktok/creator-info": {
      "get": {
        "operationId": "getTiktokCreatorInfo",
        "tags": [
          "Accounts"
        ],
        "summary": "TikTok posting options",
        "description": "Scope: `posts:read`. A TikTok account’s live posting options from TikTok (its posting rules require them before posting): allowed privacy levels, max video length, whether comments / duet / stitch are off, and the account’s nickname and username. Live call: 10 per minute per key (`429 rate_limited`). TikTok failures are typed, each with `reason`, `retryable`, `tiktokCode` and `tiktokRequestId`: `409 tiktok_reconnect_required`, `403 tiktok_permission_denied`, `429 tiktok_rate_limited`, `422 tiktok_request_rejected`, `503 tiktok_unavailable` or `503 tiktok_unexpected_response`.",
        "security": [
          {
            "apiKey": [
              "posts:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "posts:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "The TikTok account (an `id` from `GET connections`). Default: any active TikTok account the key sees.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ info: { privacyLevelOptions, commentDisabled, duetDisabled, stitchDisabled, maxVideoPostDurationSec, creatorUsername, creatorNickname, creatorAvatarUrl, profileLookup } }` (`profileLookup: \"failed\"` → the three creator names are null; the options are still live)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/workspaces/{workspaceId}/trusted": {
      "get": {
        "operationId": "getTrusted",
        "tags": [
          "Comments"
        ],
        "summary": "List trusted people",
        "description": "Scope: `comments:read`. People Hayyvn never moderates, newest first (up to 500), workspace-wide. Not available to a key limited to some account groups (`403 access_limited`). A key never receives the platform user id or the `note` a person left; `targetUsername` is the handle without `@`, or null when only the user id is known. Trusting and removing people is for people in the app.",
        "security": [
          {
            "apiKey": [
              "comments:read"
            ]
          }
        ],
        "x-havyyn-scopes": [
          "comments:read"
        ],
        "parameters": [
          {
            "name": "workspaceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The workspace the key belongs to (see `GET /api/api-keys/self`)."
          },
          {
            "name": "removed",
            "in": "query",
            "description": "`1` = the Removed list (people only — a key always gets the live list).",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ entries: [{ id, platform, targetUsername, targetDisplayName, note, addedAt, removedAt }] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "hvn_ + 43 characters",
        "description": "A workspace API key from Settings → Developers → API keys & AI agents."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Broad class, e.g. `forbidden`, `unauthenticated`, `invalid_request`. When Instagram, YouTube or TikTok refused the call: `needs_reconnect` (the account’s connection has expired — a person reconnects it in Settings → Connections), `not_found` (gone on the platform), `rate_limited` / `quota_exhausted` (back off), `platform_error` (a read) or `provider_error` (a write) for anything else. The platform’s own error text is never returned."
          },
          "reason": {
            "type": "string",
            "description": "Machine-readable cause, e.g. `api_key_missing_scope`, `rate_limited`."
          },
          "message": {
            "type": "string",
            "description": "A sentence a person can read."
          },
          "platform": {
            "type": "string",
            "description": "On a platform failure: which platform (`instagram`, `youtube`, `tiktok`)."
          },
          "accountName": {
            "type": "string",
            "description": "On `needs_reconnect` from a read: the connected account’s name (Instagram: its username, without the @)."
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Refused. See `reason`.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
