{
  "openapi": "3.1.0",
  "info": {
    "title": "Anyway Possible Agent Web Evidence API",
    "version": "3.0.0",
    "description": "Market-priced URL preflight, batch validation, and timestamped web evidence for autonomous agents, paid with x402 on Base."
  },
  "servers": [{ "url": "https://anywaypossible.com" }],
  "paths": {
    "/api/check": {
      "get": {
        "summary": "Read $0.001 check metadata",
        "responses": { "200": { "description": "Service metadata" } }
      },
      "post": {
        "operationId": "checkUrl",
        "summary": "Preflight a public URL for $0.001 USDC",
        "description": "Returns an HTTP 402 x402 challenge when unpaid, then checks reachability, status, latency, redirects, and content type.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CheckRequest" } } }
        },
        "responses": {
          "200": { "description": "Paid preflight result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CheckResult" } } } },
          "400": { "description": "Invalid request or unsupported URL" },
          "402": { "description": "x402 payment required" },
          "502": { "description": "The target could not be checked" }
        }
      }
    },
    "/api/batch": {
      "get": {
        "summary": "Read batch check metadata",
        "responses": { "200": { "description": "Service metadata" } }
      },
      "post": {
        "operationId": "batchCheckUrls",
        "summary": "Check up to 10 public URLs for $0.01 USDC",
        "description": "Checks citations, links, or API dependencies in one x402 payment and isolates partial failures per result.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BatchRequest" } } }
        },
        "responses": {
          "200": { "description": "Paid batch result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BatchResult" } } } },
          "400": { "description": "Invalid request" },
          "402": { "description": "x402 payment required" }
        }
      }
    },
    "/api/verify": {
      "get": {
        "summary": "Read service and payment metadata",
        "responses": {
          "200": {
            "description": "Service metadata",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      },
      "post": {
        "operationId": "verifyUrl",
        "summary": "Verify a public URL",
        "description": "Returns an HTTP 402 x402 challenge when unpaid. After a valid $0.01 USDC payment on Base, fetches the URL and returns timestamped verification evidence.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/VerificationRequest" },
              "examples": {
                "basic": {
                  "value": {
                    "url": "https://example.com",
                    "expectedStatus": 200,
                    "expectedText": "Example Domain"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Paid verification result",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/VerificationResult" }
              }
            }
          },
          "400": { "description": "Invalid request or unsupported URL" },
          "402": {
            "description": "x402 payment required; follow the returned payment requirements and repeat the request with a payment signature"
          },
          "502": { "description": "The target could not be verified" },
          "503": { "description": "Payment service temporarily unavailable" }
        }
      }
    },
    "/api/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Check service health",
        "responses": { "200": { "description": "Service is operational" } }
      }
    },
    "/api/stats": {
      "get": {
        "operationId": "getAggregateStats",
        "summary": "Read aggregate service usage and revenue",
        "responses": { "200": { "description": "Aggregate public metrics" } }
      }
    }
  },
  "components": {
    "schemas": {
      "VerificationRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["url"],
        "properties": {
          "url": { "type": "string", "format": "uri", "description": "Public HTTP(S) URL to verify" },
          "expectedStatus": { "type": "integer", "minimum": 100, "maximum": 599 },
          "expectedText": { "type": "string", "maxLength": 500 }
        }
      },
      "CheckRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["url"],
        "properties": {
          "url": { "type": "string", "format": "uri", "description": "Public HTTP(S) URL to check" },
          "expectedStatus": { "type": "integer", "minimum": 100, "maximum": 599 }
        }
      },
      "CheckResult": {
        "type": "object",
        "required": ["reachable", "verified", "status", "finalUrl", "responseTimeMs", "observedAt"],
        "properties": {
          "reachable": { "type": "boolean" },
          "verified": { "type": "boolean" },
          "status": { "type": "integer" },
          "finalUrl": { "type": "string", "format": "uri" },
          "redirectChain": { "type": "array", "items": { "type": "string", "format": "uri" } },
          "responseTimeMs": { "type": "integer" },
          "contentType": { "type": "string" },
          "observedAt": { "type": "string", "format": "date-time" }
        }
      },
      "BatchRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["urls"],
        "properties": {
          "urls": { "type": "array", "minItems": 1, "maxItems": 10, "items": { "type": "string", "format": "uri" } },
          "expectedStatus": { "type": "integer", "minimum": 100, "maximum": 599 }
        }
      },
      "BatchResult": {
        "type": "object",
        "required": ["verified", "count", "checkedAt", "results"],
        "properties": {
          "verified": { "type": "boolean" },
          "count": { "type": "integer" },
          "checkedAt": { "type": "string", "format": "date-time" },
          "results": { "type": "array", "items": { "type": "object" } }
        }
      },
      "VerificationResult": {
        "type": "object",
        "required": ["verified", "status", "finalUrl", "contentSha256", "receiptId", "observedAt"],
        "properties": {
          "verified": { "type": "boolean" },
          "status": { "type": "integer" },
          "title": { "type": ["string", "null"] },
          "finalUrl": { "type": "string", "format": "uri" },
          "contentSha256": { "type": "string", "description": "SHA-256 digest of the inspected response bytes" },
          "receiptId": { "type": "string", "description": "Deterministic digest binding URL, status, content digest, and observation time" },
          "redirectChain": { "type": "array", "items": { "type": "string", "format": "uri" } },
          "responseTimeMs": { "type": "integer" },
          "observedAt": { "type": "string", "format": "date-time" }
        }
      }
    }
  }
}
