{
  "openapi": "3.1.0",
  "info": {
    "title": "Screen-Anything API",
    "version": "1.0.0",
    "summary": "Polymorphic 5-domain public-data KYB, domain/TLS, sanctions fuzzy matching, OSS supply-chain health, and 0-100 SHA-256 attested vendor risk scorecard API with strict $0 billing on 422/SSRF/errors.",
    "description": "Deterministic public-data KYB and open-source supply-chain screening API covering corporate registry format & consistency checks (kyb_registry), passive DNS/DoH & live TLS certificate + typosquatting inspection (domain_tls), OFAC/EU/UN fuzzy sanctions matching with false-positive exclusion rationale (sanctions_fuzzy), GitHub/npm/PyPI OSS health scoring (oss_health), and composite 0-100 vendor risk scorecards + concurrent bulk CSV batch screening (vendor_scorecard). Invalid/empty 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. Public corporate, sanctions, DNS/TLS, and OSS data only — not a licensed credit bureau, not a consumer reporting agency, not legal advice; strict zero data resale.",
    "contact": {
      "name": "Screen-Anything Operations",
      "email": "ops@fastmesh.dev",
      "url": "https://screen.fastmesh.dev"
    }
  },
  "servers": [
    {
      "url": "https://screen.fastmesh.dev",
      "description": "Public HTTPS Gateway Mount"
    },
    {
      "url": "http://127.0.0.1:9013",
      "description": "Local Runtime Server"
    }
  ],
  "tags": [
    { "name": "Health", "description": "Liveness, 5-domain readiness, and SQLite WAL ledger health probes" },
    { "name": "Screen", "description": "Single and concurrent bulk CSV/JSON 5-domain public-data KYB & OSS screenings" },
    { "name": "Export", "description": "JSON, Markdown, CSV, and SARIF dossier exports" },
    { "name": "MCP", "description": "Native flat JSON-RPC 2.0 Model Context Protocol endpoint" },
    { "name": "Billing", "description": "Creem fixed prepaid credit packs ($19/$79/$249), pricing schedule, balance queries, and HMAC-SHA256 webhook settlement" },
    { "name": "Discovery", "description": "Try-Now console, OpenAPI 3.1, llms.txt, skill.md, sitemap.xml, and SEO/GEO landing pages" }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "getTryNowConsole",
        "tags": ["Discovery"],
        "summary": "Serve the 5-second zero-signup Try-Now KYB & OSS screening console",
        "responses": {
          "200": {
            "description": "Interactive HTML Try-Now sandbox",
            "content": {
              "text/html": {
                "schema": { "type": "string" }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getHealth",
        "tags": ["Health"],
        "summary": "Check Screen-Anything service liveness and subsystem readiness",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HealthResponse" }
              }
            }
          }
        }
      }
    },
    "/screen": {
      "post": {
        "operationId": "screenTarget",
        "tags": ["Screen"],
        "summary": "Run deterministic public-data screening across 5 KYB/OSS domains or auto mode",
        "description": "Screens a company/entity, public domain/HTTPS URL, registration number (SEC EDGAR CIK / UK Companies House / LEI), sanctions query (OFAC/EU/UN format + custom CSV/XML), or GitHub/npm/PyPI OSS package. Returns a SHA-256 attested RiskScorecard (0-100, LOW/MEDIUM/HIGH/CRITICAL). Empty/N/A 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/ScreenRequest" },
              "examples": {
                "vendor_scorecard": {
                  "summary": "Composite vendor KYB risk scorecard",
                  "value": {
                    "domain": "vendor_scorecard",
                    "company_name": "Acme Cloud Infrastructure Inc.",
                    "domain_name": "example.com",
                    "registration_number": "0000320193",
                    "jurisdiction": "US"
                  }
                },
                "kyb_registry": {
                  "summary": "Corporate registry format & shell heuristics",
                  "value": {
                    "domain": "kyb_registry",
                    "company_name": "Northstar Robotics Ltd",
                    "registration_number": "09876543",
                    "jurisdiction": "GB",
                    "url": "https://example.com"
                  }
                },
                "domain_tls": {
                  "summary": "Passive DNS/MX/SPF/DMARC & TLS/typosquatting check",
                  "value": { "domain": "domain_tls", "url": "https://example.com" }
                },
                "sanctions_fuzzy": {
                  "summary": "OFAC/EU/UN fuzzy sanctions screening",
                  "value": { "domain": "sanctions_fuzzy", "company_name": "Global Maritime Logistics LLC" }
                },
                "oss_health": {
                  "summary": "Public npm/PyPI/GitHub bus-factor & abandonment check",
                  "value": { "domain": "oss_health", "npm_package": "express" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SHA-256 attested RiskScorecard",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RiskScorecard" }
              }
            }
          },
          "422": {
            "description": "Invalid, empty, or SSRF-blocked input ($0 billed, billed_micros = 0)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ScreenErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/screen": {
      "post": {
        "operationId": "screenTargetApi",
        "tags": ["Screen"],
        "summary": "Canonical API alias for POST /screen",
        "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/ScreenRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SHA-256 attested RiskScorecard",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RiskScorecard" }
              }
            }
          },
          "422": {
            "description": "Invalid, empty, or SSRF-blocked input ($0 billed, billed_micros = 0)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ScreenErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/batch": {
      "post": {
        "operationId": "screenBatch",
        "tags": ["Screen"],
        "summary": "Concurrent multi-vendor JSON or CSV batch screening (50+ vendors) with hard $2.00 external spend cap",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BatchScreenRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch summary and per-vendor RiskScorecard results",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BatchScreenResponse" }
              }
            }
          },
          "422": { "description": "Invalid batch request ($0 billed)" }
        }
      }
    },
    "/api/batch": {
      "post": {
        "operationId": "screenBatchApi",
        "tags": ["Screen"],
        "summary": "Canonical API alias for POST /batch",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BatchScreenRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch summary and per-vendor RiskScorecard results",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BatchScreenResponse" }
              }
            }
          },
          "422": { "description": "Invalid batch request ($0 billed)" }
        }
      }
    },
    "/export": {
      "post": {
        "operationId": "exportRiskScorecard",
        "tags": ["Export"],
        "summary": "Export a RiskScorecard in JSON, Markdown, CSV, or SARIF",
        "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": "exportRiskScorecardGet",
        "tags": ["Export"],
        "summary": "Export a stored RiskScorecard by dossier_id in JSON, Markdown, CSV, or SARIF",
        "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": "exportRiskScorecardApi",
        "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" },
          "422": { "description": "Invalid export payload or format ($0 billed)" }
        }
      },
      "get": {
        "operationId": "exportRiskScorecardApiGet",
        "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)" }
        }
      }
    },
    "/pricing": {
      "get": {
        "operationId": "getPricing",
        "tags": ["Billing"],
        "summary": "Return Creem prepaid credit packs ($19/$79/$249), per-domain micro-USD tolls, and $0-on-422/miss policy",
        "responses": {
          "200": {
            "description": "Full pricing schedule and Creem prepaid credit packs",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BillingPacksResponse" }
              }
            }
          }
        }
      }
    },
    "/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, screen 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)" }
        }
      }
    },
    "/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 screen_vendor, screen_batch, screen_pricing, and screen_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" } } }
          }
        }
      }
    },
    "/sitemap.xml": {
      "get": {
        "operationId": "getSitemapXml",
        "tags": ["Discovery"],
        "summary": "Retrieve the XML sitemap for Screen-Anything and SEO/GEO landing pages",
        "responses": {
          "200": {
            "description": "XML sitemap",
            "content": { "application/xml": { "schema": { "type": "string" } } }
          }
        }
      }
    },
    "/seo": {
      "get": {
        "operationId": "listSeoPages",
        "tags": ["Discovery"],
        "summary": "List technical KYB, sanctions screening, domain/TLS, and OSS health landing pages",
        "responses": {
          "200": { "description": "Index of published SEO/GEO pages" }
        }
      }
    },
    "/seo/{slug}": {
      "get": {
        "operationId": "getSeoPageBySlug",
        "tags": ["Discovery"],
        "summary": "Serve an individual SEO/GEO KYB or OSS supply-chain landing page",
        "parameters": [
          { "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "HTML technical landing page" },
          "404": { "description": "SEO page slug not found" }
        }
      }
    },
    "/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" }
        }
      },
      "ScreenRequest": {
        "type": "object",
        "properties": {
          "domain": {
            "type": "string",
            "enum": ["auto", "kyb_registry", "domain_tls", "sanctions_fuzzy", "oss_health", "vendor_scorecard"],
            "default": "auto"
          },
          "company_name": { "type": "string", "description": "Legal company or vendor name" },
          "entity_name": { "type": "string", "description": "Alias for sanctions or entity query" },
          "domain_name": { "type": "string", "description": "Public corporate domain (e.g., stripe.com)" },
          "url": { "type": "string", "description": "Public HTTPS URL or repository URL (loopback/RFC1918/metadata blocked with HTTP 422)" },
          "registration_number": { "type": "string", "description": "SEC EDGAR CIK, UK Companies House number, or ISO 17442 LEI" },
          "cik": { "type": "string" },
          "lei": { "type": "string" },
          "jurisdiction": { "type": "string", "description": "Jurisdiction code (e.g., US, GB, DE, SG)" },
          "repo": { "type": "string", "description": "Public GitHub owner/repo or repository URL" },
          "npm_package": { "type": "string", "description": "Public npm package name" },
          "pypi_package": { "type": "string", "description": "Public PyPI package name" },
          "custom_list_csv": { "type": "string", "description": "Optional custom CSV sanctions watchlist rows" },
          "custom_list_xml": { "type": "string", "description": "Optional custom XML sanctions watchlist rows" },
          "snapshot": { "type": "object", "description": "Optional deterministic offline snapshot dict" },
          "no_cache": { "type": "boolean", "default": false },
          "verify": { "type": "boolean", "default": true },
          "format": { "type": "string", "enum": ["json", "markdown", "csv", "sarif"], "default": "json" },
          "tenant_id": { "type": "string" }
        }
      },
      "ScreenFinding": {
        "type": "object",
        "required": ["id", "severity", "category", "title", "description", "evidence"],
        "properties": {
          "id": { "type": "string" },
          "severity": { "type": "string", "enum": ["critical", "high", "medium", "low", "info"] },
          "category": { "type": "string" },
          "title": { "type": "string" },
          "description": { "type": "string" },
          "evidence": { "type": "string" },
          "rationale": { "type": "string" },
          "remediation": { "type": "string" }
        }
      },
      "RiskScorecard": {
        "type": "object",
        "required": [
          "ok",
          "dossier_id",
          "domain",
          "risk_score_0_100",
          "risk_tier",
          "summary",
          "findings_count",
          "findings",
          "cache",
          "billing",
          "billed_micros",
          "sha256_attestation",
          "disclaimer",
          "zero_data_resale",
          "generated_at_utc"
        ],
        "properties": {
          "ok": { "type": "boolean" },
          "status_code": { "type": "integer" },
          "dossier_id": { "type": "string" },
          "domain": { "type": "string", "enum": ["kyb_registry", "domain_tls", "sanctions_fuzzy", "oss_health", "vendor_scorecard"] },
          "subject": { "type": "object" },
          "risk_score_0_100": { "type": "integer", "minimum": 0, "maximum": 100 },
          "score_0_100": { "type": "integer", "minimum": 0, "maximum": 100 },
          "trust_score_0_100": { "type": "integer", "minimum": 0, "maximum": 100 },
          "risk_tier": { "type": "string", "enum": ["LOW", "MEDIUM", "HIGH", "CRITICAL", "UNSCORED"] },
          "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/ScreenFinding" } },
          "findings": { "type": "array", "items": { "$ref": "#/components/schemas/ScreenFinding" } },
          "signals": { "type": "array", "items": { "$ref": "#/components/schemas/ScreenFinding" } },
          "domain_data": { "type": "object" },
          "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 },
          "charged_micros": { "type": "integer", "minimum": 0 },
          "sha256_attestation": { "type": "string", "minLength": 64, "maxLength": 64 },
          "receipt_sha256": { "type": "string", "minLength": 64, "maxLength": 64 },
          "disclaimer": { "type": "string" },
          "zero_data_resale": { "type": "boolean", "const": true },
          "public_data_only": { "type": "boolean", "const": true },
          "generated_at_utc": { "type": "string", "format": "date-time" }
        }
      },
      "ScreenErrorResponse": {
        "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 }
        }
      },
      "BatchScreenRequest": {
        "type": "object",
        "properties": {
          "items": { "type": "array", "items": { "$ref": "#/components/schemas/ScreenRequest" } },
          "csv": { "type": "string", "description": "Bulk CSV vendor rows (50+ vendors supported)" },
          "csv_content": { "type": "string", "description": "Alias for csv" },
          "max_budget_micros": { "type": "integer", "default": 2000000, "maximum": 2000000 },
          "tenant_id": { "type": "string" }
        }
      },
      "BatchScreenResponse": {
        "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/RiskScorecard" } }
        }
      },
      "ExportRequest": {
        "type": "object",
        "required": ["format"],
        "properties": {
          "format": { "type": "string", "enum": ["json", "markdown", "md", "csv", "sarif"] },
          "dossier_id": { "type": "string" },
          "dossier": { "$ref": "#/components/schemas/RiskScorecard" }
        }
      },
      "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_screens": { "type": "integer" },
          "total_zero_bill_events": { "type": "integer" },
          "external_spend": { "type": "object" }
        }
      }
    }
  }
}
