{
  "openapi": "3.1.0",
  "info": {
    "title": "AI Visibility Audit API",
    "version": "0.1.0",
    "description": "Run AI visibility audits and read saved reports. Free; limited to 20 audits per hour per client.",
    "contact": { "name": "Local Search Pain", "url": "https://localsearchpain.com/" }
  },
  "servers": [{ "url": "https://localsearchpain.com" }],
  "paths": {
    "/api/audit/stream": {
      "get": {
        "operationId": "runAudit",
        "summary": "Run an audit (server-sent events)",
        "description": "Streams `progress` events, then one `done` event whose data is {\"id\": \"<report id>\"}, or an `error` event.",
        "parameters": [
          { "name": "url", "in": "query", "required": true, "schema": { "type": "string" }, "description": "Public page URL to audit" },
          { "name": "render", "in": "query", "schema": { "type": "boolean", "default": true }, "description": "Render JavaScript in headless Chromium" },
          { "name": "psi", "in": "query", "schema": { "type": "boolean", "default": true }, "description": "Measure Core Web Vitals with PageSpeed Insights (adds 20-30 s)" },
          { "name": "ai", "in": "query", "schema": { "type": "boolean", "default": true }, "description": "Add an AI-written summary" }
        ],
        "responses": { "200": { "description": "Event stream", "content": { "text/event-stream": { "schema": { "type": "string" } } } } }
      }
    },
    "/api/report/{id}": {
      "get": {
        "operationId": "getReport",
        "summary": "Get a saved report",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^[A-Za-z0-9]{6,16}$" } }],
        "responses": {
          "200": { "description": "Full report JSON: scores, pillars, findings, checks and generated fixes", "content": { "application/json": { "schema": { "type": "object" } } } },
          "404": { "description": "Report not found" }
        }
      }
    },
    "/api/og/{id}.svg": {
      "get": {
        "operationId": "getShareImage",
        "summary": "Share image for a report",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "SVG image", "content": { "image/svg+xml": {} } } }
      }
    },
    "/api/health": {
      "get": { "operationId": "health", "summary": "Service health", "responses": { "200": { "description": "OK" } } }
    }
  }
}
