{
  "openapi": "3.1.0",
  "info": {
    "title": "Audit-Anything API",
    "version": "1.0.0",
    "summary": "Polymorphic 5-domain deterministic security, compliance, SBOM, privacy/ToS, and secret-hygiene pre-audit engine with SHA-256 attestations and $0 billing on 422/SSRF/errors.",
    "description": "Deterministic technical pre-audit API covering passive public Web TLS and HTTP headers (web_tls), OWASP/SOC2/GDPR config baselines (compliance_config), SBOM and copyleft license conflicts (sbom_license), Privacy Policy and Terms of Service poison-pill clauses (privacy_tos), and high-entropy/prefix secret leak scanning with zero plaintext secret echo (secret_scan). Invalid inputs, SSRF rejections (HTTP 422), fake-200 error pages, and misses strictly bill $0 (billed_micros = 0). Hard $2.00 (2,000,000 micro-USD) external spend cap. Zero customer data resale or model training guarantee. Deterministic technical pre-audit tooling only — not a CPA firm, not a law firm, not legal advice, and does not issue a formal audit report.",
    "contact": {
      "name": "Audit-Anything Operations",
      "email": "ops@fastmesh.dev",
      "url": "https://audit.fastmesh.dev"
    }
  },
  "servers": [
    {
      "url": "https://audit.fastmesh.dev",
      "description": "Public HTTPS Gateway Mount"
    },
    {
      "url": "http://127.0.0.1:9001",
      "description": "Local Runtime Server"
    }
  ],
  "tags": [
    { "name": "Health", "description": "Liveness, 5-domain readiness, and ledger health probes" },
    { "name": "Audit", "description": "Single and concurrent batch 5-domain deterministic pre-audits" },
    { "name": "Export", "description": "JSON, Markdown, CSV, and SARIF 2.1.0 dossier exports" },
    { "name": "MCP", "description": "Native flat JSON-RPC 2.0 Model Context Protocol endpoint" },
    { "name": "Billing", "description": "Creem fixed prepaid credit packs, balance queries, and HMAC-SHA256 webhook settlement" },
    { "name": "Discovery", "description": "Try-Now console, OpenAPI 3.1, llms.txt, skill.md, and technical guides" }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "getTryNowConsole",
        "tags": ["Discovery"],
        "summary": "Serve the 5-second zero-signup Try-Now web console",
        "responses": {
          "200": {
            "description": "Interactive HTML Try-Now sandbox",
            "content": {
              "text/html": {
                "schema": { "type": "string" }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getHealth",
        "tags": ["Health"],
        "summary": "Check Audit-Anything service liveness and subsystem readiness",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HealthResponse" }
              }
            }
          }
        }
      }
    },
    "/audit": {
      "post": {
        "operationId": "auditArtifact",
        "tags": ["Audit"],
        "summary": "Run a deterministic single-artifact audit across 5 domains or auto mode",
        "description": "Analyzes a public HTTPS URL (passive TLS + headers + security.txt), config spec (OpenAPI/Dockerfile/Nginx/Caddy/compose), SBOM/manifest, Privacy Policy/ToS text, or code/env log snippet. Returns a SHA-256 attested AuditDossier with concrete remediation patches. Invalid inputs, private/metadata SSRF targets, and fake-200 pages 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" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AuditRequest" },
              "examples": {
                "web_tls": {
                  "summary": "Passive HTTPS surface audit",
                  "value": { "domain": "web_tls", "url": "https://example.com" }
                },
                "compliance_config": {
                  "summary": "Dockerfile & OpenAPI OWASP/SOC2/GDPR baseline audit",
                  "value": { "domain": "compliance_config", "content": "FROM python:3.12\nUSER root\nEXPOSE 80\nENV DEBUG=true\n" }
                },
                "sbom_license": {
                  "summary": "package.json SBOM and license conflict audit",
                  "value": { "domain": "sbom_license", "content": "{\"name\":\"demo-app\",\"license\":\"MIT\",\"dependencies\":{\"lodash\":\"4.17.15\",\"axios\":\"*\"}}" }
                },
                "privacy_tos": {
                  "summary": "Terms of Service poison-pill scan",
                  "value": { "domain": "privacy_tos", "content": "Section 7.1: Customer grants a perpetual, irrevocable, sublicensable license to train AI models and resell customer telemetry to third-party data brokers." }
                },
                "secret_scan": {
                  "summary": "Source/env secret leak scan (zero plaintext echo)",
                  "value": { "domain": "secret_scan", "content": "DB_HOST=10.20.30.40\nLOG_LEVEL=info\n" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SHA-256 attested AuditDossier",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AuditDossier" }
              }
            }
          },
          "422": {
            "description": "Invalid, empty, or SSRF-blocked input ($0 billed, billed_micros = 0)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AuditErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/audit": {
      "post": {
        "operationId": "auditArtifactApi",
        "tags": ["Audit"],
        "summary": "Canonical API alias for POST /audit",
        "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" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AuditRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SHA-256 attested AuditDossier",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AuditDossier" }
              }
            }
          },
          "422": {
            "description": "Invalid, empty, or SSRF-blocked input ($0 billed, billed_micros = 0)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AuditErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/batch": {
      "post": {
        "operationId": "auditBatch",
        "tags": ["Audit"],
        "summary": "Concurrent multi-artifact batch audit with hard max_budget_micros cap",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BatchAuditRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch audit summary and per-item AuditDossier results",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BatchAuditResponse" }
              }
            }
          },
          "422": { "description": "Invalid batch request ($0 billed)" }
        }
      }
    },
    "/api/batch": {
      "post": {
        "operationId": "auditBatchApi",
        "tags": ["Audit"],
        "summary": "Canonical API alias for POST /batch",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BatchAuditRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch audit summary and per-item AuditDossier results",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BatchAuditResponse" }
              }
            }
          },
          "422": { "description": "Invalid batch request ($0 billed)" }
        }
      }
    },
    "/export": {
      "post": {
        "operationId": "exportAuditDossier",
        "tags": ["Export"],
        "summary": "Export an AuditDossier in JSON, Markdown, CSV, or SARIF 2.1.0",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ExportRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Rendered export payload in json, markdown, csv, or sarif" },
          "422": { "description": "Invalid export payload or format ($0 billed)" }
        }
      },
      "get": {
        "operationId": "exportAuditDossierGet",
        "tags": ["Export"],
        "summary": "Export a stored AuditDossier by dossier_id in JSON, Markdown, CSV, or SARIF 2.1.0",
        "parameters": [
          { "name": "dossier_id", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "format", "in": "query", "required": false, "schema": { "type": "string", "enum": ["json", "markdown", "md", "csv", "sarif"], "default": "json" } }
        ],
        "responses": {
          "200": { "description": "Rendered export payload" },
          "404": { "description": "Dossier not found" },
          "422": { "description": "Missing or invalid query parameter ($0 billed)" }
        }
      }
    },
    "/api/export": {
      "post": {
        "operationId": "exportAuditDossierApi",
        "tags": ["Export"],
        "summary": "Canonical API alias for POST /export",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ExportRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Rendered export payload in json, markdown, csv, or sarif" },
          "422": { "description": "Invalid export payload or format ($0 billed)" }
        }
      },
      "get": {
        "operationId": "exportAuditDossierApiGet",
        "tags": ["Export"],
        "summary": "Canonical API alias for GET /export",
        "parameters": [
          { "name": "dossier_id", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "format", "in": "query", "required": false, "schema": { "type": "string", "enum": ["json", "markdown", "md", "csv", "sarif"], "default": "json" } }
        ],
        "responses": {
          "200": { "description": "Rendered export payload" },
          "404": { "description": "Dossier not found" },
          "422": { "description": "Missing or invalid query parameter ($0 billed)" }
        }
      }
    },
    "/mcp": {
      "post": {
        "operationId": "invokeMcp",
        "tags": ["MCP"],
        "summary": "Native flat JSON-RPC 2.0 MCP server endpoint",
        "description": "Supports initialize, notifications/initialized, tools/list, and tools/call for audit_artifact, audit_batch, audit_pricing, and audit_verify_attestation.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["jsonrpc", "method"],
                "properties": {
                  "jsonrpc": { "type": "string", "const": "2.0" },
                  "id": { "oneOf": [{ "type": "string" }, { "type": "integer" }, { "type": "null" }] },
                  "method": { "type": "string", "enum": ["initialize", "notifications/initialized", "tools/list", "tools/call"] },
                  "params": { "type": "object" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "JSON-RPC 2.0 response payload" }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "getOpenApiSpec",
        "tags": ["Discovery"],
        "summary": "Retrieve the OpenAPI 3.1.0 machine-readable specification",
        "responses": {
          "200": { "description": "OpenAPI 3.1.0 JSON document" }
        }
      }
    },
    "/llms.txt": {
      "get": {
        "operationId": "getLlmsTxt",
        "tags": ["Discovery"],
        "summary": "Retrieve the AI agent discovery manifest (llms.txt)",
        "responses": {
          "200": {
            "description": "Plain-text agent discovery index",
            "content": { "text/plain": { "schema": { "type": "string" } } }
          }
        }
      }
    },
    "/skill.md": {
      "get": {
        "operationId": "getSkillMd",
        "tags": ["Discovery"],
        "summary": "Retrieve the agent-executable skill contract (skill.md)",
        "responses": {
          "200": {
            "description": "Markdown skill contract",
            "content": { "text/markdown": { "schema": { "type": "string" } } }
          }
        }
      }
    },
    "/guides": {
      "get": {
        "operationId": "listGuides",
        "tags": ["Discovery"],
        "summary": "List technical security, compliance, SBOM, ToS, and secret-hygiene guides",
        "responses": {
          "200": { "description": "Index of published static guides" }
        }
      }
    },
    "/guides/{slug}": {
      "get": {
        "operationId": "getGuideBySlug",
        "tags": ["Discovery"],
        "summary": "Serve an individual SEO/GEO technical guide page",
        "parameters": [
          { "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "HTML technical guide page" },
          "404": { "description": "Guide slug not found" }
        }
      }
    },
    "/api/billing/packs": {
      "get": {
        "operationId": "listBillingPacks",
        "tags": ["Billing"],
        "summary": "List Creem fixed prepaid credit packs ($19/$79/$249) and per-domain micro-USD tolls",
        "responses": {
          "200": {
            "description": "Creem credit packs and per-domain pricing table",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BillingPacksResponse" }
              }
            }
          }
        }
      }
    },
    "/api/billing/balance": {
      "get": {
        "operationId": "getBillingBalance",
        "tags": ["Billing"],
        "summary": "Query tenant prepaid credit balance, audit counts, and $2.00 external spend cap status",
        "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 balance and external spend status",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BillingBalanceResponse" }
              }
            }
          },
          "422": { "description": "Missing or invalid tenant_id ($0 billed)" }
        }
      }
    },
    "/webhooks/creem": {
      "post": {
        "operationId": "processCreemWebhook",
        "tags": ["Billing"],
        "summary": "Idempotent Creem HMAC-SHA256 prepaid credit webhook ingress",
        "description": "Verifies creem-signature in constant time using CREEM_WEBHOOK_SECRET from environment variables, deduplicates event_id inside SQLite WAL BEGIN IMMEDIATE, maps product_id to prepaid credits, and redacts payer email to sha256[:12].",
        "parameters": [
          { "name": "creem-signature", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Webhook settled or deduplicated idempotently" },
          "400": { "description": "Malformed JSON or missing event_id/eventType" },
          "401": { "description": "Invalid or missing HMAC-SHA256 signature" },
          "503": { "description": "CREEM_WEBHOOK_SECRET not configured" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "status": { "type": "string" },
          "service": { "type": "string" },
          "version": { "type": "string" },
          "public_url": { "type": "string" },
          "port": { "type": "integer" },
          "domains": { "type": "array", "items": { "type": "string" } },
          "ledger_enabled": { "type": "boolean" },
          "cache_enabled": { "type": "boolean" },
          "mcp_enabled": { "type": "boolean" }
        }
      },
      "AuditRequest": {
        "type": "object",
        "properties": {
          "domain": {
            "type": "string",
            "enum": ["auto", "web_tls", "compliance_config", "sbom_license", "privacy_tos", "secret_scan"],
            "default": "auto"
          },
          "url": { "type": "string", "description": "Public HTTPS URL for passive web_tls audit (private/loopback/metadata hosts rejected with HTTP 422)" },
          "target": { "type": "string", "description": "Artifact target string, URL, or identifier" },
          "content": {
            "oneOf": [{ "type": "string" }, { "type": "object" }],
            "description": "Inline config, SBOM manifest, Privacy Policy/ToS text, or code/env snippet"
          },
          "snapshot": { "type": "object", "description": "Optional offline passive TLS/headers snapshot dict for deterministic web_tls inspection" },
          "filename": { "type": "string", "description": "Optional filename hint (e.g., package.json, Dockerfile, nginx.conf, openapi.json)" },
          "license_policy": {
            "type": "string",
            "enum": ["commercial", "permissive_only", "copyleft_allowed"],
            "default": "commercial",
            "description": "License compatibility policy for sbom_license audits"
          },
          "verify": { "type": "boolean", "default": false },
          "format": { "type": "string", "enum": ["json", "markdown", "csv", "sarif"], "default": "json" },
          "tenant_id": { "type": "string" }
        }
      },
      "AuditFinding": {
        "type": "object",
        "required": ["rule_id", "severity", "title", "description", "evidence", "remediation"],
        "properties": {
          "rule_id": { "type": "string" },
          "severity": { "type": "string", "enum": ["critical", "high", "medium", "low", "info"] },
          "title": { "type": "string" },
          "description": { "type": "string" },
          "evidence": { "type": "string" },
          "location": { "type": "string" },
          "line_number": { "type": ["integer", "null"] },
          "secret_sha256_prefix_12": { "type": ["string", "null"] },
          "controls": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "owasp": { "type": "array", "items": { "type": "string" } },
                  "soc2": { "type": "array", "items": { "type": "string" } },
                  "gdpr": { "type": "array", "items": { "type": "string" } },
                  "cve": { "type": "array", "items": { "type": "string" } }
                }
              },
              { "type": "array", "items": { "type": "string" } }
            ]
          },
          "remediation": { "type": "string" }
        }
      },
      "RemediationPatch": {
        "type": "object",
        "required": ["rule_id", "title", "patch_type", "snippet"],
        "properties": {
          "rule_id": { "type": "string" },
          "title": { "type": "string" },
          "patch_type": { "type": "string" },
          "snippet": { "type": "string" }
        }
      },
      "AuditDossier": {
        "type": "object",
        "required": [
          "ok",
          "dossier_id",
          "domain",
          "detected_format",
          "score_0_100",
          "grade",
          "summary",
          "findings_count",
          "critical_findings",
          "findings",
          "remediation_patches",
          "cache",
          "billing",
          "billed_micros",
          "sha256_attestation",
          "disclaimer",
          "zero_data_resale",
          "generated_at_utc"
        ],
        "properties": {
          "ok": { "type": "boolean" },
          "dossier_id": { "type": "string" },
          "domain": { "type": "string", "enum": ["web_tls", "compliance_config", "sbom_license", "privacy_tos", "secret_scan"] },
          "detected_format": { "type": "string" },
          "score_0_100": { "type": "integer", "minimum": 0, "maximum": 100 },
          "grade": { "type": "string", "enum": ["A+", "A", "B", "C", "D", "F"] },
          "summary": { "type": "string" },
          "findings_count": {
            "type": "object",
            "properties": {
              "critical": { "type": "integer" },
              "high": { "type": "integer" },
              "medium": { "type": "integer" },
              "low": { "type": "integer" },
              "info": { "type": "integer" },
              "total": { "type": "integer" }
            }
          },
          "critical_findings": { "type": "array", "items": { "$ref": "#/components/schemas/AuditFinding" } },
          "findings": { "type": "array", "items": { "$ref": "#/components/schemas/AuditFinding" } },
          "remediation_patches": { "type": "array", "items": { "$ref": "#/components/schemas/RemediationPatch" } },
          "cache": {
            "type": "object",
            "properties": {
              "hit": { "type": "boolean" },
              "scope": { "type": "string" },
              "ttl_seconds": { "type": "integer" },
              "price_percent": { "type": "integer" }
            }
          },
          "billing": {
            "type": "object",
            "properties": {
              "base_price_micros": { "type": "integer" },
              "billed_micros": { "type": "integer" },
              "billed_usd": { "type": "number" },
              "external_cost_micros": { "type": "integer" },
              "tenant_id": { "type": "string" },
              "charge_reason": { "type": "string" }
            }
          },
          "billed_micros": { "type": "integer", "minimum": 0 },
          "sha256_attestation": { "type": "string", "minLength": 64, "maxLength": 64 },
          "disclaimer": { "type": "string" },
          "zero_data_resale": { "type": "boolean", "const": true },
          "generated_at_utc": { "type": "string", "format": "date-time" }
        }
      },
      "AuditErrorResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean", "const": false },
          "error": { "type": "string" },
          "error_code": { "type": "string" },
          "billed_micros": { "type": "integer", "const": 0 },
          "zero_data_resale": { "type": "boolean", "const": true }
        }
      },
      "BatchAuditRequest": {
        "type": "object",
        "required": ["items"],
        "properties": {
          "items": { "type": "array", "items": { "$ref": "#/components/schemas/AuditRequest" } },
          "max_budget_micros": { "type": "integer", "default": 2000000, "maximum": 2000000 },
          "tenant_id": { "type": "string" }
        }
      },
      "BatchAuditResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "count": { "type": "integer" },
          "total_billed_micros": { "type": "integer" },
          "budget_capped": { "type": "boolean" },
          "results": { "type": "array", "items": { "$ref": "#/components/schemas/AuditDossier" } }
        }
      },
      "ExportRequest": {
        "type": "object",
        "required": ["format"],
        "properties": {
          "format": { "type": "string", "enum": ["json", "markdown", "md", "csv", "sarif"] },
          "dossier_id": { "type": "string" },
          "dossier": { "$ref": "#/components/schemas/AuditDossier" }
        }
      },
      "BillingPacksResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "service_name": { "type": "string" },
          "packs": { "type": "array", "items": { "type": "object" } },
          "domain_pricing": { "type": "object" },
          "billing_policy": { "type": "object" },
          "compliance_notice": { "type": "string" }
        }
      },
      "BillingBalanceResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "tenant_id": { "type": "string" },
          "exists": { "type": "boolean" },
          "balance_micros": { "type": "integer" },
          "balance_usd": { "type": "number" },
          "total_credited_micros": { "type": "integer" },
          "total_debited_micros": { "type": "integer" },
          "total_audits": { "type": "integer" },
          "total_zero_bill_events": { "type": "integer" },
          "external_spend": { "type": "object" }
        }
      }
    }
  }
}
