{
  "openapi": "3.0.3",
  "info": {
    "title": "LVL LTD Agent Skill Market",
    "description": "x402 skill marketplace on Base USDC. Discover skills, receive 402 challenges, unlock sealed packs with verified payments.",
    "version": "1.2.4",
    "contact": { "url": "https://lvlltd.com" }
  },
  "servers": [{ "url": "https://lvlltd.com" }],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Health and endpoint map",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/api/ready": {
      "get": {
        "summary": "Readiness — challenge generation + sealed pack path",
        "responses": {
          "200": { "description": "ready=true" },
          "503": { "description": "Not ready — checks[] explain failure" }
        }
      }
    },
    "/api/shop": {
      "get": {
        "summary": "Unified machine entry — payment contract + purchase sequence + fleet",
        "responses": {
          "200": { "description": "lvl-shop-v1 document with agent_purchase_sequence" }
        }
      }
    },
    "/api/proof": {
      "get": {
        "summary": "Public agent-purchase heartbeat — last confirmed unlock + re-verify recipe",
        "responses": {
          "200": {
            "description": "last_successful_agent_purchase from confirmed ledger (null if none)"
          }
        }
      }
    },
    "/api/revenue": {
      "get": {
        "summary": "Confirmed unlock ledger (verified volume only)",
        "responses": {
          "200": { "description": "confirmed.volume_usdc; recent_unlocks; last_successful_agent_purchase" }
        }
      }
    },
    "/skills/{id}/outline.json": {
      "get": {
        "summary": "Free evaluation outline (no payment)",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "outline JSON with challenge URL" } }
      }
    },
    "/skills/{id}/sample.md": {
      "get": {
        "summary": "Free evaluation sample markdown",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "sample markdown" } }
      }
    },
    "/api/catalog": {
      "get": {
        "summary": "Search/filter skills (slim agent rows)",
        "parameters": [
          { "name": "q", "in": "query", "schema": { "type": "string" } },
          { "name": "tag", "in": "query", "schema": { "type": "string" } },
          { "name": "category", "in": "query", "schema": { "type": "string" } },
          { "name": "tier", "in": "query", "schema": { "type": "string" } },
          { "name": "max_price", "in": "query", "schema": { "type": "number" } },
          { "name": "min_price", "in": "query", "schema": { "type": "number" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0 } }
        ],
        "responses": {
          "200": { "description": "Search results with challenge URLs per skill" }
        }
      }
    },
    "/api/pay": {
      "get": {
        "summary": "x402 payment challenge (HTTP 402)",
        "parameters": [
          {
            "name": "skill",
            "in": "query",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "402": {
            "description": "Payment required — accepts[] includes payTo, maxAmountRequired, assetContract",
            "headers": {
              "PAYMENT-REQUIRED": {
                "schema": { "type": "string" },
                "description": "Base64-encoded challenge JSON"
              }
            }
          }
        }
      },
      "post": {
        "summary": "Unlock or re-redeem sealed pack with payment proof",
        "description": "Send X-PAYMENT header or JSON body with txHash + skill. Re-posting a previously verified txHash re-downloads the pack (redeem).",
        "parameters": [
          {
            "name": "X-PAYMENT",
            "in": "header",
            "schema": { "type": "string" },
            "description": "JSON or base64 JSON: {\"txHash\":\"0x…\",\"skill\":\"id\"}"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "skill": { "type": "string" },
                  "txHash": { "type": "string" },
                  "redeem": { "type": "boolean", "description": "Optional flag; re-POST with same txHash always redeems" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Unlocked — sealed_pack.files map of full pack contents"
          },
          "402": { "description": "Invalid/missing proof or verification failed" }
        }
      }
    },
    "/api/packs": {
      "get": {
        "summary": "Pack metadata (teaser only; contents paywalled)",
        "parameters": [
          { "name": "skill", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Pack list or single pack metadata + challenge" }
        }
      }
    },
    "/api/cart": {
      "get": {
        "summary": "Batch payment challenges for multiple skills",
        "parameters": [
          {
            "name": "skills",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Comma-separated skill ids"
          }
        ],
        "responses": { "200": { "description": "Cart with per-skill challenges and total_usd" } }
      },
      "post": {
        "summary": "Batch cart from JSON body",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "skills": { "type": "array", "items": { "type": "string" } }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Cart with items[]" } }
      }
    },
    "/api/upload": {
      "get": {
        "summary": "Open marketplace service or list listings",
        "parameters": [
          { "name": "list", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Service meta or listings[]" } }
      }
    },
    "/api/orchestrate": {
      "get": {
        "summary": "Capabilities or job status",
        "parameters": [
          { "name": "action", "in": "query", "schema": { "type": "string", "enum": ["capabilities", "status", "plan"] } },
          { "name": "job_id", "in": "query", "schema": { "type": "string" } },
          { "name": "goal", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "OK" } }
      },
      "post": {
        "summary": "Create multi-role plan (not autonomous execution)",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["goal"],
                "properties": {
                  "goal": { "type": "string" },
                  "budget_usd": { "type": "number" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "job with steps + payment_split estimate" } }
      }
    }
  },
  "components": {
    "schemas": {
      "X402Accept": {
        "type": "object",
        "properties": {
          "scheme": { "type": "string", "example": "exact" },
          "network": { "type": "string", "example": "base" },
          "maxAmountRequired": { "type": "string", "description": "USDC atomic units (6 decimals)" },
          "payTo": { "type": "string" },
          "asset": { "type": "string", "example": "USDC" },
          "assetContract": { "type": "string" }
        }
      }
    }
  }
}
