{
  "openapi": "3.1.0",
  "info": {
    "title": "PDFops API",
    "version": "1.0.0",
    "description": "Deterministic PDF primitives over HTTP: inspect and fill AcroForm fields, merge, split, extract, delete and rotate pages, add watermarks and page numbers, unlock and protect PDFs, read and set metadata, and generate invoices. Edge-hosted, no Chromium. Keyless trial: 100 requests/IP/month. Free API key (250/month, emailed, no card): POST /api/signup or https://pdfops.dev/pricing. Paid tiers: Indie $16/mo (4,000), Pro $79/mo (25,000). Quotas are hard stops (429 with Retry-After) until the monthly UTC reset.",
    "contact": {
      "name": "PDFops",
      "email": "hello@pdfops.dev",
      "url": "https://pdfops.dev"
    }
  },
  "servers": [
    {
      "url": "https://pdfops.dev"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Optional on PDF endpoints — omit for the keyless 100/IP/month trial; present = your tier quota. Invalid/revoked keys get 401 (no fallback to the IP cap)."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Stable machine-readable slug, e.g. unknown_field, invalid_api_key, rate_limited"
          },
          "details": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "details"
        ]
      },
      "InspectedField": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "label": {
            "type": "string",
            "description": "Alternate (tooltip) name of the field, only when the form defines one. /api/fill-form accepts it as a key when no field name matches"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "checkbox",
              "dropdown",
              "radio",
              "optionlist",
              "unsupported"
            ]
          },
          "value": {
            "type": "string"
          },
          "checked": {
            "type": "boolean"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "readOnly": {
            "type": "boolean"
          },
          "raw": {
            "type": "string",
            "description": "Underlying field class, only for type=unsupported"
          },
          "maxLength": {
            "type": "integer",
            "description": "Maximum character count the form declares for this text field; values longer than this are rejected with exceeds_max_length"
          }
        },
        "required": [
          "name",
          "type",
          "readOnly"
        ]
      },
      "InspectResult": {
        "type": "object",
        "properties": {
          "count": {
            "type": "integer"
          },
          "hasXFA": {
            "type": "boolean",
            "description": "Hybrid AcroForm/XFA input: fill writes the AcroForm layer and drops the XFA layer on save"
          },
          "truncated": {
            "type": "boolean",
            "description": "Output hit a cap (2,000 fields, 500 options per field, or ~2M characters) and is incomplete. Strings over 4,096 characters are cut"
          },
          "fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InspectedField"
            }
          },
          "fillTemplate": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Paste-ready fields object for POST /api/fill-form (supported fields only)"
          }
        },
        "required": [
          "count",
          "hasXFA",
          "truncated",
          "fields",
          "fillTemplate"
        ]
      },
      "Usage": {
        "type": "object",
        "properties": {
          "tier": {
            "type": "string",
            "enum": [
              "free",
              "indie",
              "pro"
            ]
          },
          "limit": {
            "type": "integer"
          },
          "used": {
            "type": "integer"
          },
          "remaining": {
            "type": "integer"
          },
          "period": {
            "type": "string",
            "example": "2026-07"
          },
          "resets_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "tier",
          "limit",
          "used",
          "remaining",
          "period",
          "resets_at"
        ]
      },
      "InvoiceParty": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "lines": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 6
          }
        },
        "required": [
          "name"
        ]
      },
      "InvoiceItem": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0,
            "default": 1
          },
          "unit_price": {
            "type": "number",
            "minimum": 0
          }
        },
        "required": [
          "description",
          "unit_price"
        ]
      },
      "SplitResult": {
        "type": "object",
        "properties": {
          "count": {
            "type": "integer"
          },
          "parts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "pages": {
                  "type": "string"
                },
                "page_count": {
                  "type": "integer"
                },
                "pdf": {
                  "type": "string",
                  "description": "The part as a base64-encoded PDF"
                }
              },
              "required": [
                "pages",
                "page_count",
                "pdf"
              ]
            }
          }
        },
        "required": [
          "count",
          "parts"
        ]
      },
      "PdfMetadata": {
        "type": "object",
        "properties": {
          "page_count": {
            "type": "integer"
          },
          "pages": {
            "type": "array",
            "description": "At most 2,000 entries. Width and height are the MediaBox in points.",
            "items": {
              "type": "object",
              "properties": {
                "width": {
                  "type": "number"
                },
                "height": {
                  "type": "number"
                },
                "rotation": {
                  "type": "number"
                }
              },
              "required": [
                "width",
                "height",
                "rotation"
              ]
            }
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "author": {
            "type": [
              "string",
              "null"
            ]
          },
          "subject": {
            "type": [
              "string",
              "null"
            ]
          },
          "keywords": {
            "type": [
              "string",
              "null"
            ]
          },
          "creator": {
            "type": [
              "string",
              "null"
            ]
          },
          "producer": {
            "type": [
              "string",
              "null"
            ]
          },
          "creation_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "modification_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "encrypted": {
            "type": "boolean",
            "description": "True when the PDF had to be decrypted to read it, including owner-locked files with an empty user password"
          },
          "has_form": {
            "type": "boolean"
          },
          "form_field_count": {
            "type": "integer",
            "description": "AcroForm fields found, each counted once, never more than 2,000"
          },
          "form_field_count_capped": {
            "type": "boolean",
            "description": "True when the count stopped at the 2,000-field cap or the form was too large to walk fully, so the real number may be higher"
          }
        },
        "required": [
          "page_count",
          "pages",
          "title",
          "author",
          "subject",
          "keywords",
          "creator",
          "producer",
          "creation_date",
          "modification_date",
          "encrypted",
          "has_form",
          "form_field_count",
          "form_field_count_capped"
        ]
      }
    }
  },
  "paths": {
    "/api/inspect": {
      "post": {
        "operationId": "inspectPdf",
        "summary": "List a PDF's AcroForm fields + get a paste-ready fill template",
        "description": "The natural first call: you can't fill fields whose names you don't know. A PDF with no AcroForm returns 200 with count 0 (not an error).",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary"
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Field listing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InspectResult"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | encrypted_pdf | invalid_pdf | too_many_pages | decompressed_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (multipart endpoints: body over 4.5 MB, the Vercel platform limit; /api/invoice: over 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/fill-form": {
      "post": {
        "operationId": "fillPdfForm",
        "summary": "Fill AcroForm fields in a PDF",
        "description": "Keys are matched to fields by exact name, then by normalized name or last dotted segment, then by the field's label (tooltip); only a unique match resolves. Use /api/inspect to discover names. Checkbox values are the strings \"true\"|\"false\"; dropdown/radio/optionlist values must be one of the field's options.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary"
                  },
                  "fields": {
                    "type": "string",
                    "description": "JSON object string mapping field name → string value"
                  },
                  "flatten": {
                    "type": "string",
                    "enum": [
                      "true",
                      "false"
                    ],
                    "default": "false",
                    "description": "Bake filled values into page content and remove the AcroForm (non-interactive output). Not tamper evidence or compliance."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf",
                  "fields"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The filled PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "x-pdfops-warning": {
                "schema": {
                  "type": "string"
                },
                "description": "Present when the input was hybrid AcroForm/XFA: the XFA layer is not preserved on save (value starts with \"xfa-layer-dropped\")"
              },
              "x-pdfops-field-map": {
                "schema": {
                  "type": "string"
                },
                "description": "Present when any key was not an exact field name. JSON object {\"provided key\": \"resolved field name\"} for the non-exact keys only; non-ASCII is \\u-escaped and the header is cut at about 4 KB with a final \"...\":\"\" entry"
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | missing_fields | invalid_fields_json | invalid_fields | fields_too_large | too_many_fields | invalid_flatten_value | pdf_too_large | encrypted_pdf | invalid_pdf | too_many_pages | decompressed_too_large | no_form | invalid_field_value | unknown_field (no match, or ambiguous; details list suggestions or up to 5 candidates, at most 20 problems, 2,000 characters) | duplicate_field | invalid_checkbox_value | unrenderable_text | invalid_option | unsupported_field_type | exceeds_max_length | fill_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (multipart endpoints: body over 4.5 MB, the Vercel platform limit; /api/invoice: over 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/merge": {
      "post": {
        "operationId": "mergePdfs",
        "summary": "Merge two or more PDFs into one",
        "description": "Multipart with repeated `pdf` fields; pages are concatenated in field order. AcroForm interactivity is not preserved across the merge.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    },
                    "minItems": 2
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The merged PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | insufficient_pdfs | too_many_pdfs | pdf_too_large | encrypted_pdf | invalid_pdf | too_many_pages | decompressed_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (multipart endpoints: body over 4.5 MB, the Vercel platform limit; /api/invoice: over 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/extract-pages": {
      "post": {
        "operationId": "extractPages",
        "summary": "Extract or reorder pages of a PDF",
        "description": "Builds a new PDF from the listed pages, in the order given. Duplicates are allowed, so it also reorders. Output is byte-deterministic.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "pages": {
                    "type": "string",
                    "description": "Required. 1-based page list such as `1-3,5,8-`. `3,1,3` returns pages 3, 1, 3."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf",
                  "pages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The new PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages | invalid_pages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "copy_failed | save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/delete-pages": {
      "post": {
        "operationId": "deletePages",
        "summary": "Delete pages from a PDF",
        "description": "Removes the listed pages and keeps the rest in their original order. Deleting every page returns no_pages_left. Output is byte-deterministic.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "pages": {
                    "type": "string",
                    "description": "Required. 1-based list of pages to remove, such as `2,4-6,9-`."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf",
                  "pages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The PDF without the listed pages",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages | invalid_pages | no_pages_left",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "copy_failed | save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/rotate": {
      "post": {
        "operationId": "rotatePages",
        "summary": "Rotate PDF pages",
        "description": "Adds the rotation to each selected page's existing rotation and normalizes it to 0-359. A page listed twice is rotated once. Output is byte-deterministic.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "degrees": {
                    "type": "string",
                    "enum": [
                      "90",
                      "180",
                      "270",
                      "-90"
                    ]
                  },
                  "pages": {
                    "type": "string",
                    "description": "1-based page list such as `1-3,5` or `4-`. Items are N, A-B or A-. Default: all pages."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf",
                  "degrees"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The rotated PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages | invalid_degrees | invalid_pages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/split": {
      "post": {
        "operationId": "splitPdf",
        "summary": "Split a PDF into parts",
        "description": "Send exactly one of `ranges` (each comma group becomes one part) or `every` (chunk size). Returns each part as base64. At most 100 parts, and 4 MB for the whole JSON response (output_too_large past that; use fewer pages per request or /api/extract-pages per range).",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "ranges": {
                    "type": "string",
                    "description": "1-based page ranges, one part per comma group, e.g. `1-2,3-5`."
                  },
                  "every": {
                    "type": "string",
                    "pattern": "^[0-9]+$",
                    "description": "Positive chunk size, e.g. `2`."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The parts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SplitResult"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages | invalid_split | invalid_every | invalid_pages | too_many_parts | output_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "copy_failed | save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/watermark": {
      "post": {
        "operationId": "watermarkPdf",
        "summary": "Add a text watermark to a PDF",
        "description": "Stamps text on every page or the selected pages, upright for any page size and existing rotation. Text is limited to standard Helvetica (Latin-1). Output is byte-deterministic.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "text": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "Watermark text."
                  },
                  "opacity": {
                    "type": "number",
                    "minimum": 0.05,
                    "maximum": 1,
                    "default": 0.15
                  },
                  "size": {
                    "type": "number",
                    "minimum": 6,
                    "maximum": 200,
                    "default": 48,
                    "description": "Font size in points."
                  },
                  "color": {
                    "type": "string",
                    "default": "#808080",
                    "description": "Hex colour, #rgb or #rrggbb."
                  },
                  "rotation": {
                    "type": "number",
                    "minimum": -360,
                    "maximum": 360,
                    "default": 45,
                    "description": "Degrees counter-clockwise as the viewer sees it."
                  },
                  "position": {
                    "type": "string",
                    "enum": [
                      "center",
                      "top",
                      "bottom"
                    ],
                    "default": "center"
                  },
                  "pages": {
                    "type": "string",
                    "description": "1-based page list such as `1-3,5` or `4-`. Items are N, A-B or A-. Default: all pages."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf",
                  "text"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The watermarked PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages | missing_text | text_too_long | unsupported_characters | invalid_parameter | invalid_pages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/page-numbers": {
      "post": {
        "operationId": "addPageNumbers",
        "summary": "Add page numbers to a PDF",
        "description": "Stamps a label on every page or the selected pages. `{n}` is the page number (start + page index), `{total}` is the page count of the whole document. Output is byte-deterministic.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "format": {
                    "type": "string",
                    "maxLength": 100,
                    "default": "{n} / {total}"
                  },
                  "position": {
                    "type": "string",
                    "enum": [
                      "bottom-center",
                      "bottom-right",
                      "bottom-left",
                      "top-center",
                      "top-right",
                      "top-left"
                    ],
                    "default": "bottom-center"
                  },
                  "size": {
                    "type": "number",
                    "minimum": 4,
                    "maximum": 72,
                    "default": 10,
                    "description": "Font size in points."
                  },
                  "start": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 100000,
                    "default": 1,
                    "description": "Number shown on page 1 of the document."
                  },
                  "margin": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 200,
                    "default": 24,
                    "description": "Points from the displayed page edge."
                  },
                  "pages": {
                    "type": "string",
                    "description": "1-based page list such as `1-3,5` or `4-`. Items are N, A-B or A-. Default: all pages."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The numbered PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages | format_too_long | unsupported_characters | invalid_parameter | invalid_pages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/unlock": {
      "post": {
        "operationId": "unlockPdf",
        "summary": "Remove restrictions from a PDF",
        "description": "Saves the PDF without encryption, so print, copy and modify restrictions are gone. Does not crack passwords. Output is byte-deterministic.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "password": {
                    "type": "string",
                    "description": "Needed only for a PDF that asks for a password to open."
                  }
                },
                "required": [
                  "pdf"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The unencrypted PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "x-pdfops-note": {
                "schema": {
                  "type": "string"
                },
                "description": "`not-encrypted` when the input had no encryption and was returned re-saved"
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/protect": {
      "post": {
        "operationId": "protectPdf",
        "summary": "Password-protect a PDF",
        "description": "Encrypts the PDF with an open password, an owner password, or both. Restrictions only bind a viewer when an owner password is set. The output is always AES-128 (PDF 1.7), whatever the input's header version. Not byte-deterministic: encryption uses random salts.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "user_password": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 32,
                    "pattern": "^[\\u0020-\\u00ff]+$",
                    "description": "Password needed to open the output. 1 to 32 Latin-1 characters (U+0020 to U+00FF); anything else is rejected with invalid_password."
                  },
                  "owner_password": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 32,
                    "pattern": "^[\\u0020-\\u00ff]+$",
                    "description": "Password that lifts the permission restrictions. 1 to 32 Latin-1 characters (U+0020 to U+00FF); anything else is rejected with invalid_password."
                  },
                  "permissions": {
                    "type": "string",
                    "description": "Comma list of what stays allowed: print, copy, modify, annotate, fill-forms. Default: all allowed, except modify when owner_password is set. Empty allows none."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The encrypted PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages | missing_password | invalid_password | invalid_permissions | encrypt_failed (500)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "encrypt_failed | save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/metadata": {
      "post": {
        "operationId": "getPdfMetadata",
        "summary": "Read PDF properties",
        "description": "Returns page count, page sizes, Info fields, dates, encryption status and form field count. Read-only.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "PDF properties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PdfMetadata"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/set-metadata": {
      "post": {
        "operationId": "setPdfMetadata",
        "summary": "Set PDF title, author and keywords",
        "description": "Writes any of the five Info fields; at least one is required. The output is unencrypted. Output is byte-deterministic.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary",
                    "description": "One PDF, up to 4 MB and 2,000 pages."
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "author": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "subject": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "keywords": {
                    "type": "string",
                    "maxLength": 1000,
                    "description": "Comma list; items are trimmed and empty ones dropped."
                  },
                  "creator": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "password": {
                    "type": "string",
                    "description": "Password that opens the PDF, for user-password-encrypted inputs. Owner-locked files with an empty user password (most government blanks) open without it."
                  }
                },
                "required": [
                  "pdf"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_multipart | missing_pdf | pdf_too_large | invalid_pdf | encrypted_pdf | decompressed_too_large | too_many_pages | no_fields | field_too_long",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "save_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (body over 4.5 MB, the Vercel platform limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/signup": {
      "post": {
        "operationId": "signup",
        "summary": "Get a free API key (emailed)",
        "description": "The key (250 requests/month) is EMAILED to the address, never returned in the response — inbox possession doubles as verification. Re-signup rotates: the previous key is revoked and a fresh one is issued (this is also lost-key recovery). 5 signups/IP/day.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                },
                "required": [
                  "email"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Key issued and emailed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_json | invalid_email",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited — 5 signups/IP/day",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "issue_failed | email_failed (the key is revoked on send failure — safe to retry)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Current quota state for your API key",
        "description": "`used` reads the same counter enforcement increments — by construction the number the 429 fires on. Does not consume quota.",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Quota state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "description": "missing_api_key | invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "operationId": "health",
        "summary": "Liveness + dependency probe",
        "responses": {
          "200": {
            "description": "Healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "turso": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Persistence down"
          }
        }
      }
    },
    "/api/invoice": {
      "post": {
        "operationId": "generateInvoice",
        "summary": "Generate a complete invoice PDF from structured data — no template needed",
        "description": "Deterministic: the same request body produces byte-identical PDF bytes (metadata dates are pinned to the invoice date), so re-rendering from webhooks/crons is idempotent. Anonymous and free-tier output carries a small 'Generated with pdfops.dev' footer line; Indie/Pro output is clean.",
        "security": [
          {
            "ApiKey": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "from": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "$ref": "#/components/schemas/InvoiceParty"
                      }
                    ]
                  },
                  "to": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "$ref": "#/components/schemas/InvoiceParty"
                      }
                    ]
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "$ref": "#/components/schemas/InvoiceItem"
                    }
                  },
                  "invoice_number": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                    "description": "YYYY-MM-DD. Shown verbatim; also pins the PDF metadata dates to 00:00 UTC (determinism)"
                  },
                  "due": {
                    "type": "string"
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$",
                    "default": "USD"
                  },
                  "tax_rate": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 100,
                    "description": "Percent"
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 1000
                  }
                },
                "required": [
                  "from",
                  "to",
                  "items"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The invoice PDF (US Letter, auto-paginating)",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "invalid_json | invalid_body | invalid_from | invalid_to | invalid_items | invalid_currency | invalid_tax_rate | invalid_date | unrenderable_text",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "request_too_large (multipart endpoints: body over 4.5 MB, the Vercel platform limit; /api/invoice: over 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_api_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (Retry-After header set)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
