{
  "openapi": "3.1.0",
  "info": {
    "title": "Crumb402",
    "version": "1.0.0",
    "description": "Public static HTML inspection with BNB Chain USD1 x402 v2 pricing. GET /v1/sample is a free fixed demo. Browser requests work from any origin without credentials; preflight does not require payment. A live quote includes optional Bazaar discovery metadata but is not proof of indexing or settlement."
  },
  "servers": [{ "url": "https://crumb402.com" }],
  "externalDocs": { "url": "https://crumb402.com/docs/" },
  "paths": {
    "/health": {
      "get": {
        "operationId": "health",
        "summary": "Check service availability and payment configuration",
        "responses": {
          "200": {
            "description": "Service is reachable. Configuration is not proof of settlement.",
            "content": { "application/json": { "schema": { "type": "object", "required": ["status", "service", "version", "network", "currency", "paymentsConfigured"], "properties": { "status": { "const": "ok" }, "service": { "const": "Crumb402" }, "version": { "type": "string" }, "network": { "const": "eip155:56" }, "currency": { "const": "USD1" }, "paymentsConfigured": { "type": "boolean" } } } } }
          }
        }
      }
    },
    "/v1/sample": {
      "get": {
        "operationId": "sample",
        "summary": "Read a fixed sample without paying or fetching a site",
        "responses": { "200": { "description": "Fixed sample; demo is true and changed is null.", "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/Inspection" }, { "properties": { "demo": { "const": true }, "changed": { "type": "null" } } }] } } } } }
      }
    },
    "/v1/inspect": {
      "get": {
        "operationId": "inspect",
        "summary": "Inspect an eligible public page after x402 authorization",
        "description": "Static HTML only. Robots rules apply; maximum page size is 196608 bytes. Requires 0.005 USD1 on BNB Smart Chain (eip155:56) using x402 v2 exact via Permit2. Returns 503 if payments are not configured or available.",
        "parameters": [
          { "name": "url", "in": "query", "required": true, "schema": { "type": "string", "format": "uri", "maxLength": 4096 }, "example": "https://example.com/", "description": "An eligible internet hostname on the default HTTP or HTTPS port; URL-encode as a query value." },
          { "name": "since", "in": "query", "schema": { "type": "string", "pattern": "^([0-9A-Fa-f]{64})?$" }, "description": "A prior live inspection fingerprint; empty is equivalent to omission." },
          { "name": "Payment-Signature", "in": "header", "schema": { "type": "string", "maxLength": 12000 }, "description": "x402 v2 signed payment authorization. Omit on the first request to obtain a quote when configured." }
        ],
        "responses": {
          "200": { "description": "Settled inspection result.", "headers": { "Payment-Response": { "$ref": "#/components/headers/Receipt" } }, "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/Inspection" }, { "properties": { "demo": { "const": false } } }] } } } },
          "400": { "description": "Invalid URL or fingerprint.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "description": "Invalid, expired, or mismatched payment authorization.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "402": { "description": "Payment required or settlement rejected.", "headers": { "Payment-Required": { "description": "Base64-encoded x402 v2 requirements.", "schema": { "type": "string" } }, "Payment-Response": { "$ref": "#/components/headers/Receipt" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "Excluded by robots policy or blocked destination.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "422": { "description": "Ineligible response, oversize document, or excessive redirects.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "431": { "description": "Oversized payment header.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "502": { "description": "DNS, upstream, robots policy, facilitator or settlement failure.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "503": { "description": "Payments unconfigured or facilitator initialization failed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" }, "example": { "error": { "code": "PAYMENTS_NOT_CONFIGURED", "message": "Paid inspection is not configured. Try the fixed, free GET /v1/sample response." } } } } },
          "504": { "description": "Inspection network timeout.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "default": { "description": "Unexpected error.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        },
        "x-crumb402-payment": { "manifest": "/x402.json", "status": "check_live_quote", "settlementVerified": false, "x402Version": 2, "scheme": "exact", "network": "eip155:56", "token": "USD1", "amount": "0.005" }
      }
    }
  },
  "components": {
    "headers": { "Receipt": { "description": "Base64-encoded x402 v2 settlement response, when returned.", "schema": { "type": "string" } } },
    "schemas": {
      "Inspection": {
        "type": "object",
        "required": ["demo", "url", "finalUrl", "title", "description", "canonical", "openGraph", "jsonLd", "facts", "excerpt", "fingerprint", "changed"],
        "properties": {
          "demo": { "type": "boolean" },
          "url": { "type": "string", "format": "uri" },
          "finalUrl": { "type": "string", "format": "uri" },
          "title": { "type": ["string", "null"] },
          "description": { "type": ["string", "null"] },
          "canonical": { "type": ["string", "null"], "format": "uri" },
          "openGraph": { "type": "object", "additionalProperties": { "type": "array", "items": { "type": "string" } } },
          "jsonLd": { "type": "array", "maxItems": 3, "items": { "type": ["object", "array"] } },
          "facts": { "type": "object", "required": ["product", "event", "job"], "properties": { "product": { "$ref": "#/components/schemas/FactList" }, "event": { "$ref": "#/components/schemas/FactList" }, "job": { "$ref": "#/components/schemas/FactList" } } },
          "excerpt": { "type": "string", "maxLength": 600 },
          "fingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "changed": { "type": ["boolean", "null"], "description": "Null without a prior fingerprint; otherwise true if the hashes differ." }
        }
      },
      "FactList": { "type": "array", "maxItems": 5, "items": { "type": "object" } },
      "Error": { "type": "object", "required": ["error"], "properties": { "error": { "type": "object", "required": ["code", "message"], "properties": { "code": { "type": "string" }, "message": { "type": "string" } } } } }
    }
  }
}
