{
  "openapi": "3.1.0",
  "info": {
    "title": "Brand App account connector",
    "version": "1.2.0",
    "description": "AI Brand Manager MCP & REST API for one authenticated Brand App user: identity profiles (including ceiling_buyer, unique_mechanism, preferred_mechanism), Zernio connections, isolated 14-day CRM pixel health, 40-piece Educator Retargeting Bin, named brand refs, saved prompts, ad images, short video ads, and scheduling/publishing. Do not send user_id. schedule, publish, and create_video_ad require confirm true. API keys need the matching scope."
  },
  "servers": [
    {
      "url": "https://zvltrbklmbggrsgxaeae.supabase.co/functions/v1/brand-account-connector"
    }
  ],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Supabase user access token, aibrand_ MCP key, or platform API key."
      }
    }
  },
  "paths": {
    "/v1/profiles": {
      "get": {
        "operationId": "listIdentityProfiles",
        "summary": "List identity profiles for the authenticated user",
        "responses": { "200": { "description": "Profiles" } }
      },
      "post": {
        "operationId": "createIdentityProfile",
        "summary": "Create an identity profile on this account and set it active",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["business_name"],
                "properties": {
                  "business_name": { "type": "string" },
                  "brief": { "type": "string" },
                  "industry": { "type": "string" },
                  "brand_colors": { "type": "array", "items": { "type": "string" } },
                  "speakers": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": ["name"],
                      "properties": {
                        "name": { "type": "string" },
                        "role": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Created profile" } }
      }
    },
    "/v1/capabilities": {
      "get": {
        "operationId": "listConnectorCapabilities",
        "summary": "Live, partial, and planned studios on this connector",
        "responses": { "200": { "description": "Toolkit map. Planned areas are not callable." } }
      }
    },
    "/v1/profiles/{profile_id}/references": {
      "get": {
        "operationId": "listBrandReferences",
        "summary": "List brand references (logos, cast, product photos) on this profile",
        "parameters": [
          { "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "active_only", "in": "query", "required": false, "schema": { "type": "boolean" } },
          { "name": "tags", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Brand references" } }
      }
    },
    "/v1/profiles/{profile_id}/cast": {
      "get": {
        "operationId": "listCast",
        "summary": "List named people on this profile",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Cast references" } }
      },
      "post": {
        "operationId": "saveCastReference",
        "summary": "Save a named person, logo, or product on this profile",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name"],
                "properties": {
                  "name": { "type": "string" },
                  "kind": { "type": "string", "enum": ["person", "logo", "product"] },
                  "content_base64": { "type": "string" },
                  "file_url": { "type": "string" },
                  "content_type": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Saved reference" } }
      }
    },
    "/v1/profiles/{profile_id}/resolve-references": {
      "post": {
        "operationId": "resolveBrandReferences",
        "summary": "Resolve named people, logos, and brand colors",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["names"],
                "properties": { "names": { "type": "array", "items": { "type": "string" } } }
              }
            }
          }
        },
        "responses": { "200": { "description": "Matches, logos, colors, missing names" } }
      }
    },
    "/v1/profiles/{profile_id}/image-prompts": {
      "post": {
        "operationId": "createImagePrompts",
        "summary": "Create and save promotional image prompts using this profile's brand references. Charges 0.05 credits.",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "brief": { "type": "string" },
                  "count": { "type": "integer", "minimum": 1, "maximum": 10 },
                  "platform": { "type": "string" },
                  "language": { "type": "string", "enum": ["en", "es", "pt", "de", "fr"] },
                  "replace_existing": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Saved image prompts" }, "402": { "description": "Insufficient credits" } }
      }
    },
    "/v1/profiles/{profile_id}/marketing-prompts": {
      "get": {
        "operationId": "listMarketingPrompts",
        "summary": "List saved image and marketing prompts on this profile",
        "parameters": [
          { "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "category", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "integer", "minimum": 1, "maximum": 50 } }
        ],
        "responses": { "200": { "description": "Saved prompts" } }
      },
      "post": {
        "operationId": "createMarketingPrompts",
        "summary": "Create and save a full marketing prompt pack using this profile's brand references. Charges 0.05 credits.",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "brief": { "type": "string" },
                  "count": { "type": "integer", "minimum": 1, "maximum": 12 },
                  "platform": { "type": "string" },
                  "language": { "type": "string", "enum": ["en", "es", "pt", "de", "fr"] },
                  "replace_existing": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Saved marketing prompts" }, "402": { "description": "Insufficient credits" } }
      }
    },
    "/v1/profiles/{profile_id}/generate-ad": {
      "post": {
        "operationId": "generateAd",
        "summary": "Generate 1-4 previews from prompt_id or prompt. Charges 1 credit at 1K/2K or 2 credits at 4K. Does not schedule.",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt_id": { "type": "string" },
                  "prompt": { "type": "string" },
                  "style_preset": { "type": "string", "enum": ["photo", "marketing_graphic"] },
                  "text_policy": { "type": "string", "enum": ["photo", "ad"] },
                  "headline": { "type": "string" },
                  "subtext": { "type": "string" },
                  "cta": { "type": "string" },
                  "reference_ids": { "type": "array", "items": { "type": "string" } },
                  "reference_names": { "type": "array", "items": { "type": "string" } },
                  "variants": { "type": "integer", "minimum": 1, "maximum": 4 },
                  "resolution": { "type": "string", "enum": ["1K", "2K", "4K"] },
                  "aspect_ratio": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Preview variants" }, "402": { "description": "Insufficient credits" } }
      }
    },
    "/v1/profiles/{profile_id}/generate-image-prompt-ad": {
      "post": {
        "operationId": "generateImagePromptAd",
        "summary": "Generate 1-4 previews from prompt_id or brief. Charges 1 credit at 1K/2K or 2 credits at 4K. Does not schedule.",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt_id": { "type": "string" },
                  "brief": { "type": "string" },
                  "style_preset": { "type": "string", "enum": ["photo", "marketing_graphic"] },
                  "text_policy": { "type": "string", "enum": ["photo", "ad"] },
                  "headline": { "type": "string" },
                  "subtext": { "type": "string" },
                  "cta": { "type": "string" },
                  "reference_ids": { "type": "array", "items": { "type": "string" } },
                  "reference_names": { "type": "array", "items": { "type": "string" } },
                  "variants": { "type": "integer", "minimum": 1, "maximum": 4 },
                  "resolution": { "type": "string", "enum": ["1K", "2K", "4K"] },
                  "aspect_ratio": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Preview variants" }, "402": { "description": "Insufficient credits" } }
      }
    },
    "/v1/profiles/{profile_id}/drafts": {
      "post": {
        "operationId": "createPostDraft",
        "summary": "Create a captioned draft from a preview asset_id",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["asset_id", "caption"],
                "properties": {
                  "asset_id": { "type": "string" },
                  "caption": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Draft" } }
      }
    },
    "/v1/drafts/{draft_id}/schedule": {
      "post": {
        "operationId": "schedulePost",
        "summary": "Schedule a draft to social accounts on its profile",
        "parameters": [{ "name": "draft_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["scheduled_for", "confirm"],
                "properties": {
                  "scheduled_for": { "type": "string", "format": "date-time" },
                  "account_ids": { "type": "array", "items": { "type": "string" } },
                  "confirm": { "type": "boolean", "description": "Must be true or the draft is left unchanged." }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Scheduled" } }
      }
    },
    "/v1/drafts/{draft_id}/publish": {
      "post": {
        "operationId": "publishPost",
        "summary": "Publish a draft now. Requires confirm true.",
        "parameters": [{ "name": "draft_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["confirm"],
                "properties": {
                  "account_ids": { "type": "array", "items": { "type": "string" } },
                  "confirm": { "type": "boolean", "description": "Must be true or nothing is published." }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Published" } }
      }
    },
    "/v1/profiles/{profile_id}/zernio": {
      "get": {
        "operationId": "getZernioConnections",
        "summary": "Get Zernio workspace, channels, and ad account links for this profile or all profiles",
        "parameters": [
          { "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "all_profiles", "in": "query", "required": false, "schema": { "type": "boolean" } }
        ],
        "responses": { "200": { "description": "Zernio connection status" } }
      }
    },
    "/v1/profiles/{profile_id}/zernio/sync": {
      "post": {
        "operationId": "syncZernioConnections",
        "summary": "Ensure Zernio workspace and sync connected channels and ad accounts",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Synced Zernio link" } }
      }
    },
    "/v1/profiles/{profile_id}/zernio/connect-link": {
      "post": {
        "operationId": "getZernioConnectLink",
        "summary": "Generate an OAuth link to connect a social or ad platform via Zernio",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["platform"],
                "properties": {
                  "platform": { "type": "string" },
                  "redirect_url": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Zernio OAuth connect URL" } }
      }
    },
    "/v1/profiles/{profile_id}/crm-pixel-health": {
      "get": {
        "operationId": "getCrmPixelHealth",
        "summary": "Read strictly profile-isolated 14-day CRM qualification ratio (70/30 rule), objections, and ads plan signals",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "CRM pixel health and objections" } }
      }
    },
    "/v1/profiles/{profile_id}/educator-bin": {
      "post": {
        "operationId": "generateEducatorRetargetingPack",
        "summary": "Generate a 40-piece Educator Retargeting Bin plus Confirmation Page and 3 emails",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "limit": { "type": "integer", "minimum": 1, "maximum": 40 }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Educator retargeting bin and companion kit" } }
      }
    },
    "/v1/profiles/{profile_id}/video-ads": {
      "post": {
        "operationId": "createVideoAd",
        "summary": "Render a short video ad. Requires confirm true.",
        "parameters": [{ "name": "profile_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["prompt", "confirm"],
                "properties": {
                  "prompt": { "type": "string" },
                  "aspect_ratio": { "type": "string", "enum": ["9:16", "16:9", "1:1"] },
                  "duration": { "type": "integer", "minimum": 3, "maximum": 15 },
                  "model": { "type": "string" },
                  "resolution": { "type": "string", "enum": ["720p", "1080p"] },
                  "reference_ids": { "type": "array", "items": { "type": "string" } },
                  "reference_names": { "type": "array", "items": { "type": "string" } },
                  "confirm": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Queued video job" }, "402": { "description": "Insufficient credits" } }
      }
    },
    "/v1/video-ads/{job_id}": {
      "get": {
        "operationId": "getVideoStatus",
        "summary": "Poll status and finished video URL for a queued video ad job",
        "parameters": [{ "name": "job_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Video job status" } }
      }
    }
  }
}
