{
  "openapi": "3.1.0",
  "info": {
    "title": "Microquery Data API",
    "description": "SQL over 70+ authoritative datasets. Pay-per-query in USDC.",
    "version": "1.0.0"
  },
  "servers": [{ "url": "https://microquery.dev" }],
  "paths": {
    "/v1/register": {
      "post": {
        "operationId": "register",
        "summary": "Get an API key and $0.10 free trial credit. Call this first if you have no key.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": { "type": "string", "description": "Agent or app name" },
                  "wallet_addr": { "type": "string", "description": "Optional Base/Ethereum address for USDC top-up" }
                },
                "required": ["name"]
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Returns api_key" }
        }
      }
    },
    "/v1/databases": {
      "get": {
        "operationId": "listDatabases",
        "summary": "List all available datasets with table names and field schemas. Call before writing SQL.",
        "security": [{ "bearerAuth": [] }]
      }
    },
    "/query": {
      "post": {
        "operationId": "query",
        "summary": "Execute SQL against a dataset. Returns newline-delimited JSON records.",
        "parameters": [
          {
            "name": "database",
            "in": "query",
            "required": true,
            "schema": { "type": "string" },
            "description": "Dataset id, e.g. 'fda', 'nvd', 'eth', 'sec', 'pubmed', 'arxiv'"
          }
        ],
        "requestBody": {
          "content": {
            "text/plain": {
              "schema": { "type": "string", "description": "SQL query" }
            }
          }
        },
        "security": [{ "bearerAuth": [] }, { "x402": [] }]
      }
    },
    "/v1/agent-quickstart": {
      "get": {
        "operationId": "agentQuickstart",
        "summary": "Machine-readable onboarding guide for autonomous agents. Returns registration steps, example queries, pricing, and partition key hints for cost-efficient SQL."
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from /v1/register"
      },
      "x402": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Payment",
        "description": "x402 stateless payment header — no registration needed"
      }
    }
  }
}
