{
  "openapi": "3.1.0",
  "info": {
    "title": "Influmesh API",
    "version": "1.0.0",
    "description": "Turn a product link into matched creators and native content briefs rebuilt from ads already winning in that market. Jobs take 1-3 minutes: create a job, then poll it; each poll moves the job one step. MCP server: https://influmesh.com/mcp. Guide: https://influmesh.com/agents"
  },
  "servers": [{ "url": "https://influmesh.com" }],
  "components": {
    "securitySchemes": { "bearer": { "type": "http", "scheme": "bearer", "description": "Influmesh API key (im_…). Create a free one with POST /api/keys." } },
    "schemas": {
      "BriefRequest": {
        "type": "object",
        "properties": {
          "product_url": { "type": "string", "description": "Product page link (preferred)." },
          "product_description": { "type": "string", "description": "One-line description if there is no link, or extra notes." },
          "output": { "type": "string", "enum": ["creator-brief", "brand-content", "paid-ad"], "default": "creator-brief" },
          "count": { "type": "integer", "minimum": 1, "maximum": 6, "default": 3 },
          "creator_size": { "type": "string", "enum": ["balanced", "head", "budget"], "default": "balanced" },
          "markets": { "type": "array", "items": { "type": "string" }, "description": "ISO country codes. Default [\"US\"]." }
        }
      },
      "Job": {
        "type": "object",
        "description": "While running: {status:'processing', stage, step}. When finished: the full result with packs (one per brief), audience, page (whether the product page was read), category, lockedCount and jobId. On failure: {status:'failed', error}.",
        "properties": {
          "status": { "type": "string", "enum": ["processing", "failed"] },
          "stage": { "type": "string" },
          "step": { "type": "string" },
          "packs": { "type": "array", "items": { "type": "object" } },
          "lockedCount": { "type": "integer" },
          "jobId": { "type": "string" }
        }
      },
      "Error": { "type": "object", "properties": { "error": { "type": "string" }, "code": { "type": "string" } } }
    }
  },
  "paths": {
    "/api/keys": {
      "post": {
        "operationId": "createFreeKey",
        "summary": "Create a free API key (shown once)",
        "requestBody": { "required": false, "content": { "application/json": { "schema": { "type": "object", "properties": { "label": { "type": "string" } } } } } },
        "responses": { "201": { "description": "Key created", "content": { "application/json": { "schema": { "type": "object", "properties": { "key": { "type": "string" }, "prefix": { "type": "string" }, "tier": { "type": "string" } } } } } }, "429": { "description": "Too many keys from this network today" } }
      }
    },
    "/api/v1/briefs": {
      "post": {
        "operationId": "createBriefs",
        "summary": "Start a job for one product",
        "security": [{ "bearer": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BriefRequest" } } } },
        "responses": {
          "202": { "description": "Job started", "content": { "application/json": { "schema": { "type": "object", "properties": { "job_id": { "type": "string" }, "status": { "type": "string" }, "poll": { "type": "string" } } } } } },
          "400": { "description": "Missing product", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "description": "Missing or invalid key" },
          "429": { "description": "Daily limit reached", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/v1/briefs/{job_id}": {
      "get": {
        "operationId": "getBriefs",
        "summary": "Poll a job (each call moves it one step; call every few seconds until it is no longer processing)",
        "security": [{ "bearer": [] }],
        "parameters": [{ "name": "job_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Job state or full result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Job" } } } }, "404": { "description": "No such job" } }
      }
    },
    "/api/v1/results": {
      "post": {
        "operationId": "reportResult",
        "summary": "Paid plans: report how a brief performed",
        "security": [{ "bearer": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["angle_id", "result"], "properties": { "angle_id": { "type": "string" }, "creator_handle": { "type": "string" }, "result": { "type": "string", "enum": ["won", "mixed", "flopped"] } } } } } },
        "responses": { "200": { "description": "Recorded" }, "403": { "description": "Paid plans only" } }
      }
    },
    "/api/v1/account": {
      "get": {
        "operationId": "getAccount",
        "summary": "Plan, runs used today and limits",
        "security": [{ "bearer": [] }],
        "responses": { "200": { "description": "Account status" } }
      }
    }
  }
}
