{
  "openapi": "3.1.0",
  "info": {
    "title": "Ad-Anything API",
    "version": "1.0.0",
    "summary": "Polymorphic 5-domain deterministic ad creative compiler, vector SVG renderer, and policy pre-flight API with $0 billing on 422/SSRF/errors.",
    "description": "Deterministic ad creative compilation engine covering public landing page hook dissection (SSRF-safe with 7d-30d verified-hit archive caching), 30+ platform-compliant ad scripts (Meta, TikTok, Google RSA <= 30/90 chars, LinkedIn), semantic HTML/JSON landing page hero A/B variants, strict-XML vector SVG ad cards (1080x1080, 1080x1920, 1200x628), and policy pre-flight violation scanning with RFC 4180 Google Ads RSA and Meta Ads bulk CSV export. Invalid inputs, private/metadata SSRF rejections (HTTP 422), and fake-200 error pages strictly bill $0 (billed_micros = 0). Hard $2.00 (2,000,000 micro-USD) external spend cap. Strict zero customer ad copy or analytics resale commitment.",
    "contact": {
      "name": "Ad-Anything Operations",
      "email": "prep@far31prescan.com",
      "url": "https://ad.fastmesh.dev"
    }
  },
  "servers": [
    {
      "url": "https://ad.fastmesh.dev",
      "description": "Public HTTPS Gateway Mount"
    },
    {
      "url": "http://127.0.0.1:9007",
      "description": "Local Runtime Server"
    }
  ],
  "tags": [
    { "name": "Health", "description": "Liveness, 5-domain readiness, and ledger health probes" },
    { "name": "Compile", "description": "Full 5-domain compilation, dissection, vector SVG rendering, policy preflight, and batch SKUs" },
    { "name": "MCP", "description": "Native flat JSON-RPC 2.0 Model Context Protocol endpoint" },
    { "name": "Billing", "description": "Creem fixed non-expiring prepaid credit packs ($19/$59/$149), balances, and HMAC-SHA256 webhook settlement" },
    { "name": "Discovery", "description": "5-second Try-Now storefront, OpenAPI 3.1, llms.txt, skill.md, sitemap.xml, and SEO/GEO landing pages" }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "getTryNowStorefront",
        "tags": ["Discovery"],
        "summary": "Serve the 5-second zero-signup Try-Now web storefront",
        "responses": {
          "200": {
            "description": "Interactive HTML Try-Now storefront",
            "content": {
              "text/html": {
                "schema": { "type": "string" }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getHealth",
        "tags": ["Health"],
        "summary": "Check Ad-Anything service liveness and subsystem readiness",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HealthResponse" }
              }
            }
          }
        }
      }
    },
    "/v1/compile": {
      "post": {
        "operationId": "compileCampaignBundle",
        "tags": ["Compile"],
        "summary": "Run full 5-domain ad compilation from a public URL, raw HTML, or product parameters",
        "description": "Executes landing page hook dissection, 30+ char-clamped multi-platform scripts, 3 HTML/JSON hero A/B variants, deterministic XML-valid SVG ad cards (1080x1080, 1080x1920, 1200x628), policy pre-flight violation rewrite, and Google/Meta CSV export. Empty, invalid, or SSRF-blocked requests return HTTP 422 with billed_micros = 0.",
        "parameters": [
          { "name": "X-Tenant-Id", "in": "header", "required": false, "schema": { "type": "string" } },
          { "name": "X-API-Key", "in": "header", "required": false, "schema": { "type": "string" } },
          { "name": "X-Try-Now", "in": "header", "required": false, "schema": { "type": "string" } },
          { "name": "X-Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CompileRequest" },
              "examples": {
                "by_parameters": {
                  "summary": "Compile from structured product parameters",
                  "value": {
                    "product_name": "LedgerPulse",
                    "competitor_name": "Manual Spreadsheets",
                    "uvp": "Automated invoice variance checks in 10 seconds with zero monthly seat fees",
                    "price_anchor": "$19 prepaid",
                    "social_proof": "Trusted by 420+ finance teams",
                    "guarantee": "Non-expiring credits and $0 charge on 422 errors",
                    "pain_points": ["missed billing errors", "slow month-end close", "expiring software seats"],
                    "theme": "obsidian_volt"
                  }
                },
                "by_url": {
                  "summary": "Compile by dissecting a public landing page URL",
                  "value": {
                    "url": "https://example.com",
                    "theme": "clean_saas"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SHA-256 attested 5-domain AdCompileBundle",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CompileResponse" }
              }
            }
          },
          "422": {
            "description": "Empty, invalid, fake-200, or SSRF-blocked request ($0 billed, billed_micros = 0)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/v1/dissect": {
      "post": {
        "operationId": "dissectLandingPage",
        "tags": ["Compile"],
        "summary": "Dissect a public landing page URL or HTML snapshot into UVP, social proof, price anchor, guarantee, and attackable wedges",
        "parameters": [
          { "name": "X-Tenant-Id", "in": "header", "required": false, "schema": { "type": "string" } },
          { "name": "X-Try-Now", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/DissectRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Structured landing page dissection",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericOperationResponse" }
              }
            }
          },
          "422": {
            "description": "Invalid, empty, fake-200, or SSRF-blocked URL ($0 billed)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/v1/svg": {
      "post": {
        "operationId": "renderSvgPack",
        "tags": ["Compile"],
        "summary": "Compile deterministic strict-XML vector SVG ad creatives (1080x1080, 1080x1920, 1200x628)",
        "parameters": [
          { "name": "X-Tenant-Id", "in": "header", "required": false, "schema": { "type": "string" } },
          { "name": "X-Try-Now", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SvgRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Strictly XML-valid vector SVG pack",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericOperationResponse" }
              }
            }
          },
          "422": {
            "description": "Invalid parameters or unsupported dimensions ($0 billed)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/v1/preflight": {
      "post": {
        "operationId": "policyPreflightAndCsv",
        "tags": ["Compile"],
        "summary": "Scan ad copy for policy violations, emit compliant rewrites, and export Google RSA / Meta Ads CSVs",
        "parameters": [
          { "name": "X-Tenant-Id", "in": "header", "required": false, "schema": { "type": "string" } },
          { "name": "X-Try-Now", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PreflightRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Policy pre-flight findings, safe rewrites, and RFC 4180 CSV exports",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericOperationResponse" }
              }
            }
          },
          "422": {
            "description": "Empty or malformed copy input ($0 billed)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/v1/batch": {
      "post": {
        "operationId": "compileBatch",
        "tags": ["Compile"],
        "summary": "Concurrent multi-SKU creative batch compilation bounded by max_budget_micros and $2.00 cap",
        "parameters": [
          { "name": "X-Tenant-Id", "in": "header", "required": false, "schema": { "type": "string" } },
          { "name": "X-API-Key", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BatchRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch summary and per-item creative bundles",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BatchResponse" }
              }
            }
          },
          "422": {
            "description": "Invalid batch request ($0 billed)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/billing/packs": {
      "get": {
        "operationId": "listBillingPacks",
        "tags": ["Billing"],
        "summary": "List non-expiring Creem prepaid credit packs ($19/$59/$149) and per-operation micro-USD tolls",
        "responses": {
          "200": {
            "description": "Credit packs and toll schedule",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/api/billing/balance": {
      "get": {
        "operationId": "getBillingBalance",
        "tags": ["Billing"],
        "summary": "Query tenant prepaid credit balance and $2.00 external spend cap telemetry",
        "parameters": [
          { "name": "tenant_id", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "X-Tenant-Id", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Tenant wallet balance and external spend status",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/mcp": {
      "get": {
        "operationId": "mcpMetadata",
        "tags": ["MCP"],
        "summary": "Return Model Context Protocol server manifest and tool list",
        "responses": {
          "200": {
            "description": "MCP capability descriptor",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "mcpJsonRpc",
        "tags": ["MCP"],
        "summary": "Invoke native JSON-RPC 2.0 MCP tools (ad_dissect_and_compile, ad_render_svg_pack, ad_policy_preflight, ad_export_csv)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/McpRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 response payload",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "getOpenApiSpec",
        "tags": ["Discovery"],
        "summary": "Serve OpenAPI 3.1.0 JSON specification",
        "responses": {
          "200": {
            "description": "OpenAPI 3.1.0 document",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/llms.txt": {
      "get": {
        "operationId": "getLlmsTxt",
        "tags": ["Discovery"],
        "summary": "Serve AI-crawler capability index (llms.txt)",
        "responses": {
          "200": {
            "description": "Plain-text llms.txt discovery index",
            "content": {
              "text/plain": {
                "schema": { "type": "string" }
              }
            }
          }
        }
      }
    },
    "/skill.md": {
      "get": {
        "operationId": "getSkillMd",
        "tags": ["Discovery"],
        "summary": "Serve agent-executable skill handbook (skill.md)",
        "responses": {
          "200": {
            "description": "Markdown skill handbook",
            "content": {
              "text/markdown": {
                "schema": { "type": "string" }
              }
            }
          }
        }
      }
    },
    "/sitemap.xml": {
      "get": {
        "operationId": "getSitemapXml",
        "tags": ["Discovery"],
        "summary": "Serve XML sitemap for ad.fastmesh.dev and SEO/GEO landing pages",
        "responses": {
          "200": {
            "description": "XML sitemap",
            "content": {
              "application/xml": {
                "schema": { "type": "string" }
              }
            }
          }
        }
      }
    },
    "/seo/{slug}": {
      "get": {
        "operationId": "getSeoLandingPage",
        "tags": ["Discovery"],
        "summary": "Serve a long-tail English SEO/GEO landing page",
        "parameters": [
          { "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Static SEO/GEO landing page HTML",
            "content": {
              "text/html": {
                "schema": { "type": "string" }
              }
            }
          },
          "404": {
            "description": "SEO page not found"
          }
        }
      }
    },
    "/webhooks/creem": {
      "post": {
        "operationId": "handleCreemWebhook",
        "tags": ["Billing"],
        "summary": "Idempotent Creem payment webhook ingress verified via HMAC-SHA256",
        "description": "Verifies creem-signature or X-Creem-Signature using CREEM_WEBHOOK_SECRET, deduplicates event_id in SQLite WAL BEGIN IMMEDIATE, redacts payer email to sha256[:12], and credits the tenant wallet.",
        "parameters": [
          { "name": "creem-signature", "in": "header", "required": false, "schema": { "type": "string" } },
          { "name": "X-Creem-Signature", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "type": "object" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook settled or deduplicated idempotently",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/WebhookResult" }
              }
            }
          },
          "400": { "description": "Malformed payload or missing event_id" },
          "401": { "description": "Invalid creem-signature HMAC-SHA256 digest" },
          "503": { "description": "CREEM_WEBHOOK_SECRET not configured" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "service": { "type": "string" },
          "version": { "type": "string" },
          "port": { "type": "integer" },
          "domains": { "type": "array", "items": { "type": "string" } },
          "zero_data_resale": { "type": "boolean" },
          "ledger": { "type": "object" }
        }
      },
      "CompileRequest": {
        "type": "object",
        "properties": {
          "url": { "type": "string" },
          "html": { "type": "string" },
          "product_name": { "type": "string" },
          "competitor_name": { "type": "string" },
          "uvp": { "type": "string" },
          "price_anchor": { "type": "string" },
          "social_proof": { "type": "string" },
          "guarantee": { "type": "string" },
          "pain_points": { "type": "array", "items": { "type": "string" } },
          "cta": { "type": "string" },
          "theme": { "type": "string" },
          "brand_colors": { "type": "object" },
          "sizes": { "type": "array", "items": { "type": "string" } },
          "templates": { "type": "array", "items": { "type": "string" } },
          "tenant_id": { "type": "string" }
        }
      },
      "DissectRequest": {
        "type": "object",
        "properties": {
          "url": { "type": "string" },
          "html": { "type": "string" },
          "product_name": { "type": "string" },
          "uvp": { "type": "string" },
          "tenant_id": { "type": "string" }
        }
      },
      "SvgRequest": {
        "type": "object",
        "properties": {
          "product_name": { "type": "string" },
          "competitor_name": { "type": "string" },
          "uvp": { "type": "string" },
          "price_anchor": { "type": "string" },
          "social_proof": { "type": "string" },
          "guarantee": { "type": "string" },
          "pain_points": { "type": "array", "items": { "type": "string" } },
          "sizes": { "type": "array", "items": { "type": "string" } },
          "templates": { "type": "array", "items": { "type": "string" } },
          "theme": { "type": "string" },
          "brand_colors": { "type": "object" },
          "tenant_id": { "type": "string" }
        }
      },
      "PreflightRequest": {
        "type": "object",
        "properties": {
          "text": { "type": "string" },
          "texts": { "type": "array", "items": { "type": "string" } },
          "scripts": { "type": ["array", "object"] },
          "product_name": { "type": "string" },
          "uvp": { "type": "string" },
          "final_url": { "type": "string" },
          "tenant_id": { "type": "string" }
        }
      },
      "BatchRequest": {
        "type": "object",
        "required": ["items"],
        "properties": {
          "items": { "type": "array", "items": { "$ref": "#/components/schemas/CompileRequest" } },
          "max_budget_micros": { "type": "integer", "minimum": 0, "maximum": 2000000 },
          "tenant_id": { "type": "string" }
        }
      },
      "CompileResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "compile_id": { "type": "string" },
          "operation": { "type": "string" },
          "product_context": { "type": "object" },
          "dissection": { "type": "object" },
          "scripts": { "type": "object" },
          "google_rsa": { "type": "object" },
          "hero_variants": { "type": "object" },
          "svgs": { "type": "object" },
          "preflight": { "type": "object" },
          "csv_exports": { "type": "object" },
          "cache": { "type": "object" },
          "billing": { "type": "object" },
          "billed_micros": { "type": "integer" },
          "sha256_attestation": { "type": "string" },
          "disclaimer": { "type": "string" },
          "zero_data_resale": { "type": "boolean" },
          "generated_at_utc": { "type": "string" }
        }
      },
      "GenericOperationResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "operation": { "type": "string" },
          "billed_micros": { "type": "integer" },
          "sha256_attestation": { "type": "string" },
          "zero_data_resale": { "type": "boolean" }
        }
      },
      "BatchResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "total_items": { "type": "integer" },
          "succeeded": { "type": "integer" },
          "failed_unbilled": { "type": "integer" },
          "total_billed_micros": { "type": "integer" },
          "results": { "type": "array", "items": { "type": "object" } }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean", "const": false },
          "status_code": { "type": "integer" },
          "operation": { "type": "string" },
          "error_code": { "type": "string" },
          "error": { "type": "string" },
          "billed_micros": { "type": "integer", "const": 0 },
          "zero_data_resale": { "type": "boolean", "const": true }
        }
      },
      "McpRequest": {
        "type": "object",
        "required": ["jsonrpc", "method"],
        "properties": {
          "jsonrpc": { "type": "string", "const": "2.0" },
          "id": { "type": ["string", "integer", "null"] },
          "method": { "type": "string", "enum": ["initialize", "tools/list", "tools/call"] },
          "params": { "type": "object" }
        }
      },
      "WebhookResult": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "status_code": { "type": "integer" },
          "event_id": { "type": "string" },
          "event_type": { "type": "string" },
          "tenant_id": { "type": "string" },
          "payer_sha256_12": { "type": "string" },
          "product_id": { "type": "string" },
          "sku_id": { "type": "string" },
          "credits_granted_micros": { "type": "integer" },
          "balance_micros": { "type": "integer" },
          "replayed": { "type": "boolean" },
          "status": { "type": "string" }
        }
      }
    }
  }
}
