{
  "openapi": "3.1.0",
  "info": {
    "title": "Papermint API",
    "version": "0.5.0",
    "description": "Turn invoice JSON or raw Stripe payloads into branded, locale-aware PDF invoices with one POST request. Deterministic rendering: the same input always produces the same bytes. No invoice data is stored.",
    "contact": {
      "email": "support@papermint.dev"
    }
  },
  "servers": [
    {
      "url": "https://papermint-phi.vercel.app"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api/v1/invoice": {
      "post": {
        "summary": "Render invoice JSON to PDF",
        "operationId": "renderInvoice",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Invoice"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The rendered PDF. X-Papermint-Remaining reports the monthly quota left.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/from-stripe": {
      "post": {
        "summary": "Render a raw Stripe payload to PDF",
        "operationId": "renderFromStripe",
        "description": "Send the Stripe invoice, payment_intent, or checkout.session object you already have (from a webhook or API call) with its `object` field intact. Supports current (2025-03-31 basil and later) and legacy payload shapes. Zero-decimal and Stripe special-case currencies are handled; three-decimal currencies are rejected.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "stripe_object",
                  "seller"
                ],
                "properties": {
                  "stripe_object": {
                    "type": "object",
                    "description": "Raw Stripe object JSON"
                  },
                  "seller": {
                    "$ref": "#/components/schemas/Party"
                  },
                  "overrides": {
                    "$ref": "#/components/schemas/Invoice"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The rendered PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/api/v1/validate": {
      "post": {
        "summary": "Validate invoice JSON without rendering",
        "operationId": "validateInvoice",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Invoice"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": {
                      "type": "boolean"
                    },
                    "template": {
                      "type": "string"
                    },
                    "issues": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "path": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/templates": {
      "get": {
        "summary": "List templates",
        "operationId": "listTemplates",
        "security": [],
        "responses": {
          "200": {
            "description": "Available templates"
          }
        }
      }
    },
    "/api/preview": {
      "post": {
        "summary": "Free watermarked render (playground)",
        "operationId": "previewInvoice",
        "security": [],
        "description": "Same schema as /api/v1/invoice. No auth, watermarked output, 60 renders per hour per IP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Invoice"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Watermarked PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "summary": "Liveness check",
        "operationId": "health",
        "security": [],
        "responses": {
          "200": {
            "description": "Service status and version"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key issued after checkout, format pm_..."
      }
    },
    "responses": {
      "Error": {
        "description": "Error with a human-readable message",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ValidationError": {
        "description": "Validation failure listing every issue with its JSON path",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                },
                "issues": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "path": {
                        "type": "string"
                      },
                      "message": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Party": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 160
          },
          "addressLines": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 6
          },
          "email": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "vatId": {
            "type": "string"
          },
          "website": {
            "type": "string"
          }
        }
      },
      "LineItem": {
        "type": "object",
        "required": [
          "description",
          "unitPrice"
        ],
        "properties": {
          "description": {
            "type": "string",
            "maxLength": 600
          },
          "quantity": {
            "type": "number",
            "minimum": 0,
            "default": 1
          },
          "unitPrice": {
            "type": "number",
            "description": "Major units, e.g. 19.99"
          },
          "taxRate": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "description": "Percent"
          },
          "discount": {
            "type": "number",
            "minimum": 0,
            "description": "Absolute amount per line"
          }
        }
      },
      "Invoice": {
        "type": "object",
        "required": [
          "invoice",
          "seller",
          "buyer",
          "items"
        ],
        "properties": {
          "template": {
            "type": "string",
            "enum": [
              "clean",
              "classic",
              "bold",
              "minimal",
              "receipt"
            ],
            "default": "clean"
          },
          "pageSize": {
            "type": "string",
            "enum": [
              "a4",
              "letter"
            ],
            "default": "a4"
          },
          "locale": {
            "type": "string",
            "default": "en-US",
            "description": "BCP 47 tag for number/date formatting"
          },
          "currency": {
            "type": "string",
            "default": "USD",
            "description": "ISO 4217. Three-decimal currencies (BHD, IQD, JOD, KWD, LYD, OMR, TND) are not supported"
          },
          "invoice": {
            "type": "object",
            "required": [
              "number"
            ],
            "properties": {
              "number": {
                "type": "string"
              },
              "date": {
                "type": "string"
              },
              "dueDate": {
                "type": "string"
              },
              "purchaseOrder": {
                "type": "string"
              },
              "reference": {
                "type": "string"
              }
            }
          },
          "seller": {
            "$ref": "#/components/schemas/Party"
          },
          "buyer": {
            "$ref": "#/components/schemas/Party"
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 300,
            "items": {
              "$ref": "#/components/schemas/LineItem"
            }
          },
          "totals": {
            "type": "object",
            "description": "Explicit overrides so the PDF matches your source system to the cent",
            "properties": {
              "subtotal": {
                "type": "number"
              },
              "taxLines": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "label": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number"
                    }
                  }
                }
              },
              "total": {
                "type": "number"
              },
              "amountPaid": {
                "type": "number"
              },
              "amountDue": {
                "type": "number"
              }
            }
          },
          "amountPaid": {
            "type": "number"
          },
          "discount": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "amount": {
                "type": "number"
              }
            }
          },
          "shipping": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "amount": {
                "type": "number"
              }
            }
          },
          "payment": {
            "type": "object",
            "required": [
              "url"
            ],
            "description": "Renders a scannable QR code and a clickable payment link on the PDF",
            "properties": {
              "url": {
                "type": "string",
                "format": "uri"
              },
              "label": {
                "type": "string",
                "default": "Pay online"
              },
              "qr": {
                "type": "boolean",
                "default": true
              }
            }
          },
          "notes": {
            "type": "string",
            "maxLength": 3000
          },
          "terms": {
            "type": "string",
            "maxLength": 3000
          },
          "footerNote": {
            "type": "string",
            "maxLength": 400
          },
          "reverseCharge": {
            "type": "boolean",
            "default": false
          },
          "branding": {
            "type": "object",
            "properties": {
              "accentColor": {
                "type": "string",
                "pattern": "^#[0-9a-fA-F]{6}$"
              },
              "logo": {
                "type": "string",
                "description": "Base64 or data-URI PNG/JPEG"
              },
              "logoWidth": {
                "type": "number",
                "minimum": 20,
                "maximum": 220
              }
            }
          },
          "documentTitle": {
            "type": "string",
            "default": "Invoice",
            "maxLength": 40,
            "description": "Heading word on the document: Invoice, Quote, Receipt, Estimate..."
          },
          "filename": {
            "type": "string",
            "pattern": "^[\\w.() -]{1,120}$",
            "description": "Sets the Content-Disposition filename on the PDF response"
          },
          "customFields": {
            "type": "array",
            "maxItems": 4,
            "description": "Extra header fields rendered with the invoice metadata",
            "items": {
              "type": "object",
              "required": [
                "name",
                "value"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "maxLength": 40
                },
                "value": {
                  "type": "string",
                  "maxLength": 120
                }
              }
            }
          }
        }
      }
    }
  }
}