{
  "openapi": "3.1.0",
  "info": {
    "title": "poststr API",
    "version": "1.0.0",
    "description": "Write messages permanently to the Bitcoin blockchain (OP_RETURN), paid with Lightning. No API key. Flow: POST /api/v1/orders, pay the returned BOLT11 invoice, poll GET /api/v1/orders/{orderId} until status is broadcast or confirmed. Messages are public and permanent."
  },
  "servers": [
    {
      "url": "https://poststr.com"
    }
  ],
  "paths": {
    "/api/v1/quote": {
      "get": {
        "operationId": "getQuote",
        "summary": "Price a message without creating an order",
        "parameters": [
          {
            "name": "message",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Quote",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "400": {
            "description": "Invalid message",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Upstream fee/price error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postQuote",
        "summary": "Price a message (JSON body, for long messages)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "description": "UTF-8 text, max 90000 bytes"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Quote",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "400": {
            "description": "Invalid message",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Upstream fee/price error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/orders": {
      "post": {
        "operationId": "createOrder",
        "summary": "Create an order and get a Lightning invoice",
        "description": "Nothing is written on-chain until `invoice` is paid. Invoices expire after 1 hour.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "description": "UTF-8 text, max 90000 bytes"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "400": {
            "description": "Invalid message",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited (20 orders / 10 min per client)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Could not create invoice",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/orders/{orderId}": {
      "get": {
        "operationId": "getOrder",
        "summary": "Order payment and broadcast status",
        "parameters": [
          {
            "name": "orderId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/opreturns/search": {
      "get": {
        "operationId": "searchOpReturns",
        "summary": "Search on-chain OP_RETURN messages by keyword or txid",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 25
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          },
          {
            "name": "includeMachine",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpReturnList"
                }
              }
            }
          },
          "400": {
            "description": "Missing q",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/opreturns/recent": {
      "get": {
        "operationId": "recentOpReturns",
        "summary": "Newest OP_RETURN messages",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 12
            }
          },
          {
            "name": "includeMachine",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpReturnList"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "Quote": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Message after typography cleanup; this exact text is written"
          },
          "amountSats": {
            "type": "integer"
          },
          "totalUsd": {
            "type": "string"
          },
          "dataBytes": {
            "type": "integer"
          },
          "maxBytes": {
            "type": "integer"
          },
          "breakdown": {
            "type": "object",
            "properties": {
              "networkFeeSats": {
                "type": "integer"
              },
              "marginSats": {
                "type": "integer"
              },
              "opReturnSats": {
                "type": "integer"
              },
              "serviceFeeSats": {
                "type": "integer"
              },
              "feeRateSatPerVByte": {
                "type": "number"
              },
              "estimatedVsize": {
                "type": "integer"
              }
            }
          },
          "btcUsdRate": {
            "type": "number"
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "orderId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "awaiting_payment",
              "expired",
              "processing",
              "broadcast",
              "confirmed",
              "failed"
            ]
          },
          "hint": {
            "type": "string",
            "description": "What to do next"
          },
          "amountSats": {
            "type": "integer"
          },
          "amountPaidSats": {
            "type": [
              "integer",
              "null"
            ]
          },
          "invoice": {
            "type": [
              "string",
              "null"
            ],
            "description": "BOLT11 Lightning invoice; null once paid or expired"
          },
          "paymentHash": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "txid": {
            "type": [
              "string",
              "null"
            ]
          },
          "blockHeight": {
            "type": [
              "integer",
              "null"
            ]
          },
          "explorerUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "statusUrl": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "quote": {
            "$ref": "#/components/schemas/Quote",
            "description": "Only on create"
          }
        }
      },
      "OpReturn": {
        "type": "object",
        "properties": {
          "txid": {
            "type": "string"
          },
          "vout": {
            "type": "integer"
          },
          "blockHeight": {
            "type": "integer"
          },
          "blockTime": {
            "type": "string",
            "format": "date-time"
          },
          "text": {
            "type": [
              "string",
              "null"
            ],
            "description": "First 2000 characters"
          },
          "textTruncated": {
            "type": "boolean"
          },
          "byteLen": {
            "type": "integer"
          },
          "protocol": {
            "type": [
              "string",
              "null"
            ]
          },
          "matchType": {
            "type": "string"
          },
          "explorerUrl": {
            "type": "string"
          }
        }
      },
      "OpReturnList": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OpReturn"
            }
          }
        }
      }
    }
  }
}