{
  "openapi": "3.1.0",
  "info": {
    "title": "Smmize Agent API",
    "version": "2.0.0",
    "description": "Quote and order Smmize services with an owner-signed agent envelope. The API never exposes the owner's main balance. Agent-safe services only. Verified targets only. Step-up above the owner's threshold. MCP is available at /mcp."
  },
  "servers": [{ "url": "https://smmize.com", "description": "Production" }],
  "security": [{ "ApiKeyAuth": [] }],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": { "type": "apiKey", "in": "header", "name": "X-API-KEY" },
      "BearerAuth": { "type": "http", "scheme": "bearer" }
    },
    "schemas": {
      "AgentRequest": {
        "type": "object",
        "required": ["action"],
        "properties": {
          "key": { "type": "string", "description": "Agent key. You can also send X-API-KEY." },
          "action": { "type": "string", "enum": ["services", "add", "status", "orders", "cancel", "refill", "refill_status", "balance"] },
          "service": { "type": "integer", "description": "Agent-safe service id" },
          "quantity": { "type": "integer", "minimum": 1 },
          "link": { "type": "string", "description": "Verified target URL. It must match an owner-verified target." },
          "target_id": { "type": "integer", "description": "Verified target id. Recommended." },
          "idempotency_key": { "type": "string", "description": "Client-generated id. Reusing it returns the original order." },
          "approval_id": { "type": "integer", "description": "Owner approval returned by a step-up quote." },
          "order": { "type": "integer" }
        }
      },
      "Quote": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "enum": ["ok", "step_up_required"] },
          "service": { "type": "integer" },
          "quantity": { "type": "integer" },
          "amount": { "type": "number" },
          "target": { "type": "integer" },
          "target_handle": { "type": "string" },
          "decision": { "type": "string", "enum": ["auto"] },
          "approval": { "type": "integer" },
          "expires_at": { "type": "string" }
        }
      },
      "Error": {
        "type": "object",
        "properties": { "error": { "type": "string" } }
      }
    }
  },
  "paths": {
    "/api/v2": {
      "post": {
        "summary": "Agent API v2",
        "description": "Use action=services, add, status, orders, cancel, refill, refill_status or balance. action=add requires a verified target and an agent-safe service. Orders above step_up_over return step_up_required instead of charging.",
        "requestBody": {
          "required": true,
          "content": { "application/x-www-form-urlencoded": { "schema": { "$ref": "#/components/schemas/AgentRequest" } }, "application/json": { "schema": { "$ref": "#/components/schemas/AgentRequest" } } }
        },
        "responses": {
          "200": { "description": "Command result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Quote" } } } },
          "403": { "description": "Outside the envelope", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/mcp": {
      "post": {
        "summary": "MCP JSON-RPC endpoint",
        "description": "Streamable HTTP MCP. Initialize, then tools/list and tools/call. Authenticate with Authorization: Bearer <agent key>. Tools: list_services, get_service, list_targets, quote_order, create_order, get_order, list_orders, get_balance, get_referral_link, create_refill.",
        "security": [{ "BearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "required": ["jsonrpc", "method"], "properties": { "jsonrpc": { "type": "string", "const": "2.0" }, "id": { "type": ["string", "integer", "null"] }, "method": { "type": "string" }, "params": { "type": "object" } } } } }
        },
        "responses": { "200": { "description": "JSON-RPC response" }, "401": { "description": "Invalid agent key" } }
      }
    },
    "/.well-known/mcp.json": {
      "get": {
        "summary": "MCP discovery",
        "security": [],
        "responses": { "200": { "description": "MCP server metadata" } }
      }
    },
    "/x402/order": {
      "post": {
        "summary": "x402 direct paid order",
        "description": "No owner account needed. POST service, quantity and link. Without a payment header the server returns HTTP 402 with PAYMENT-REQUIRED. Pay the accepted USDC amount and retry with PAYMENT-SIGNATURE. The order is created only after settlement and within the per-wallet caps.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["service", "quantity", "link"],
                "properties": {
                  "service": { "type": "integer" },
                  "quantity": { "type": "integer" },
                  "link": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Order created; PAYMENT-RESPONSE header contains the settlement" },
          "402": { "description": "Payment required; PAYMENT-REQUIRED header contains the accepts list" },
          "422": { "description": "Invalid service, quantity or link" },
          "503": { "description": "x402 is not configured" }
        }
      }
    },
    "/x402/order/{id}": {
      "get": {
        "summary": "Read an x402 order",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "integer" } },
          { "name": "tx", "in": "query", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Order status" }, "404": { "description": "Not found" } }
      }
    },
    "/.well-known/x402.json": {
      "get": {
        "summary": "x402 discovery",
        "security": [],
        "responses": { "200": { "description": "x402 resource metadata" }, "503": { "description": "Not configured" } }
      }
    }
  }
}
