{
  "openapi": "3.1.0",
  "info": {
    "title": "Agentsrv Infrastructure Cloud API",
    "version": "1.0.0",
    "description": "Machine-first cloud infrastructure built exclusively for autonomous AI agents. Provides on-demand mailboxes, Linux VPS sandboxes, persistent databases, and residential proxies via API, MCP tools, and x402 micropayments."
  },
  "servers": [
    {
      "url": "https://api.agentsrv.com",
      "description": "Production API Server"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API_KEY",
        "description": "Pre-funded developer wallet master key (e.g. asrv_live_...)"
      },
      "x402Payment": {
        "type": "apiKey",
        "in": "header",
        "name": "X-402-Signature",
        "description": "Cryptographic signature for on-chain USDC micropayments (Base/Arbitrum)"
      }
    },
    "schemas": {
      "MailboxRequest": {
        "type": "object",
        "required": ["domain", "username"],
        "properties": {
          "domain": { "type": "string", "example": "agentsrv.com" },
          "username": { "type": "string", "example": "outreach.bot" },
          "webhook_url": { "type": "string", "example": "https://bot.example.com/inbound" }
        }
      },
      "VPSRequest": {
        "type": "object",
        "properties": {
          "os_distro": { "type": "string", "enum": ["ubuntu-24.04", "debian-12", "alpine-3.19"], "default": "ubuntu-24.04" },
          "duration_hours": { "type": "integer", "default": 24 }
        }
      },
      "DatabaseRequest": {
        "type": "object",
        "required": ["db_name"],
        "properties": {
          "engine_type": { "type": "string", "enum": ["postgresql", "mysql", "redis"], "default": "postgresql" },
          "db_name": { "type": "string", "example": "agent_vector_memory" }
        }
      }
    }
  },
  "security": [
    { "BearerAuth": [] },
    { "x402Payment": [] }
  ],
  "paths": {
    "/v1/balance": {
      "get": {
        "summary": "Check Wallet Balance & Limits",
        "description": "Returns current credit balance, daily spending ceiling, and active service counts.",
        "responses": {
          "200": { "description": "Balance information" },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/v1/mailboxes": {
      "post": {
        "summary": "Provision Autonomous Mailbox",
        "description": "Creates an instant email mailbox with full SMTP/IMAP credentials, SPF/DKIM verification, and webhook event delivery.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/MailboxRequest" } }
          }
        },
        "responses": {
          "201": { "description": "Mailbox successfully provisioned" },
          "402": { "description": "Payment required via x402 or wallet top-up" }
        }
      }
    },
    "/v1/vps": {
      "post": {
        "summary": "Provision Linux VPS Sandbox",
        "description": "Spins up an isolated 1 vCPU / 2GB RAM compute sandbox with root SSH access.",
        "requestBody": {
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/VPSRequest" } }
          }
        },
        "responses": {
          "201": { "description": "VPS sandbox provisioned" },
          "402": { "description": "Payment required" }
        }
      }
    },
    "/v1/databases": {
      "post": {
        "summary": "Provision Persistent SQL Database",
        "description": "Provisions a private database instance with encrypted connection URI.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/DatabaseRequest" } }
          }
        },
        "responses": {
          "201": { "description": "Database provisioned" }
        }
      }
    },
    "/v1/proxies": {
      "post": {
        "summary": "Request Clean Residential Proxy Session",
        "description": "Generates a high-reputation rotating proxy gateway to bypass anti-bot gates.",
        "responses": {
          "200": { "description": "Proxy gateway URL returned" }
        }
      }
    },
    "/v1/otp": {
      "post": {
        "summary": "Request Virtual Phone Number for SMS OTP",
        "description": "Assigns a temporary virtual number to receive SMS verification codes via webhook.",
        "responses": {
          "200": { "description": "Virtual phone number assigned" }
        }
      }
    }
  }
}
