{
  "openapi": "3.1.0",
  "info": {
    "title": "Verify-Anything API",
    "version": "1.0.0",
    "summary": "Deterministic 5-domain verification engine with SHA-256 tamper-evident receipts and $0-on-miss billing.",
    "description": "Polymorphic deterministic verification across DNS/Email/TLS, Entity/Tax registries, Regulatory Licenses, Anti-Fake-200 HTTP Integrity, and SHA-256 Artifact Attestation. Every request emits a tamper-evident VerificationReceipt. Invalid inputs (422), upstream misses, and INCONCLUSIVE verdicts are strictly billed $0 (billed_micros = 0). Zero customer query or receipt data resale guarantee.",
    "contact": {
      "name": "Verify-Anything Operations",
      "email": "ops@fastmesh.dev",
      "url": "https://verify.fastmesh.dev"
    }
  },
  "servers": [
    {
      "url": "https://verify.fastmesh.dev",
      "description": "Public HTTPS Gateway Mount"
    },
    {
      "url": "http://127.0.0.1:8801",
      "description": "Local Runtime Server"
    }
  ],
  "tags": [
    { "name": "Health", "description": "Service liveness and readiness probes" },
    { "name": "Verification", "description": "Single and batch polymorphic 5-domain verification" },
    { "name": "Receipts", "description": "Tamper-evident SHA-256 receipt lookup and validation" },
    { "name": "MCP", "description": "Native flat JSON-RPC 2.0 Model Context Protocol endpoint" },
    { "name": "Billing", "description": "Creem HMAC-SHA256 prepaid credit webhook settlement" }
  ],
  "paths": {
    "/health": {
      "get": {
        "operationId": "getHealth",
        "tags": ["Health"],
        "summary": "Check Verify-Anything service health",
        "responses": {
          "200": {
            "description": "Service is healthy and ready",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HealthResponse" },
                "example": {
                  "status": "ok",
                  "service": "verify-anything",
                  "version": "1.0.0",
                  "public_host": "verify.fastmesh.dev",
                  "port": 8801,
                  "domains": [
                    "dns_email",
                    "entity_tax",
                    "regulatory_license",
                    "http_integrity",
                    "artifact_attestation"
                  ],
                  "ledger_enabled": true,
                  "mcp_enabled": true,
                  "timestamp_utc": "2026-12-01T19:40:00+00:00"
                }
              }
            }
          }
        }
      }
    },
    "/verify": {
      "post": {
        "operationId": "verifySingle",
        "tags": ["Verification"],
        "summary": "Verify a single target across any of the 5 supported domains",
        "description": "Returns a deterministic, SHA-256 signed VerificationReceipt. Strictly bills $0 (`billed_micros = 0`) on 422 invalid input, upstream error, miss, or INCONCLUSIVE verdict.",
        "parameters": [
          {
            "name": "X-Tenant-Id",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Optional tenant identifier for prepaid ledger accounting and 10% recheck pricing."
          },
          {
            "name": "X-API-Key",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Optional prepaid API key (omittable for zero-signup Try-Now sandbox)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/VerificationRequest" },
              "examples": {
                "dns_email_cloudflare": {
                  "summary": "Domain 1: DNS / SPF / DMARC / Live TLS verification",
                  "value": {
                    "domain": "dns_email",
                    "target": "cloudflare.com",
                    "confirm": false,
                    "recheck": false
                  }
                },
                "entity_tax_sec_cik": {
                  "summary": "Domain 2: Entity & Tax (SEC EDGAR CIK / EU VAT / US EIN)",
                  "value": {
                    "domain": "entity_tax",
                    "target": "CIK0000320193",
                    "confirm": false,
                    "recheck": false
                  }
                },
                "regulatory_license_npi": {
                  "summary": "Domain 3: US CMS NPPES NPI Healthcare License",
                  "value": {
                    "domain": "regulatory_license",
                    "target": "1881018208",
                    "confirm": false,
                    "recheck": false
                  }
                },
                "http_integrity_fake200": {
                  "summary": "Domain 4: Anti-Fake-200 CAPTCHA/Login Wall Detection",
                  "value": {
                    "domain": "http_integrity",
                    "target": "https://api.example.com/v1/records",
                    "status_code": 200,
                    "headers": { "Content-Type": "text/html; charset=utf-8" },
                    "body": "<html><title>Just a moment...</title><div>Verify you are human - CAPTCHA</div></html>",
                    "expected_content_type": "application/json",
                    "required_keys": ["records"]
                  }
                },
                "artifact_attestation_sha256": {
                  "summary": "Domain 5: SHA-256 Digest & Schema Artifact Attestation",
                  "value": {
                    "domain": "artifact_attestation",
                    "target": "release-manifest-2026.json",
                    "confirm": true,
                    "content": "{\"release\":\"1.0.0\",\"status\":\"signed\"}",
                    "expected_sha256": "52842bdcd5d11d33faa196432eefe8beb0d8270f1531dadacf4ea9d50ff26383",
                    "required_fields": ["release", "status"]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verification completed with signed VerificationReceipt",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/VerificationReceipt" },
                "examples": {
                  "dns_email_verified": {
                    "summary": "Verified DNS/Email/TLS Receipt",
                    "value": {
                      "receipt_id": "vr_9a1b2c3d4e5f6a7b",
                      "domain": "dns_email",
                      "target": "cloudflare.com",
                      "verdict": "VERIFIED",
                      "confidence": 0.99,
                      "evidence_sources": [
                        {
                          "source": "cloudflare_doh",
                          "url": "https://1.1.1.1/dns-query?name=cloudflare.com&type=TXT",
                          "status": "ok",
                          "observed_at_utc": "2026-12-01T19:40:00+00:00",
                          "summary": "SPF and DMARC policies parsed; A/MX records resolved"
                        },
                        {
                          "source": "tls_live_handshake",
                          "url": "tls://cloudflare.com:443",
                          "status": "ok",
                          "observed_at_utc": "2026-12-01T19:40:00+00:00",
                          "summary": "Valid certificate chain matching SAN cloudflare.com"
                        }
                      ],
                      "checks": [
                        { "name": "dns_a_or_mx_present", "passed": true, "detail": "Resolved live A and MX records" },
                        { "name": "spf_record_valid", "passed": true, "detail": "v=spf1 policy found" },
                        { "name": "dmarc_record_valid", "passed": true, "detail": "v=DMARC1 policy found" },
                        { "name": "tls_cert_valid", "passed": true, "detail": "Certificate valid and unexpired" }
                      ],
                      "payload_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
                      "sha256_attestation": "4f8c9a12d5e6f7890123456789abcdef4f8c9a12d5e6f7890123456789abcdef",
                      "billed_micros": 15000,
                      "base_price_micros": 15000,
                      "cache_hit": false,
                      "cache_tier": "live",
                      "confirm_dual_source": false,
                      "timestamp_utc": "2026-12-01T19:40:00+00:00",
                      "zero_bill_reason": ""
                    }
                  },
                  "http_integrity_failed_fake200": {
                    "summary": "Detected Fake-200 CAPTCHA Wall Receipt",
                    "value": {
                      "receipt_id": "vr_7c6d5e4f3a2b1c0d",
                      "domain": "http_integrity",
                      "target": "https://api.example.com/v1/records",
                      "verdict": "FAILED",
                      "confidence": 0.98,
                      "evidence_sources": [
                        {
                          "source": "composite_anti_fake_200",
                          "url": "https://api.example.com/v1/records",
                          "status": "soft_block_detected",
                          "observed_at_utc": "2026-12-01T19:40:01+00:00",
                          "summary": "Detected CAPTCHA challenge wall and Content-Type mismatch (text/html vs application/json)"
                        }
                      ],
                      "checks": [
                        { "name": "no_captcha_wall", "passed": false, "detail": "Matched CAPTCHA challenge marker" },
                        { "name": "content_type_matches", "passed": false, "detail": "Expected application/json, got text/html" }
                      ],
                      "payload_sha256": "11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff",
                      "sha256_attestation": "99887766554433221100ffeeddccbbaa99887766554433221100ffeeddccbbaa",
                      "billed_micros": 20000,
                      "base_price_micros": 20000,
                      "cache_hit": false,
                      "cache_tier": "live",
                      "confirm_dual_source": false,
                      "timestamp_utc": "2026-12-01T19:40:01+00:00",
                      "zero_bill_reason": ""
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Malformed or unsupported verification input — strictly $0 billed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ZeroBillErrorResponse" },
                "example": {
                  "ok": false,
                  "error": "invalid_input",
                  "detail": "Parameter 'target' cannot be empty or placeholder 'N/A'.",
                  "billed_micros": 0,
                  "zero_bill_reason": "http_422_validation_error"
                }
              }
            }
          }
        }
      }
    },
    "/verify/batch": {
      "post": {
        "operationId": "verifyBatch",
        "tags": ["Verification"],
        "summary": "Verify a heterogeneous CSV or JSON batch with hard budget cap",
        "description": "Executes concurrent multi-domain checks bounded by `max_budget_micros`. Any row that errors, misses, or evaluates INCONCLUSIVE is strictly billed $0.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BatchVerifyRequest" },
                "example": {
                  "tenant_id": "tenant_demo",
                  "max_budget_micros": 200000,
                  "items": [
                    { "domain": "dns_email", "target": "cloudflare.com" },
                    { "domain": "entity_tax", "target": "CIK0000320193" },
                    { "domain": "regulatory_license", "target": "1881018208" }
                  ]
                }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch execution summary and per-item VerificationReceipts",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BatchVerifyResponse" }
              }
            }
          },
          "422": {
            "description": "Invalid batch request — strictly $0 billed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ZeroBillErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/receipt/{receipt_id}": {
      "get": {
        "operationId": "getReceipt",
        "tags": ["Receipts"],
        "summary": "Fetch a stored VerificationReceipt and verify its SHA-256 attestation",
        "parameters": [
          {
            "name": "receipt_id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Unique VerificationReceipt ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Receipt retrieved with cryptographic attestation check",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "signature_valid": { "type": "boolean" },
                    "receipt": { "$ref": "#/components/schemas/VerificationReceipt" }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Receipt ID not found",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ZeroBillErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "operationId": "mcpJsonRpc",
        "tags": ["MCP"],
        "summary": "Native flat JSON-RPC 2.0 MCP endpoint",
        "description": "Supports initialize, notifications/initialized, ping, tools/list, and tools/call for verify_anything, verify_batch, and verify_receipt.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/McpJsonRpcRequest" },
              "examples": {
                "initialize": {
                  "summary": "MCP Initialize Handshake",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 1,
                    "method": "initialize",
                    "params": {
                      "protocolVersion": "2025-03-26",
                      "clientInfo": { "name": "agent-client", "version": "1.0.0" }
                    }
                  }
                },
                "tools_list": {
                  "summary": "List Flat MCP Tools",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 2,
                    "method": "tools/list",
                    "params": {}
                  }
                },
                "tools_call_verify": {
                  "summary": "Invoke verify_anything Tool",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 3,
                    "method": "tools/call",
                    "params": {
                      "name": "verify_anything",
                      "arguments": {
                        "domain": "dns_email",
                        "target": "github.com",
                        "confirm": false
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 response payload",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/McpJsonRpcResponse" }
              }
            }
          },
          "202": {
            "description": "Accepted notification (notifications/initialized without id)"
          }
        }
      }
    },
    "/webhooks/creem": {
      "post": {
        "operationId": "creemWebhook",
        "tags": ["Billing"],
        "summary": "Creem HMAC-SHA256 payment webhook ingress",
        "description": "Verifies `creem-signature` HMAC-SHA256 using `CREEM_WEBHOOK_SECRET` from environment variables, deduplicates by `event_id`, and atomically credits the tenant wallet inside a SQLite WAL `BEGIN IMMEDIATE` transaction.",
        "parameters": [
          {
            "name": "creem-signature",
            "in": "header",
            "required": true,
            "schema": { "type": "string" },
            "description": "HMAC-SHA256 hex digest (or sha256=<hex>) computed over the raw HTTP request body."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreemWebhookPayload" },
              "example": {
                "id": "evt_creem_01",
                "eventType": "checkout.completed",
                "object": {
                  "product_id": "prod_verify_anything_pro_29",
                  "amount": 2900,
                  "currency": "USD",
                  "customer": { "email": "buyer@example.com" },
                  "metadata": { "tenant_id": "tenant_acme", "sku_id": "sku_verify_pro_29" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event verified and atomically settled (or deduplicated idempotently)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "event_id": { "type": "string" },
                    "tenant_id": { "type": "string" },
                    "credits_granted_micros": { "type": "integer" },
                    "balance_micros": { "type": "integer" },
                    "replayed": { "type": "boolean" },
                    "status": { "type": "string" }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing creem-signature HMAC-SHA256 digest"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "required": ["status", "service"],
        "properties": {
          "status": { "type": "string", "enum": ["ok"] },
          "service": { "type": "string" },
          "version": { "type": "string" },
          "public_host": { "type": "string" },
          "port": { "type": "integer" },
          "domains": { "type": "array", "items": { "type": "string" } },
          "pricing": { "type": "object" },
          "cache_stats": { "type": "object" },
          "ledger_enabled": { "type": "boolean" },
          "mcp_enabled": { "type": "boolean" },
          "timestamp_utc": { "type": "string", "format": "date-time" }
        }
      },
      "VerificationRequest": {
        "type": "object",
        "required": ["domain", "target"],
        "properties": {
          "domain": {
            "type": "string",
            "enum": [
              "dns_email",
              "entity_tax",
              "regulatory_license",
              "http_integrity",
              "artifact_attestation"
            ]
          },
          "target": { "type": "string", "minLength": 1 },
          "confirm": { "type": "boolean", "default": false },
          "recheck": { "type": "boolean", "default": false },
          "tenant_id": { "type": "string" },
          "expected_sha256": { "type": "string" },
          "payload": { "type": "object" },
          "options": { "type": "object" }
        }
      },
      "EvidenceSource": {
        "type": "object",
        "required": ["source", "url", "status", "observed_at_utc", "summary"],
        "properties": {
          "source": { "type": "string" },
          "url": { "type": "string" },
          "status": { "type": "string" },
          "observed_at_utc": { "type": "string", "format": "date-time" },
          "summary": { "type": "string" }
        }
      },
      "CheckItem": {
        "type": "object",
        "required": ["name", "passed", "detail"],
        "properties": {
          "name": { "type": "string" },
          "passed": { "type": "boolean" },
          "detail": { "type": "string" }
        }
      },
      "VerificationReceipt": {
        "type": "object",
        "required": [
          "receipt_id",
          "domain",
          "target",
          "verdict",
          "confidence",
          "evidence_sources",
          "checks",
          "payload_sha256",
          "sha256_attestation",
          "billed_micros",
          "base_price_micros",
          "cache_hit",
          "cache_tier",
          "confirm_dual_source",
          "timestamp_utc",
          "zero_bill_reason"
        ],
        "properties": {
          "receipt_id": { "type": "string" },
          "domain": {
            "type": "string",
            "enum": [
              "dns_email",
              "entity_tax",
              "regulatory_license",
              "http_integrity",
              "artifact_attestation"
            ]
          },
          "target": { "type": "string" },
          "verdict": { "type": "string", "enum": ["VERIFIED", "FAILED", "INCONCLUSIVE"] },
          "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
          "evidence_sources": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/EvidenceSource" }
          },
          "checks": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/CheckItem" }
          },
          "payload_sha256": { "type": "string" },
          "sha256_attestation": { "type": "string" },
          "billed_micros": { "type": "integer", "minimum": 0 },
          "base_price_micros": { "type": "integer", "minimum": 0 },
          "cache_hit": { "type": "boolean" },
          "cache_tier": { "type": "string", "enum": ["live", "shared_cache", "recheck_10pct"] },
          "confirm_dual_source": { "type": "boolean" },
          "timestamp_utc": { "type": "string", "format": "date-time" },
          "zero_bill_reason": { "type": "string" }
        }
      },
      "BatchVerifyRequest": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/VerificationRequest" }
          },
          "csv_text": { "type": "string" },
          "max_budget_micros": { "type": "integer", "minimum": 0 },
          "tenant_id": { "type": "string" },
          "confirm": { "type": "boolean", "default": false },
          "recheck": { "type": "boolean", "default": false },
          "max_workers": { "type": "integer", "minimum": 1, "maximum": 16 }
        }
      },
      "BatchVerifyResponse": {
        "type": "object",
        "properties": {
          "batch_id": { "type": "string" },
          "tenant_id": { "type": "string" },
          "total_items": { "type": "integer" },
          "processed_items": { "type": "integer" },
          "verified_count": { "type": "integer" },
          "failed_count": { "type": "integer" },
          "inconclusive_count": { "type": "integer" },
          "stopped_by_budget": { "type": "boolean" },
          "skipped_by_budget_count": { "type": "integer" },
          "cache_hits": { "type": "integer" },
          "zero_billed_rows": { "type": "integer" },
          "max_budget_micros": { "type": ["integer", "null"] },
          "total_billed_micros": { "type": "integer" },
          "elapsed_ms": { "type": "integer" },
          "timestamp_utc": { "type": "string", "format": "date-time" },
          "batch_sha256": { "type": "string" },
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "row_index": { "type": "integer" },
                "skipped_by_budget": { "type": "boolean" },
                "receipt": { "$ref": "#/components/schemas/VerificationReceipt" }
              }
            }
          }
        }
      },
      "ZeroBillErrorResponse": {
        "type": "object",
        "required": ["ok", "error", "billed_micros"],
        "properties": {
          "ok": { "type": "boolean" },
          "error": { "type": "string" },
          "detail": { "type": "string" },
          "billed_micros": { "type": "integer", "enum": [0] },
          "zero_bill_reason": { "type": "string" }
        }
      },
      "McpJsonRpcRequest": {
        "type": "object",
        "required": ["jsonrpc", "method"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "type": ["string", "integer", "null"] },
          "method": { "type": "string" },
          "params": { "type": "object" }
        }
      },
      "McpJsonRpcResponse": {
        "type": "object",
        "required": ["jsonrpc"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "type": ["string", "integer", "null"] },
          "result": { "type": "object" },
          "error": { "type": "object" }
        }
      },
      "CreemWebhookPayload": {
        "type": "object",
        "required": ["id", "eventType", "object"],
        "properties": {
          "id": { "type": "string" },
          "eventType": { "type": "string" },
          "object": { "type": "object" }
        }
      }
    }
  }
}
