{
  "openapi": "3.1.0",
  "info": {
    "title": "x402 Library",
    "version": "1.4.0",
    "summary": "Machine-purchasable utilities for autonomous agents.",
    "description": "Machine-purchasable market utilities led by a managed-data action-safety product. Results are bounded: no return forecast, investment advice, or order execution."
  },
  "servers": [{ "url": "https://x402library.com" }],
  "externalDocs": { "description": "Budget-bounded autonomous buyer kit", "url": "https://x402library.com/agent-kit.json" },
  "paths": {
    "/v1/market/action-safety/offer": {
      "post": {
        "operationId": "inspectManagedActionSafetyOffer",
        "summary": "Qualify a managed action-safety purchase without payment",
        "description": "Checks input, live-data age, evidence coverage, known limitations, service availability, and buyer price ceiling. It never returns the paid decision.",
        "requestBody": { "required": true, "content": { "application/json": {
          "schema": { "$ref": "#/components/schemas/ManagedActionSafetyInput" },
          "example": { "asset": "BTCUSDT", "intended_action": "ENTER_LONG", "risk_tolerance": "BALANCED", "max_data_age_seconds": 60, "max_price_usdc": 0.02 }
        } } },
        "responses": {
          "200": { "description": "Free pre-purchase offer and suitability result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ManagedActionSafetyOffer" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "413": { "description": "Request exceeds 16 KiB" },
          "503": { "description": "Live data or payment service unavailable" }
        },
        "x-payment": { "required": false, "price": "0.00", "currency": "USDC" },
        "x-result-boundary": { "paid-decision-included": false, "live-data-age-included": true, "known-limitations-included": true }
      }
    },
    "/v1/market/action-safety": {
      "post": {
        "operationId": "runManagedActionSafety",
        "summary": "Obtain a managed-data BTC or ETH action-safety decision",
        "description": "Valid and currently saleable requests return an x402 v2 challenge for 0.01 USDC on Base mainnet. The service attaches the latest Local Sentinel evidence before evaluating the action.",
        "parameters": [{ "name": "PAYMENT-SIGNATURE", "in": "header", "required": false, "description": "x402 v2 signed payment payload. Omit initially to receive payment requirements.", "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": {
          "schema": { "$ref": "#/components/schemas/ManagedActionSafetyInput" },
          "example": { "asset": "BTCUSDT", "intended_action": "ENTER_LONG", "risk_tolerance": "BALANCED", "max_data_age_seconds": 60, "max_price_usdc": 0.02, "intended_notional_usd": 1000 }
        } } },
        "responses": {
          "200": { "description": "Paid bounded action-safety result", "headers": { "PAYMENT-RESPONSE": { "description": "x402 v2 settlement response", "schema": { "type": "string" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ManagedActionSafetyResult" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "402": { "description": "x402 payment required", "headers": { "PAYMENT-REQUIRED": { "required": true, "schema": { "type": "string" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "409": { "description": "Buyer price ceiling is below the current product price" },
          "413": { "description": "Request exceeds 16 KiB" },
          "503": { "description": "Live data is stale or unavailable, or paid access is unavailable" }
        },
        "x-payment": { "protocol": "x402", "version": 2, "price": "0.01", "currency": "USDC", "network": "eip155:8453" },
        "x-managed-data": { "included": true, "source-grade": "SINGLE_VENUE_VERIFIED", "freshness-checked-before-payment": true },
        "x-claim-boundary": { "single-venue": true, "source-truth-independently-verified": false, "forecast": false, "investment-advice": false, "order-execution": false }
      }
    },
    "/v1/market/action-safety/reuse-check": {
      "post": {
        "operationId": "checkManagedActionSafetyResultReuse",
        "summary": "Decide whether a client-retained result should be reused or refreshed",
        "description": "Free TTL-only evaluation of client-supplied managed-result metadata. It does not verify the original payment, receipt, or result-hash existence.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": {
          "type": "object", "additionalProperties": false,
          "required": ["product_id", "policy_id", "result_hash", "valid_until", "refresh_not_before"],
          "properties": {
            "product_id": { "const": "market.action-safety-managed-v1" },
            "policy_id": { "const": "action-safety-managed-policy-v1" },
            "result_hash": { "type": "string", "pattern": "^[0-9a-fA-F]{64}$" },
            "valid_until": { "type": "string", "format": "date-time" },
            "refresh_not_before": { "type": "string", "format": "date-time" }
          }
        } } } },
        "responses": {
          "200": { "description": "REUSE_CURRENT_RESULT, REFRESH_ALLOWED, or REFRESH_REQUIRED TTL decision" },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "413": { "description": "Request exceeds 16 KiB" }
        },
        "x-payment": { "required": false, "price": "0.00", "currency": "USDC" },
        "x-claim-boundary": { "ttl-evaluation-only": true, "original-payment-verified": false, "result-hash-existence-verified": false }
      }
    },
    "/v1/trust/service-summary": {
      "get": {
        "operationId": "getServiceTrustSummary",
        "summary": "Read privacy-minimal aggregate offer and settlement evidence",
        "description": "Returns 24-hour and 7-day aggregate event counts. Canary and unverified settlements are separated and never represented as verified external revenue.",
        "responses": {
          "200": { "description": "Hashed aggregate summary with sample-size and claim boundaries" },
          "503": { "description": "Aggregate ledger is unavailable" }
        },
        "x-payment": { "required": false, "price": "0.00", "currency": "USDC" },
        "x-privacy": { "aggregate-only": true, "payer-addresses": false, "request-ids": false }
      }
    },
    "/v1/health/market-data": {
      "get": {
        "operationId": "getMarketDataHealth",
        "summary": "Check actual market-data freshness and saleability without payment",
        "responses": {
          "200": {
            "description": "Per-asset live health derived from the latest received snapshots",
            "content": { "application/json": { "schema": {
              "type": "object",
              "required": ["status", "checked_at", "saleable", "saleable_assets", "maximum_saleable_age_seconds", "assets"],
              "properties": {
                "status": { "enum": ["LIVE", "DEGRADED", "NODE_OFFLINE", "DATA_UNAVAILABLE"] },
                "checked_at": { "type": "string", "format": "date-time" },
                "saleable": { "type": "boolean" },
                "saleable_assets": { "type": "array", "items": { "enum": ["BTCUSDT", "ETHUSDT"] } },
                "maximum_saleable_age_seconds": { "const": 90 },
                "node_offline_after_seconds": { "const": 300 },
                "assets": { "type": "object", "additionalProperties": { "type": "object", "required": ["status", "age_seconds", "received_at"] } }
              }
            } } }
          },
          "503": { "description": "Snapshot storage binding unavailable" }
        },
        "x-payment": { "required": false, "price": "0.00", "currency": "USDC" }
      }
    },
    "/v1/market/purchase-precheck": {
      "post": {
        "operationId": "runMarketPurchasePrecheck",
        "summary": "Decide whether purchasing market analysis is rational before payment",
        "description": "Free policy and incremental-utility precheck. Caller-supplied probabilities and loss estimates are not verified or guaranteed.",
        "requestBody": {
          "required": true,
          "content": { "application/json": {
            "schema": { "$ref": "#/components/schemas/MarketPurchasePrecheckInput" },
            "example": {
              "schema_version": "1.0.0", "asset": "BTC-USD", "intended_action": "ENTER_LONG", "intended_notional_usd": 2500,
              "horizon_seconds": 300, "seconds_until_deadline": 30, "cached_market_data_age_seconds": null, "cached_event_data_age_seconds": 600,
              "has_funding_crowding_capability": false, "has_execution_preflight_capability": false,
              "estimated_failure_probability_without_analysis": 0.02, "estimated_failure_probability_with_analysis": 0.005,
              "loss_given_failure_fraction": 0.05, "max_autonomous_spend_usdc": 0.05, "max_total_spend_usdc": 0.10
            }
          } }
        },
        "responses": {
          "200": { "description": "Free machine-readable purchasing decision", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MarketPurchasePrecheckResult" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "413": { "description": "Request exceeds 16 KiB" }
        },
        "x-payment": { "required": false, "price": "0.00", "currency": "USDC" },
        "x-claim-boundary": { "caller-supplied-economics": true, "source-truth-verification": false, "loss-reduction-guarantee": false, "investment-advice": false, "order-execution": false }
      }
    },
    "/v1/market/execution-preflight": {
      "post": {
        "operationId": "runCryptoEventAwareExecutionPreflight",
        "summary": "Audit caller-supplied evidence before a crypto market action",
        "description": "Valid unpaid requests return an x402 v2 challenge for 0.01 USDC on Base mainnet. Retry the identical request with PAYMENT-SIGNATURE.",
        "parameters": [{
          "name": "PAYMENT-SIGNATURE",
          "in": "header",
          "required": false,
          "description": "x402 v2 signed payment payload. Omit initially to receive payment requirements.",
          "schema": { "type": "string" }
        }],
        "requestBody": {
          "required": true,
          "content": { "application/json": {
            "schema": { "$ref": "#/components/schemas/PreflightInput" },
            "example": {
              "schema_version": "1.0.0", "asset": "BTC-USD", "observed_at": "2026-08-16T00:00:00Z", "horizon_seconds": 300, "intended_action": "ENTER_LONG",
              "evidence": { "market_data_age_seconds": 10, "event_age_seconds": 20, "independent_sources": 3, "signal_agreement": 0.72, "liquidity_score": 0.85, "spread_bps": 4, "estimated_slippage_bps": 8, "volatility_percentile": 0.7, "position_risk_fraction": 0.01, "invalidation_defined": true, "alternative_explanations": [] }
            }
          } }
        },
        "responses": {
          "200": {
            "description": "Paid structured preflight result",
            "headers": {
              "PAYMENT-RESPONSE": { "description": "x402 v2 settlement response", "schema": { "type": "string" } },
              "X-X402LIBRARY-Payment-Status": { "description": "Payment lifecycle status", "schema": { "type": "string" } }
            },
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PaidPreflightResult" } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "402": {
            "description": "x402 payment required",
            "headers": { "PAYMENT-REQUIRED": { "required": true, "description": "Base64-encoded x402 v2 payment requirements", "schema": { "type": "string" } } },
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
          },
          "413": { "description": "Request exceeds 16 KiB", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "503": { "description": "Paid access or payment configuration unavailable", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        },
        "x-payment": { "protocol": "x402", "version": 2, "price": "0.01", "currency": "USDC", "network": "eip155:8453" },
        "x-result-identity": ["request_hash", "result_hash"],
        "x-claim-boundary": { "caller-supplied-data": true, "source-truth-verification": false, "trade-command": false, "profit-guarantee": false, "order-execution": false }
      }
    },
    "/v1/market/funding-crowding-risk": {
      "post": {
        "operationId": "runFundingCrowdingRiskGate",
        "summary": "Audit derivatives positioning evidence before a crypto position",
        "description": "Valid unpaid requests return an x402 v2 challenge for 0.01 USDC on Base mainnet. This BYOD utility does not source or verify market data and does not forecast liquidations.",
        "parameters": [{ "name": "PAYMENT-SIGNATURE", "in": "header", "required": false, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": { "application/json": {
            "schema": { "$ref": "#/components/schemas/FundingCrowdingInput" },
            "example": {
              "schema_version": "1.0.0", "asset": "BTC-PERP", "observed_at": "2026-08-25T00:00:00Z", "horizon_seconds": 300, "intended_action": "ENTER_LONG",
              "evidence": { "data_age_seconds": 10, "independent_venues": 3, "funding_rate_8h": 0.0008, "funding_percentile": 0.94, "open_interest_change_1h_fraction": 0.12, "open_interest_change_24h_fraction": 0.28, "basis_bps": 38, "long_short_ratio": 2.4, "liquidation_pressure": 0.71, "liquidity_score": 0.82, "spread_bps": 5, "estimated_slippage_bps": 9, "volatility_percentile": 0.84 }
            }
          } }
        },
        "responses": {
          "200": { "description": "Paid structured crowding-risk result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PaidFundingCrowdingResult" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "402": { "description": "x402 payment required", "headers": { "PAYMENT-REQUIRED": { "required": true, "schema": { "type": "string" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "413": { "description": "Request exceeds 16 KiB" },
          "503": { "description": "Paid access or payment configuration unavailable" }
        },
        "x-payment": { "protocol": "x402", "version": 2, "price": "0.01", "currency": "USDC", "network": "eip155:8453" },
        "x-claim-boundary": { "caller-supplied-data": true, "source-truth-verification": false, "liquidation-forecast": false, "trade-command": false, "profit-guarantee": false, "order-execution": false }
      }
    },
    "/v1/market/trade-safety-decision": {
      "post": {
        "operationId": "runTradeSafetyDecision",
        "summary": "Combine execution and crowding evidence into one trade-safety decision",
        "description": "Valid unpaid requests return an x402 v2 challenge for 0.02 USDC on Base mainnet. The service evaluates caller-supplied evidence and does not source data or execute orders.",
        "parameters": [{ "name": "PAYMENT-SIGNATURE", "in": "header", "required": false, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": {
          "schema": { "$ref": "#/components/schemas/TradeSafetyDecisionInput" }
        } } },
        "responses": {
          "200": { "description": "Paid combined trade-safety result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PaidTradeSafetyDecisionResult" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "402": { "description": "x402 payment required", "headers": { "PAYMENT-REQUIRED": { "required": true, "schema": { "type": "string" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "413": { "description": "Request exceeds 16 KiB" },
          "503": { "description": "Paid access or payment configuration unavailable" }
        },
        "x-payment": { "protocol": "x402", "version": 2, "price": "0.02", "currency": "USDC", "network": "eip155:8453" },
        "x-claim-boundary": { "caller-supplied-data": true, "source-truth-verification": false, "investment-advice": false, "trade-command": false, "profit-guarantee": false, "order-execution": false }
      }
    },
    "/v1/market/regime-risk-checkpoint": {
      "post": {
        "operationId": "runRegimeRiskCheckpoint",
        "summary": "Classify caller-supplied evidence against a bounded regime-risk policy",
        "description": "Valid unpaid requests return an x402 v2 challenge for 0.01 USDC on Base mainnet. This utility does not source data or forecast future regimes.",
        "parameters": [{ "name": "PAYMENT-SIGNATURE", "in": "header", "required": false, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": {
          "type": "object", "additionalProperties": false,
          "required": ["schema_version", "asset", "observed_at", "horizon_seconds", "evidence"],
          "properties": {
            "schema_version": { "const": "1.0.0" }, "asset": { "type": "string" }, "observed_at": { "type": "string", "format": "date-time" },
            "horizon_seconds": { "type": "number", "minimum": 30, "maximum": 86400 },
            "evidence": { "type": "object", "required": ["data_age_seconds", "independent_sources", "volatility_percentile", "volatility_change_fraction", "cross_asset_correlation_change", "liquidity_score", "spread_bps", "drawdown_fraction", "trend_strength"] }
          }
        } } } },
        "responses": {
          "200": { "description": "Paid structured regime-risk classification" },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "402": { "description": "x402 payment required", "headers": { "PAYMENT-REQUIRED": { "required": true, "schema": { "type": "string" } } } },
          "413": { "description": "Request exceeds 16 KiB" }, "503": { "description": "Paid access or payment configuration unavailable" }
        },
        "x-payment": { "protocol": "x402", "version": 2, "price": "0.01", "currency": "USDC", "network": "eip155:8453" },
        "x-actions": ["STABLE", "CAUTION", "DEFER", "ABSTAIN"],
        "x-claim-boundary": { "caller-supplied-data": true, "source-truth-verification": false, "regime-forecast": false, "investment-advice": false, "order-execution": false }
      }
    },
    "/v1/data/market-snapshot": {
      "post": {
        "operationId": "getLiveMarketSnapshot",
        "summary": "Purchase a fresh Local Sentinel market snapshot",
        "description": "Freshness is checked before payment. Data older than 90 seconds returns a free 503. Initial snapshots use Binance public data and are explicitly single venue.",
        "parameters": [{ "name": "PAYMENT-SIGNATURE", "in": "header", "required": false, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "required": ["asset"], "properties": { "asset": { "enum": ["BTCUSDT", "ETHUSDT"] } } } } } },
        "responses": {
          "200": { "description": "Paid fresh point-in-time snapshot" },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "402": { "description": "0.003 USDC x402 payment required for a currently fresh snapshot" },
          "503": { "description": "Free DATA_UNAVAILABLE, DATA_STALE, NODE_OFFLINE, or service-disabled response; no payment required" }
        },
        "x-payment": { "protocol": "x402", "version": 2, "price": "0.003", "currency": "USDC", "network": "eip155:8453", "freshness-checked-before-payment": true },
        "x-source-boundary": { "source-grade": "SINGLE_VENUE_VERIFIED", "source": "Binance public API", "independent-sources": 1, "forecast": false, "order-execution": false }
      }
    }
  },
  "components": {
    "responses": {
      "BadRequest": { "description": "Schema rejected before payment", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
    },
    "schemas": {
      "ManagedActionSafetyInput": {
        "type": "object", "additionalProperties": false,
        "required": ["asset", "intended_action", "risk_tolerance"],
        "properties": {
          "schema_version": { "const": "1.0.0", "default": "1.0.0" },
          "asset": { "enum": ["BTCUSDT", "ETHUSDT"] },
          "intended_action": { "enum": ["ENTER_LONG", "ENTER_SHORT", "INCREASE_LONG", "INCREASE_SHORT", "REDUCE_POSITION", "EXIT_POSITION", "OBSERVE_ONLY"] },
          "risk_tolerance": { "enum": ["CONSERVATIVE", "BALANCED", "AGGRESSIVE"] },
          "max_data_age_seconds": { "type": "integer", "minimum": 15, "maximum": 90, "default": 60 },
          "max_price_usdc": { "type": ["number", "null"], "minimum": 0, "maximum": 100 },
          "intended_notional_usd": { "type": ["number", "null"], "exclusiveMinimum": 0, "maximum": 1000000000 }
        }
      },
      "ManagedActionSafetyOffer": {
        "type": "object",
        "required": ["schema_version", "product_id", "policy_id", "purchase_gate", "purchase_allowed", "payment_required_for_result", "reason_codes", "price", "request", "data_status", "expected_result_actions", "valid_until", "buy_when", "do_not_buy_when", "next"],
        "properties": {
          "schema_version": { "const": "1.0.0" }, "product_id": { "const": "market.action-safety-managed-v1" }, "policy_id": { "const": "action-safety-managed-policy-v1" },
          "purchase_gate": { "enum": ["PURCHASE_READY", "WARN", "NOT_SUITABLE", "DATA_STALE", "OVER_BUDGET", "SERVICE_UNAVAILABLE"] },
          "purchase_allowed": { "type": "boolean" }, "payment_required_for_result": { "const": true }, "reason_codes": { "type": "array", "items": { "type": "string" } },
          "price": { "type": "object" }, "request": { "type": "object" },
          "data_status": { "type": "object", "required": ["availability", "age_seconds", "source_grade", "evidence_coverage", "known_limitations"] },
          "expected_result_actions": { "type": "array", "items": { "enum": ["ALLOW_TRADE", "REDUCE_TRADE", "DEFER_TRADE", "BLOCK_TRADE", "ABSTAIN"] } },
          "valid_until": { "type": ["string", "null"], "format": "date-time" }, "buy_when": { "type": "array", "items": { "type": "string" } }, "do_not_buy_when": { "type": "array", "items": { "type": "string" } },
          "next": { "type": "object", "properties": { "method": { "const": "POST" }, "endpoint": { "const": "/v1/market/action-safety" } } }
        }
      },
      "ManagedActionSafetyResult": {
        "type": "object",
        "required": ["schema_version", "product_id", "policy_id", "decision", "recommended_size_multiplier", "reason_codes", "gates", "thresholds", "evidence", "evaluated_at", "served_at", "valid_until", "refresh_not_before", "claim_boundary", "request_hash", "result_hash", "payment_receipt"],
        "properties": {
          "schema_version": { "const": "1.0.0" }, "product_id": { "const": "market.action-safety-managed-v1" }, "policy_id": { "const": "action-safety-managed-policy-v1" },
          "decision": { "enum": ["ALLOW_TRADE", "REDUCE_TRADE", "DEFER_TRADE", "BLOCK_TRADE", "ABSTAIN"] }, "recommended_size_multiplier": { "type": "number", "minimum": 0, "maximum": 1 },
          "maximum_recommended_notional_usd": { "type": ["number", "null"] }, "reason_codes": { "type": "array", "items": { "type": "string" } },
          "gates": { "type": "object" }, "thresholds": { "type": "object" }, "evidence": { "type": "object" },
          "evaluated_at": { "type": "string", "format": "date-time" }, "served_at": { "type": "string", "format": "date-time" }, "valid_until": { "type": "string", "format": "date-time" }, "refresh_not_before": { "type": "string", "format": "date-time" },
          "claim_boundary": { "type": "object" }, "request_hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" }, "result_hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" }, "payment_receipt": { "type": "object" }
        }
      },
      "MarketPurchasePrecheckInput": {
        "type": "object", "additionalProperties": false,
        "required": ["schema_version", "asset", "intended_action", "intended_notional_usd", "horizon_seconds", "seconds_until_deadline", "cached_market_data_age_seconds", "cached_event_data_age_seconds", "has_funding_crowding_capability", "has_execution_preflight_capability", "estimated_failure_probability_without_analysis", "estimated_failure_probability_with_analysis", "loss_given_failure_fraction", "max_autonomous_spend_usdc", "max_total_spend_usdc"],
        "properties": {
          "schema_version": { "const": "1.0.0" }, "asset": { "type": "string", "pattern": "^[A-Za-z0-9._:/-]{2,40}$" }, "intended_action": { "enum": ["ENTER_LONG", "ENTER_SHORT"] },
          "intended_notional_usd": { "type": "number", "minimum": 0, "maximum": 1000000000 }, "horizon_seconds": { "type": "number", "minimum": 30, "maximum": 86400 }, "seconds_until_deadline": { "type": "number", "minimum": 0, "maximum": 604800 },
          "cached_market_data_age_seconds": { "type": ["number", "null"], "minimum": 0, "maximum": 604800 }, "cached_event_data_age_seconds": { "type": ["number", "null"], "minimum": 0, "maximum": 604800 },
          "has_funding_crowding_capability": { "type": "boolean" }, "has_execution_preflight_capability": { "type": "boolean" },
          "estimated_failure_probability_without_analysis": { "type": "number", "minimum": 0, "maximum": 1 }, "estimated_failure_probability_with_analysis": { "type": "number", "minimum": 0, "maximum": 1 },
          "loss_given_failure_fraction": { "type": "number", "minimum": 0, "maximum": 1 }, "max_autonomous_spend_usdc": { "type": "number", "minimum": 0, "maximum": 1000 }, "max_total_spend_usdc": { "type": "number", "minimum": 0, "maximum": 1000 }
        }
      },
      "MarketPurchasePrecheckResult": {
        "type": "object",
        "required": ["schema_version", "product", "payment_required", "decision", "reason_codes", "detected_gaps", "recommended_capabilities", "economics", "policy", "buy_when", "do_not_buy_when", "claim_boundary", "evaluated_at", "valid_until"],
        "properties": {
          "schema_version": { "const": "1.0.0" }, "product": { "const": "market.purchase-precheck-v1" }, "payment_required": { "const": false },
          "decision": { "enum": ["BUY_ANALYSIS", "SKIP_ANALYSIS", "REQUIRE_APPROVAL"] }, "reason_codes": { "type": "array", "items": { "type": "string" } },
          "detected_gaps": { "type": "array", "items": { "type": "object" } }, "recommended_capabilities": { "type": "array", "items": { "type": "object" } },
          "economics": { "type": "object" }, "policy": { "type": "object" }, "buy_when": { "type": "array", "items": { "type": "string" } }, "do_not_buy_when": { "type": "array", "items": { "type": "string" } },
          "claim_boundary": { "type": "object" }, "evaluated_at": { "type": "string", "format": "date-time" }, "valid_until": { "type": "string", "format": "date-time" }
        }
      },
      "PreflightInput": {
        "type": "object",
        "additionalProperties": false,
        "required": ["schema_version", "asset", "observed_at", "horizon_seconds", "intended_action", "evidence"],
        "properties": {
          "schema_version": { "const": "1.0.0" },
          "asset": { "type": "string", "pattern": "^[A-Za-z0-9._:/-]{2,40}$" },
          "observed_at": { "type": "string", "format": "date-time" },
          "horizon_seconds": { "type": "number", "minimum": 30, "maximum": 86400 },
          "intended_action": { "enum": ["ENTER_LONG", "ENTER_SHORT"] },
          "evidence": { "$ref": "#/components/schemas/MarketEvidence" }
        }
      },
      "MarketEvidence": {
        "type": "object",
        "required": ["market_data_age_seconds", "event_age_seconds", "independent_sources", "signal_agreement", "liquidity_score", "spread_bps", "estimated_slippage_bps", "volatility_percentile", "position_risk_fraction", "invalidation_defined"],
        "properties": {
          "market_data_age_seconds": { "type": "number", "minimum": 0, "maximum": 86400 },
          "event_age_seconds": { "type": "number", "minimum": 0, "maximum": 604800 },
          "independent_sources": { "type": "integer", "minimum": 0, "maximum": 20 },
          "signal_agreement": { "type": "number", "minimum": -1, "maximum": 1 },
          "liquidity_score": { "type": "number", "minimum": 0, "maximum": 1 },
          "spread_bps": { "type": "number", "minimum": 0, "maximum": 10000 },
          "estimated_slippage_bps": { "type": "number", "minimum": 0, "maximum": 10000 },
          "volatility_percentile": { "type": "number", "minimum": 0, "maximum": 1 },
          "position_risk_fraction": { "type": "number", "minimum": 0, "maximum": 1 },
          "invalidation_defined": { "type": "boolean" },
          "alternative_explanations": { "type": "array", "maxItems": 10, "items": { "type": "string", "maxLength": 240 } }
        }
      },
      "FundingCrowdingInput": {
        "type": "object",
        "additionalProperties": false,
        "required": ["schema_version", "asset", "observed_at", "horizon_seconds", "intended_action", "evidence"],
        "properties": {
          "schema_version": { "const": "1.0.0" }, "asset": { "type": "string", "pattern": "^[A-Za-z0-9._:/-]{2,40}$" },
          "observed_at": { "type": "string", "format": "date-time" }, "horizon_seconds": { "type": "number", "minimum": 30, "maximum": 86400 },
          "intended_action": { "enum": ["ENTER_LONG", "ENTER_SHORT"] },
          "evidence": {
            "type": "object",
            "required": ["data_age_seconds", "independent_venues", "funding_rate_8h", "funding_percentile", "open_interest_change_1h_fraction", "open_interest_change_24h_fraction", "basis_bps", "long_short_ratio", "liquidation_pressure", "liquidity_score", "spread_bps", "estimated_slippage_bps", "volatility_percentile"],
            "properties": {
              "data_age_seconds": { "type": "number", "minimum": 0, "maximum": 86400 }, "independent_venues": { "type": "integer", "minimum": 0, "maximum": 20 },
              "funding_rate_8h": { "type": "number", "minimum": -1, "maximum": 1 }, "funding_percentile": { "type": "number", "minimum": 0, "maximum": 1 },
              "open_interest_change_1h_fraction": { "type": "number", "minimum": -1, "maximum": 5 }, "open_interest_change_24h_fraction": { "type": "number", "minimum": -1, "maximum": 10 },
              "basis_bps": { "type": "number", "minimum": -10000, "maximum": 10000 }, "long_short_ratio": { "type": "number", "minimum": 0, "maximum": 100 },
              "liquidation_pressure": { "type": "number", "minimum": -1, "maximum": 1 }, "liquidity_score": { "type": "number", "minimum": 0, "maximum": 1 },
              "spread_bps": { "type": "number", "minimum": 0, "maximum": 10000 }, "estimated_slippage_bps": { "type": "number", "minimum": 0, "maximum": 10000 },
              "volatility_percentile": { "type": "number", "minimum": 0, "maximum": 1 }
            }
          }
        }
      },
      "TradeSafetyDecisionInput": {
        "type": "object", "additionalProperties": false,
        "required": ["schema_version", "asset", "observed_at", "horizon_seconds", "intended_action", "intended_notional_usd", "risk_tolerance", "execution_evidence", "crowding_evidence"],
        "properties": {
          "schema_version": { "const": "1.0.0" }, "asset": { "type": "string", "pattern": "^[A-Za-z0-9._:/-]{2,40}$" },
          "observed_at": { "type": "string", "format": "date-time" }, "horizon_seconds": { "type": "number", "minimum": 30, "maximum": 86400 },
          "intended_action": { "enum": ["ENTER_LONG", "ENTER_SHORT"] }, "intended_notional_usd": { "type": "number", "exclusiveMinimum": 0, "maximum": 1000000000 },
          "risk_tolerance": { "enum": ["LOW", "MEDIUM", "HIGH"] },
          "execution_evidence": { "$ref": "#/components/schemas/MarketEvidence" },
          "crowding_evidence": { "$ref": "#/components/schemas/FundingCrowdingInput/properties/evidence" }
        }
      },
      "PaidTradeSafetyDecisionResult": {
        "type": "object", "additionalProperties": true,
        "required": ["schema_version", "product", "action", "reason_codes", "recommended_size_multiplier", "maximum_recommended_notional_usd", "component_decisions", "request_hash", "result_hash", "payment_receipt"],
        "properties": {
          "schema_version": { "const": "1.0.0" }, "product": { "const": "market.trade-safety-decision-v1" },
          "action": { "enum": ["ALLOW_TRADE", "REDUCE_TRADE", "DEFER_TRADE", "BLOCK_TRADE"] },
          "reason_codes": { "type": "array", "items": { "type": "string" } }, "recommended_size_multiplier": { "type": "number", "minimum": 0, "maximum": 1 },
          "maximum_recommended_notional_usd": { "type": "number", "minimum": 0 }, "component_decisions": { "type": "object" },
          "request_hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" }, "result_hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "payment_receipt": { "$ref": "#/components/schemas/PaymentReceipt" }
        }
      },
      "PreflightResult": {
        "type": "object",
        "required": ["schema_version", "product", "action", "reason_codes", "asset", "intended_action", "evaluated_at", "valid_until", "evidence_summary", "claim_boundary", "request_hash", "result_hash"],
        "properties": {
          "schema_version": { "const": "1.0.0" },
          "product": { "const": "market.crypto-event-aware-execution-preflight-v1" },
          "action": { "enum": ["CONTINUE", "WAIT", "REDUCE", "ABSTAIN", "ESCALATE"] },
          "reason_codes": { "type": "array", "items": { "type": "string" } },
          "asset": { "type": "string" },
          "intended_action": { "enum": ["ENTER_LONG", "ENTER_SHORT"] },
          "evaluated_at": { "type": "string", "format": "date-time" },
          "valid_until": { "type": "string", "format": "date-time" },
          "evidence_summary": { "type": "object" },
          "claim_boundary": { "type": "object" },
          "request_hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "result_hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
        }
      },
      "PaymentReceipt": {
        "type": "object",
        "required": ["protocol", "status", "persistence"],
        "properties": { "protocol": { "const": "x402" }, "status": { "type": "string" }, "payment_id": { "type": ["string", "null"] }, "settlement": {}, "persistence": { "const": "client_retained" } }
      },
      "PaidFundingCrowdingResult": {
        "type": "object",
        "required": ["schema_version", "product", "action", "crowding_state", "crowding_score", "reason_codes", "asset", "intended_action", "evaluated_at", "valid_until", "evidence_summary", "claim_boundary", "request_hash", "result_hash", "payment_receipt"],
        "properties": {
          "schema_version": { "const": "1.0.0" }, "product": { "const": "market.funding-crowding-risk-gate-v1" },
          "action": { "enum": ["CONTINUE", "WAIT", "REDUCE", "ABSTAIN", "ESCALATE"] },
          "crowding_state": { "enum": ["BALANCED", "LONG_CROWDED", "SHORT_CROWDED", "MIXED", "UNDETERMINED"] },
          "crowding_score": { "type": "integer", "minimum": 0, "maximum": 5 }, "reason_codes": { "type": "array", "items": { "type": "string" } },
          "asset": { "type": "string" }, "intended_action": { "enum": ["ENTER_LONG", "ENTER_SHORT"] },
          "evaluated_at": { "type": "string", "format": "date-time" }, "valid_until": { "type": "string", "format": "date-time" },
          "evidence_summary": { "type": "object" }, "claim_boundary": { "type": "object" },
          "request_hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" }, "result_hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "payment_receipt": { "$ref": "#/components/schemas/PaymentReceipt" }
        }
      },
      "PaidPreflightResult": { "allOf": [{ "$ref": "#/components/schemas/PreflightResult" }, { "type": "object", "required": ["payment_receipt"], "properties": { "payment_receipt": { "$ref": "#/components/schemas/PaymentReceipt" } } }] },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": { "error": { "type": "object", "required": ["code", "message"], "properties": { "code": { "type": "string" }, "message": { "type": "string" }, "issues": { "type": "array", "items": { "type": "string" } } } } }
      }
    }
  },
  "x-library-status": "production_paid_utility_live"
}
