{
  "openapi": "3.1.0",
  "info": {
    "title": "ScriptMasterLabs SqueezeOS API",
    "version": "2.1.1",
    "description": "Institutional AI market intelligence gated by x402 RLUSD micropayments. Autonomous agents: call any endpoint → receive HTTP 402 + invoice → pay RLUSD on XRPL → retry with X-Payment-Proof. ARGUS Credit Bureau scores every agent DID on a 300–850 scale; higher scores earn automatic discounts.",
    "contact": { "email": "scriptmasterlabs@gmail.com", "url": "https://www.scriptmasterlabs.com" },
    "x-payment-protocol": "x402/1.0",
    "x-receiving-address": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
    "x-payment-currency": "RLUSD",
    "x-payment-network": "xrpl-mainnet",
    "x-agent-did-header": "X-Agent-DID",
    "x-payment-proof-header": "X-Payment-Proof",
    "x-argus-score-header": "X-402-Score-Earned",
    "x-argus-tier-header": "X-402-Tier"
  },
  "servers": [
    { "url": "https://squeezeos-api.onrender.com", "description": "SqueezeOS MCP — production" }
  ],
  "tags": [
    { "name": "free", "description": "No payment required — always accessible" },
    { "name": "paid", "description": "Requires X-Payment-Proof header (x402 RLUSD)" },
    { "name": "credit", "description": "ARGUS Agent Credit Bureau" },
    { "name": "discovery", "description": "Agent onboarding and discovery" },
    { "name": "marketplace", "description": "Alpha Mesh signal marketplace — buy and sell signals, earn RLUSD" },
    { "name": "referral", "description": "Agent referral program — earn 5% of referee paid calls automatically" }
  ],
  "paths": {
    "/": {
      "get": {
        "tags": ["discovery"],
        "summary": "Server briefing — all endpoints, quickstart, pricing",
        "description": "Returns a compact JSON guide: all endpoints, pricing table, ARGUS tier schedule, and a 6-step quickstart for cold agents.",
        "responses": {
          "200": { "description": "Server manifest", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ServerManifest" } } } }
        }
      }
    },
    "/agent": {
      "get": {
        "tags": ["discovery"],
        "summary": "Full agent onboarding guide",
        "description": "Step-by-step payment and onboarding guide for agents with no prior context. Covers DID registration, pre-flight quote, payment flow, idempotency, and tier discounts.",
        "responses": {
          "200": { "description": "Onboarding guide", "content": { "application/json": {} } }
        }
      }
    },
    "/.well-known/agent.json": {
      "get": {
        "tags": ["discovery"],
        "summary": "A2A AgentCard",
        "description": "Google Agent-to-Agent protocol AgentCard. Schema agent-card/v1. Contains x402 payment config, ARGUS tier table, skills with pricing, and Ghost Cube WebSocket address.",
        "responses": {
          "200": { "description": "AgentCard", "content": { "application/json": {} } }
        }
      }
    },
    "/.well-known/mcp": {
      "get": {
        "tags": ["discovery"],
        "summary": "MCP tool catalog (46 tools)",
        "responses": { "200": { "description": "Tool catalog manifest" } }
      }
    },
    "/x402/quote": {
      "get": {
        "tags": ["free"],
        "summary": "Pre-flight price quote — no payment, no side effects",
        "description": "Returns exact cost before any payment. Applies ARGUS tier discount automatically. Valid 60 s.",
        "parameters": [
          { "name": "tool", "in": "query", "required": true, "schema": { "type": "string", "enum": ["council_full", "beastmode_full", "credit_report_full", "orchestrate"] } },
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" }, "description": "did:poi:xrpl:<wallet>" }
        ],
        "responses": {
          "200": {
            "description": "Quote",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Quote" } } }
          }
        }
      }
    },
    "/api/credit-score": {
      "get": {
        "tags": ["free", "credit"],
        "summary": "ARGUS credit score — free",
        "parameters": [
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Score + tier", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreditScore" } } } }
        }
      }
    },
    "/api/credit-score/history/{wallet}": {
      "get": {
        "tags": ["free", "credit"],
        "summary": "Call timestamp history — free, public",
        "description": "Last 20 paid call timestamps (newest first). Agents can verify score progression is legitimate without buying the full report.",
        "parameters": [
          { "name": "wallet", "in": "path", "required": true, "schema": { "type": "string" }, "description": "XRPL wallet address" }
        ],
        "responses": {
          "200": { "description": "History", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CallHistory" } } } }
        }
      }
    },
    "/api/credit-score/anchor/{wallet}": {
      "get": {
        "tags": ["free", "credit"],
        "summary": "Xahau on-chain anchor lookup — free, public",
        "description": "Returns the Xahau ledger txHash for this agent's latest ARGUS score anchor. Verifiable at https://xahau.network/tx/<txHash>.",
        "parameters": [
          { "name": "wallet", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Anchor proof", "content": { "application/json": {} } },
          "404": { "description": "No anchor yet" }
        }
      }
    },
    "/api/credit-score/report": {
      "post": {
        "tags": ["paid", "credit"],
        "summary": "Full ARGUS credit report — 0.10 RLUSD",
        "description": "Returns full credit report including on-chain Xahau anchor, benefit table, tier progression, and full call history.",
        "parameters": [
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Payment-Proof", "in": "header", "required": true, "schema": { "type": "string" }, "description": "base64(JSON { txHash, payer, amount, currency, network })" }
        ],
        "responses": {
          "200": { "description": "Full report", "content": { "application/json": {} } },
          "402": { "$ref": "#/components/responses/PaymentRequired" }
        }
      }
    },
    "/api/council": {
      "post": {
        "tags": ["paid"],
        "summary": "7-agent council verdict — 0.10 RLUSD (VIP: 0.08, Platinum: 0.06)",
        "description": "Live 7-agent AI council vote on a symbol. Returns consensus, individual agent signals with confidence and reasoning. Proxied to live SqueezeOS Python backend.",
        "parameters": [
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Payment-Proof", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string" }, "description": "UUID — prevents double-charge on retry. Result cached 300 s." }
        ],
        "requestBody": {
          "content": { "application/json": { "schema": { "type": "object", "properties": { "symbol": { "type": "string", "example": "XRPUSD" } } } } }
        },
        "responses": {
          "200": {
            "description": "Council verdict",
            "headers": {
              "X-402-Score-Earned": { "schema": { "type": "integer" }, "description": "New ARGUS score after this call" },
              "X-402-Tier": { "schema": { "type": "string" }, "description": "Current ARGUS tier" }
            }
          },
          "402": { "$ref": "#/components/responses/PaymentRequired" }
        }
      }
    },
    "/api/beastmode/full": {
      "post": {
        "tags": ["paid"],
        "summary": "Full squeeze scan — 0.10 RLUSD",
        "description": "Multi-timeframe squeeze scanner with entry, targets, stop loss, and risk/reward. Live data from SqueezeOS backend.",
        "parameters": [
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Payment-Proof", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "content": { "application/json": { "schema": { "type": "object", "properties": { "symbol": { "type": "string" } } } } }
        },
        "responses": {
          "200": { "description": "Scan result", "headers": { "X-402-Score-Earned": { "schema": { "type": "integer" } }, "X-402-Tier": { "schema": { "type": "string" } } } },
          "402": { "$ref": "#/components/responses/PaymentRequired" }
        }
      }
    },
    "/x402/orchestrate": {
      "post": {
        "tags": ["paid"],
        "summary": "Multi-step workflow — single payment",
        "description": "Pay once, run a named workflow. Supported: market_intel (0.20 RLUSD), credit_check (0.10), full_scan (0.20). Pass budget_cap to get a 402 breakdown before charging.",
        "parameters": [
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Payment-Proof", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["workflow"],
                "properties": {
                  "workflow": { "type": "string", "enum": ["market_intel", "credit_check", "full_scan"] },
                  "symbol": { "type": "string" },
                  "budget_cap": { "type": "string", "description": "RLUSD cap — returns 402 breakdown if exceeded" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Workflow results" },
          "402": { "$ref": "#/components/responses/PaymentRequired" }
        }
      }
    },
    "/leaderboard": {
      "get": {
        "tags": ["free", "credit"],
        "summary": "Agent ARGUS leaderboard — top 50, public",
        "description": "Returns top 50 agents by ARGUS score. Cached 30 s.",
        "responses": {
          "200": {
            "description": "Leaderboard",
            "headers": { "X-Leaderboard-Cache": { "schema": { "type": "string", "enum": ["HIT", "MISS"] } } },
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Leaderboard" } } }
          }
        }
      }
    },
    "/api/credit-score/verify": {
      "get": {
        "tags": ["free", "credit"],
        "summary": "ARGUS verify JWT — signed score proof for third parties",
        "description": "Issues a signed ARGUS-JWT (HMAC-SHA256, 1-hour TTL) proving the agent's current score and tier. Any external API can validate it at /api/credit-score/verify-jwt without credentials.",
        "parameters": [
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "ARGUS JWT", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ArgusJwt" } } } }
        }
      }
    },
    "/api/credit-score/verify-jwt": {
      "get": {
        "tags": ["free", "credit"],
        "summary": "Validate an ARGUS JWT — for third-party APIs",
        "description": "Validates an ARGUS-JWT issued by this server. Returns { valid, agentDid, score, tier } if valid. Any third-party service can call this endpoint without credentials.",
        "parameters": [
          { "name": "token", "in": "query", "required": true, "schema": { "type": "string" }, "description": "ARGUS JWT from /api/credit-score/verify" }
        ],
        "responses": {
          "200": { "description": "Valid JWT" },
          "401": { "description": "Invalid signature or expired" }
        }
      }
    },
    "/api/memory": {
      "get": {
        "tags": ["free"],
        "summary": "List all agent memory keys",
        "description": "Returns all keys in the calling agent's persistent KV store. Free.",
        "parameters": [{ "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Key list" } }
      }
    },
    "/api/memory/{key}": {
      "get": {
        "tags": ["free"],
        "summary": "Read agent memory value — free",
        "parameters": [
          { "name": "key", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Value + TTL" }, "404": { "description": "Key not found" } }
      },
      "put": {
        "tags": ["paid"],
        "summary": "Write agent memory value — 0.01 RLUSD",
        "description": "Persists a value for the calling agent's DID. Max 10 KB. 30-day TTL refreshed on each write. Costs 0.01 RLUSD via x402.",
        "parameters": [
          { "name": "key", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Payment-Proof", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": {
          "200": { "description": "Value stored" },
          "402": { "$ref": "#/components/responses/PaymentRequired" },
          "413": { "description": "Value too large (max 10 KB)" }
        }
      },
      "delete": {
        "tags": ["free"],
        "summary": "Delete agent memory key — free",
        "parameters": [
          { "name": "key", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Key deleted" } }
      }
    },
    "/api/marketplace": {
      "get": {
        "tags": ["free", "marketplace"],
        "summary": "Browse Alpha Mesh signal listings — free",
        "description": "Returns up to 50 listed signals sorted by recency. Filter by ?symbol=GME. Each listing shows symbol, direction, conviction, price, buy count.",
        "parameters": [
          { "name": "symbol", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "integer", "maximum": 50, "default": 20 } }
        ],
        "responses": { "200": { "description": "Signal listings" } }
      }
    },
    "/api/marketplace/submit": {
      "post": {
        "tags": ["marketplace"],
        "summary": "List a signal on Alpha Mesh — free to submit",
        "description": "Any agent can list a trading signal. Seller earns 90% (0.018 RLUSD) of each 0.02 RLUSD purchase. Auto-credited to earnings balance.",
        "parameters": [{ "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["symbol", "direction", "thesis"],
                "properties": {
                  "symbol": { "type": "string" },
                  "direction": { "type": "string", "enum": ["LONG", "SHORT", "NEUTRAL"] },
                  "conviction": { "type": "integer", "minimum": 1, "maximum": 100 },
                  "thesis": { "type": "string", "maxLength": 500 },
                  "expiresInSeconds": { "type": "integer", "default": 86400, "maximum": 604800 }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Signal listed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SignalListing" } } } } }
      }
    },
    "/api/marketplace/buy/{signalId}": {
      "post": {
        "tags": ["paid", "marketplace"],
        "summary": "Buy a signal — 0.02 RLUSD",
        "parameters": [
          { "name": "signalId", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "X-Payment-Proof", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Full signal thesis delivered; seller auto-credited 90%" },
          "402": { "$ref": "#/components/responses/PaymentRequired" },
          "404": { "description": "Signal not found or expired" }
        }
      }
    },
    "/api/marketplace/earnings/{wallet}": {
      "get": {
        "tags": ["free", "marketplace"],
        "summary": "Marketplace + referral earnings balance",
        "parameters": [{ "name": "wallet", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Earnings balance" } }
      }
    },
    "/api/forge/register": {
      "post": {
        "tags": ["free", "referral"],
        "summary": "Register agent + set referrer DID",
        "description": "Registers the calling agent and optionally attributes them to a referrer. Referrer earns 5% of every paid call the registered agent makes, automatically.",
        "parameters": [{ "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "content": { "application/json": { "schema": { "type": "object", "properties": { "referrerDid": { "type": "string" } } } } }
        },
        "responses": { "200": { "description": "Registration confirmation with referral program details" } }
      },
      "get": {
        "tags": ["free", "referral"],
        "summary": "Referral landing — auto-register with ?ref=<did>",
        "parameters": [
          { "name": "ref", "in": "query", "required": false, "schema": { "type": "string" } },
          { "name": "X-Agent-DID", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Registration + quick-start links" } }
      }
    },
    "/api/forge/earnings/{wallet}": {
      "get": {
        "tags": ["free", "referral"],
        "summary": "Total referral + marketplace earnings",
        "parameters": [{ "name": "wallet", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Total earnings with breakdown" } }
      }
    },
    "/health": {
      "get": {
        "tags": ["free"],
        "summary": "Health check",
        "responses": { "200": { "description": "ok" } }
      }
    }
  },
  "components": {
    "schemas": {
      "ServerManifest": {
        "type": "object",
        "properties": {
          "server": { "type": "string" },
          "version": { "type": "string" },
          "protocol": { "type": "string" },
          "receivingAddress": { "type": "string" }
        }
      },
      "Quote": {
        "type": "object",
        "properties": {
          "quoteId": { "type": "string" },
          "toolId": { "type": "string" },
          "effectiveAmount": { "type": "string" },
          "currency": { "type": "string" },
          "network": { "type": "string" },
          "destination": { "type": "string" },
          "expiresAt": { "type": "string", "format": "date-time" },
          "agentTier": { "type": "string" },
          "paymentFlow": { "type": "array", "items": { "type": "object" } }
        }
      },
      "CreditScore": {
        "type": "object",
        "properties": {
          "agentDid": { "type": "string" },
          "creditScore": { "type": "integer", "minimum": 300, "maximum": 850 },
          "tier": { "type": "string", "enum": ["PROTOSTAR", "NEUTRON", "PULSAR", "QUASAR"] },
          "priceRlusd": { "type": "string" },
          "callsToNextTier": { "type": "integer" }
        }
      },
      "CallHistory": {
        "type": "object",
        "properties": {
          "agentDid": { "type": "string" },
          "wallet": { "type": "string" },
          "creditScore": { "type": "integer" },
          "tier": { "type": "string" },
          "totalPaidCalls": { "type": "integer" },
          "callHistory": { "type": "array", "items": { "type": "string", "format": "date-time" } },
          "callsToNextTier": { "type": "integer" }
        }
      },
      "Leaderboard": {
        "type": "object",
        "properties": {
          "leaderboard": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "rank": { "type": "integer" },
                "agentDid": { "type": "string" },
                "score": { "type": "integer" },
                "tier": { "type": "string" },
                "totalPaidCalls": { "type": "integer" },
                "lastSeen": { "type": "string" }
              }
            }
          },
          "totalAgents": { "type": "integer" },
          "generatedAt": { "type": "string" }
        }
      },
      "ArgusJwt": {
        "type": "object",
        "properties": {
          "token": { "type": "string", "description": "Signed ARGUS-JWT (header.payload.sig in base64url)" },
          "agentDid": { "type": "string" },
          "score": { "type": "integer" },
          "tier": { "type": "string" },
          "expiresAt": { "type": "string", "format": "date-time" },
          "verifyUrl": { "type": "string" },
          "usage": { "type": "string" }
        }
      },
      "SignalListing": {
        "type": "object",
        "properties": {
          "signalId": { "type": "string" },
          "listed": { "type": "boolean" },
          "priceRlusd": { "type": "string" },
          "sellerEarningsOnSale": { "type": "string" },
          "buyUrl": { "type": "string" }
        }
      },
      "PaymentRequirements": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "example": "payment_required" },
          "protocol": { "type": "string", "example": "x402/1.0" },
          "requirements": {
            "type": "object",
            "properties": {
              "destination": { "type": "string" },
              "amount": { "type": "string" },
              "currency": { "type": "string", "example": "RLUSD" },
              "network": { "type": "string", "example": "xrpl-mainnet" },
              "memo": { "type": "string" }
            }
          }
        }
      }
    },
    "responses": {
      "PaymentRequired": {
        "description": "HTTP 402 — Payment Required. Send RLUSD to requirements.destination, then retry with X-Payment-Proof header.",
        "headers": {
          "X-A2A-Payment-Protocol": { "schema": { "type": "string", "example": "x402/1.0" } },
          "X-A2A-Receiving-Address": { "schema": { "type": "string" } }
        },
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PaymentRequirements" } } }
      }
    }
  }
}
