{
  "openapi": "3.1.0",
  "info": {
    "title": "Subnano Post Discovery and Access",
    "version": "1.0.0",
    "description": "Search creator-published research, guides, and datasets. Preview Posts for free and unlock individual Posts with native USDC on Base via x402 v2.",
    "contact": { "name": "Subnano", "email": "hello@subnano.ai" },
    "x-guidance": "Use GET /api/posts with a task query to find relevant Posts. Inspect each freePreview and paymentOffers. To search paid Posts within a Base USDC budget, send access=paid, asset=USDC, network=eip155:8453, and max_amount_atomic in USDC micro-units (1000000 = 1 USDC). For a ready offer, GET its accessUrl with rail=usdc. The live Payment-Required header is the authoritative quote. Check the resource, amount, asset, network, and recipient against your spending policy before signing. An eligible wallet can submit the original Payment-Signature to the same GET without a Subnano account. Read post.content.paid.markdown in the JSON response. If settlement is pending, retry the original signature at the returned retryUrl with rail=usdc; never sign a second payment while the first is uncertain."
  },
  "servers": [{ "url": "https://subnano.ai" }],
  "externalDocs": {
    "description": "Search, preview, and evaluate a Post before paying",
    "url": "https://docs.subnano.ai/v1/api/buyer-discovery"
  },
  "paths": {
    "/api/posts": {
      "get": {
        "operationId": "searchPosts",
        "summary": "Search published Subnano Posts for free",
        "description": "Returns public summaries, free previews and indicative payment offers. For a Base USDC budget, send asset=USDC and network=eip155:8453 together with max_amount_atomic. Search never allocates a payable quote.",
        "security": [],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Task or keywords to match against published Posts. Omit to browse.",
            "schema": { "type": "string", "maxLength": 100 },
            "example": "x402 payment recovery"
          },
          {
            "name": "access",
            "in": "query",
            "description": "Filter by free or paid access, or include both.",
            "schema": { "type": "string", "enum": ["all", "free", "paid"], "default": "all" }
          },
          {
            "name": "asset",
            "in": "query",
            "description": "Asset for the budget filter. Supply USDC with network=eip155:8453.",
            "schema": { "type": "string", "enum": ["USDC"] }
          },
          {
            "name": "network",
            "in": "query",
            "description": "Base mainnet for the USDC budget filter. Supply with asset=USDC.",
            "schema": { "type": "string", "enum": ["eip155:8453"] }
          },
          {
            "name": "max_amount_atomic",
            "in": "query",
            "description": "Inclusive budget in USDC micro-units as a decimal integer string. Requires asset and network. Filters for ready indicative offers.",
            "schema": { "type": "string", "pattern": "^[0-9]{1,78}$", "maxLength": 78 },
            "example": "1000000"
          },
          {
            "name": "page",
            "in": "query",
            "description": "One-based result page.",
            "schema": { "type": "integer", "minimum": 1, "maximum": 1000, "default": 1 }
          },
          {
            "name": "per_page",
            "in": "query",
            "description": "Maximum number of Posts to return per page.",
            "schema": { "type": "integer", "minimum": 1, "maximum": 48, "default": 12 }
          }
        ],
        "responses": {
          "200": {
            "description": "Public search results and pagination. Paid text is excluded from previews.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "total", "page", "perPage"],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/PostSummary" }
                    },
                    "total": { "type": "integer" },
                    "page": { "type": "integer" },
                    "perPage": { "type": "integer" }
                  }
                }
              }
            }
          },
          "400": { "description": "Invalid search parameters or incompatible budget filters." },
          "429": { "description": "Rate limited. Respect Retry-After when present." },
          "503": { "description": "Search is temporarily unavailable." }
        }
      }
    },
    "/api/posts/{postId}/access": {
      "get": {
        "operationId": "unlockPostWithUsdc",
        "summary": "Unlock a published Post with Base USDC",
        "description": "Select a ready USDC offer from search (paymentOffers: rail=usdc, network=eip155:8453, status=ready) and set rail=usdc. Not every Post accepts USDC. A paid Post with an available offer returns an x402 v2 exact quote in Payment-Required; an unavailable offer returns 422, not a login requirement. Eligible EOA, delegated primary-key and deployed ERC-1271 contract wallets can sign and retry the same GET without an account, login, cookies or API key. Anonymous contract payments grant only original Post access, never account ownership or a session. Exact settled proof replay returns the original content without a second charge. Free Posts can return 200 immediately.",
        "security": [],
        "x-payment-info": {
          "price": { "mode": "dynamic", "currency": "USDC", "min": "0.100000" },
          "protocols": [{ "x402": {} }]
        },
        "externalDocs": {
          "description": "Base USDC purchases, wallet eligibility and returning access",
          "url": "https://docs.subnano.ai/v1/api/payments#base-usdc-purchases"
        },
        "parameters": [
          {
            "name": "postId",
            "in": "path",
            "required": true,
            "description": "Published Post UUID from a search result's id or accessUrl.",
            "schema": { "type": "string", "format": "uuid" },
            "example": "41fbccdc-e591-4216-9475-b4661d8beb77"
          },
          {
            "name": "rail",
            "in": "query",
            "required": true,
            "description": "Selects the Base USDC flow documented here.",
            "schema": { "type": "string", "enum": ["usdc"] },
            "example": "usdc"
          },
          {
            "name": "Payment-Signature",
            "in": "header",
            "description": "Omit on the quote request. On the retry, send the wallet-generated base64 x402 v2 payment payload for the original resource and accepted offer.",
            "schema": {
              "type": "string",
              "contentEncoding": "base64",
              "contentMediaType": "application/json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Readable Post content. After a successful unlock, post.content.paid.markdown contains the paid text.",
            "headers": {
              "Payment-Response": {
                "description": "Base64-encoded x402 settlement response on successful payment.",
                "schema": {
                  "type": "string",
                  "contentEncoding": "base64",
                  "contentMediaType": "application/json"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ReadablePost" },
                "examples": {
                  "paidPost": {
                    "summary": "Illustrative paid response; content is synthetic, not the referenced creator’s paid text.",
                    "value": {
                      "post": {
                        "id": "41fbccdc-e591-4216-9475-b4661d8beb77",
                        "title": "Illustrative paid Post",
                        "content": {
                          "free": { "markdown": "Public preview." },
                          "paid": { "markdown": "Illustrative protected Post content." }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment required. The quote is specific to the Post and may change between new quote requests. Text Posts start at 0.10 USDC, and Posts with ZIPs have a 0.25 USDC minimum.",
            "headers": {
              "Payment-Required": {
                "description": "Base64-encoded x402 v2 quote with the exact accepted amount in USDC micro-units.",
                "schema": {
                  "type": "string",
                  "contentEncoding": "base64",
                  "contentMediaType": "application/json",
                  "contentSchema": { "$ref": "#/components/schemas/BasePaymentRequired" }
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["statusCode", "data"],
                  "properties": {
                    "statusCode": { "const": 402 },
                    "data": { "$ref": "#/components/schemas/BasePaymentRequired" }
                  }
                },
                "examples": {
                  "baseUsdc": {
                    "summary": "Illustrative 0.10 USDC quote; request a fresh live quote and never sign these example values.",
                    "value": {
                      "statusCode": 402,
                      "data": {
                        "x402Version": 2,
                        "resource": {
                          "url": "https://subnano.ai/api/posts/41fbccdc-e591-4216-9475-b4661d8beb77/access?rail=usdc"
                        },
                        "accepts": [
                          {
                            "scheme": "exact",
                            "network": "eip155:8453",
                            "asset": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
                            "amount": "100000",
                            "payTo": "0xb44cd235a9a08435a4ffa79f8dfab32dcb9c401b",
                            "maxTimeoutSeconds": 300,
                            "extra": {
                              "name": "USD Coin",
                              "version": "2",
                              "quoteId": "11111111-1111-4111-8111-111111111111"
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "description": "Invalid request or payment proof." },
          "404": { "description": "Post unavailable to this caller." },
          "409": {
            "description": "Original settlement is pending or conflicts with another saved purchase. For usdc-settlement-pending, use data.retryUrl with rail=usdc and replay the identical Payment-Signature. Preserve the original payment on conflict."
          },
          "410": {
            "description": "The original quote expired or the authorization was safely closed."
          },
          "422": {
            "description": "USDC is off or unavailable for this Post (for example missing payout setup, stale conversion or below-minimum price), or the wallet proof/account class is unsupported. Check paymentOffers and its status/reason. A Post without a ready USDC offer does not become payable by logging in.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["statusCode"],
                  "properties": {
                    "statusCode": { "const": 422 },
                    "message": { "type": "string" },
                    "statusMessage": { "type": "string" },
                    "data": { "type": "object", "properties": { "code": { "type": "string" } } }
                  }
                },
                "examples": {
                  "usdcOff": {
                    "value": {
                      "statusCode": 422,
                      "message": "USDC payment offer is unavailable",
                      "data": { "code": "off" }
                    }
                  }
                }
              }
            }
          },
          "429": { "description": "Rate limited. Respect Retry-After when present." },
          "503": {
            "description": "USDC quote issuance or a required service is temporarily unavailable."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PostSummary": {
        "type": "object",
        "required": [
          "id",
          "title",
          "description",
          "freePreview",
          "isPaywalled",
          "accessUrl",
          "paymentOffers"
        ],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "title": { "type": ["string", "null"] },
          "description": { "type": ["string", "null"] },
          "freePreview": {
            "type": "string",
            "description": "Plain text excerpt from free content."
          },
          "isPaywalled": { "type": "boolean" },
          "accessUrl": {
            "type": "string",
            "format": "uri",
            "description": "Canonical URL to read or quote this Post."
          },
          "paymentOffers": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["rail", "network", "currency", "status", "amountAtomic", "indicative"],
              "properties": {
                "rail": { "type": "string", "enum": ["nano", "usdc"] },
                "network": { "type": "string", "enum": ["nano-mainnet", "eip155:8453"] },
                "currency": { "type": "string", "enum": ["XNO", "USDC"] },
                "status": {
                  "type": "string",
                  "description": "Use a ready USDC offer to select a candidate."
                },
                "amountAtomic": {
                  "type": ["string", "null"],
                  "pattern": "^[0-9]+$",
                  "description": "Indicative atomic price, or null when unavailable. USDC uses six decimals and XNO uses 30."
                },
                "indicative": { "const": true }
              }
            }
          }
        }
      },
      "ReadablePost": {
        "type": "object",
        "required": ["post"],
        "properties": {
          "post": {
            "type": "object",
            "required": ["id", "title", "content"],
            "properties": {
              "id": { "type": "string", "format": "uuid" },
              "title": { "type": "string" },
              "content": {
                "type": "object",
                "required": ["free", "paid"],
                "properties": {
                  "free": { "$ref": "#/components/schemas/PostContentSection" },
                  "paid": { "$ref": "#/components/schemas/PostContentSection" }
                }
              }
            }
          }
        }
      },
      "PostContentSection": {
        "type": "object",
        "required": ["markdown"],
        "properties": { "markdown": { "type": ["string", "null"] } }
      },
      "BasePaymentRequired": {
        "type": "object",
        "required": ["x402Version", "resource", "accepts"],
        "properties": {
          "x402Version": { "const": 2 },
          "resource": {
            "type": "object",
            "required": ["url"],
            "properties": { "url": { "type": "string", "format": "uri" } }
          },
          "accepts": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "scheme",
                "network",
                "asset",
                "amount",
                "payTo",
                "maxTimeoutSeconds",
                "extra"
              ],
              "properties": {
                "scheme": { "const": "exact" },
                "network": { "const": "eip155:8453" },
                "asset": { "const": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" },
                "amount": {
                  "type": "string",
                  "pattern": "^[0-9]+$",
                  "description": "Exact price in USDC micro-units."
                },
                "payTo": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
                "maxTimeoutSeconds": { "type": "integer", "minimum": 1 },
                "extra": {
                  "type": "object",
                  "description": "Preserve these fields from the original offer in the signed payload.",
                  "required": ["name", "version", "quoteId"],
                  "properties": {
                    "name": { "const": "USD Coin" },
                    "version": { "const": "2" },
                    "quoteId": { "type": "string", "format": "uuid" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
