{
  "openapi": "3.1.0",
  "info": {
    "title": "html-pdf.com API",
    "version": "1.0.0",
    "description": "HTML to PDF. 1 credit = 1 PDF page. 100 free credits on signup; credits never expire.",
    "contact": {
      "url": "https://html-pdf.com/docs"
    }
  },
  "servers": [
    {
      "url": "https://html-pdf.com"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key hp_live_..."
      }
    },
    "schemas": {
      "PDFOptions": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Public http(s) page to render instead of html."
          },
          "html": {
            "type": "string",
            "description": "Full HTML document or fragment."
          },
          "css": {
            "type": "string"
          },
          "format": {
            "type": "string",
            "enum": [
              "A3",
              "A4",
              "A5",
              "A6",
              "Letter",
              "Legal",
              "Tabloid"
            ],
            "default": "A4"
          },
          "width": {
            "type": "string",
            "examples": [
              "210mm"
            ]
          },
          "height": {
            "type": "string",
            "examples": [
              "297mm"
            ]
          },
          "landscape": {
            "type": "boolean",
            "default": false
          },
          "margin": {
            "oneOf": [
              {
                "type": "string",
                "examples": [
                  "10mm"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "top": {
                    "type": "string"
                  },
                  "right": {
                    "type": "string"
                  },
                  "bottom": {
                    "type": "string"
                  },
                  "left": {
                    "type": "string"
                  }
                }
              }
            ]
          },
          "print_background": {
            "type": "boolean",
            "default": true
          },
          "prefer_css_page_size": {
            "type": "boolean",
            "default": false
          },
          "scale": {
            "type": "number",
            "minimum": 0.1,
            "maximum": 2
          },
          "page_ranges": {
            "type": "string",
            "examples": [
              "1-3, 5"
            ]
          },
          "header_html": {
            "type": "string"
          },
          "footer_html": {
            "type": "string"
          },
          "media": {
            "type": "string",
            "enum": [
              "print",
              "screen"
            ]
          },
          "wait_delay": {
            "type": "number",
            "minimum": 0,
            "maximum": 10
          },
          "wait_for_expression": {
            "type": "string"
          },
          "max_pages": {
            "type": "integer",
            "minimum": 1
          },
          "filename": {
            "type": "string"
          },
          "response": {
            "type": "string",
            "enum": [
              "binary",
              "base64",
              "url"
            ],
            "default": "binary"
          }
        },
        "oneOf": [
          {
            "required": [
              "html"
            ]
          },
          {
            "required": [
              "url"
            ]
          }
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "docs_url": {
                "type": "string"
              },
              "top_up_url": {
                "type": "string"
              }
            }
          }
        }
      },
      "AutoTopup": {
        "type": "object",
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "threshold": {
            "type": "integer"
          },
          "pack": {
            "type": "object",
            "properties": {
              "usd": {
                "type": "integer"
              },
              "credits": {
                "type": "integer"
              }
            }
          },
          "card": {
            "type": [
              "string",
              "null"
            ],
            "description": "Saved card label, null before the first purchase"
          },
          "settings_url": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/v1/pdf": {
      "post": {
        "operationId": "htmlToPdf",
        "summary": "Convert HTML or a URL to PDF",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PDFOptions"
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "index.html": {
                    "type": "string",
                    "format": "binary"
                  },
                  "options": {
                    "type": "string",
                    "description": "PDFOptions as JSON (without html)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "PDF (binary), or JSON when response is base64 or url",
            "headers": {
              "X-Pages": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-Credits-Used": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-Credits-Remaining": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-Conversion-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "No credits left, or the PDF has more pages than the balance (error includes pages and balance). Nothing is charged. The error includes checkout_url, a ready Stripe payment link for a pack sized to recent usage (checkout_pack).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "email_not_confirmed: open the emailed link to confirm the email and unlock the free credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Render failed (not charged)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Busy (not charged)"
          }
        }
      }
    },
    "/v1/credits": {
      "get": {
        "operationId": "getCredits",
        "summary": "Credit balance",
        "responses": {
          "200": {
            "description": "Balance",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance": {
                      "type": "integer"
                    },
                    "used_total": {
                      "type": "integer"
                    },
                    "auto_topup": {
                      "$ref": "#/components/schemas/AutoTopup"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/conversions": {
      "get": {
        "operationId": "listConversions",
        "summary": "Recent conversions",
        "responses": {
          "200": {
            "description": "List"
          }
        }
      }
    },
    "/v1/signup": {
      "post": {
        "operationId": "signup",
        "summary": "Create an account and get an API key (100 free credits once the email is confirmed)",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_key": {
                      "type": "string"
                    },
                    "credits": {
                      "type": "integer",
                      "description": "0 until the email is confirmed"
                    },
                    "pending_credits": {
                      "type": "integer",
                      "description": "Free credits added when the owner opens the emailed link"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Account exists; login link emailed"
          }
        }
      }
    },
    "/v1/keys": {
      "post": {
        "operationId": "createKey",
        "summary": "Create an additional API key",
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/v1/checkout": {
      "post": {
        "operationId": "createCheckout",
        "summary": "Get a Stripe payment link for a credit pack",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "usd": {
                    "type": "integer",
                    "enum": [
                      10,
                      25,
                      50,
                      100,
                      250
                    ],
                    "default": 10
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout link",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "checkout_url": {
                      "type": "string"
                    },
                    "usd": {
                      "type": "integer"
                    },
                    "credits": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Payments not enabled"
          }
        }
      }
    },
    "/v1/autotopup": {
      "post": {
        "operationId": "setAutoTopup",
        "summary": "Turn auto top-up on or off (needs a card saved by a first purchase; the owner is emailed)",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  },
                  "threshold": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "At most the pack size (credits of the usd pack)"
                  },
                  "usd": {
                    "type": "integer",
                    "enum": [
                      10,
                      25,
                      50,
                      100,
                      250
                    ]
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current auto top-up settings",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "auto_topup": {
                      "$ref": "#/components/schemas/AutoTopup"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_json, invalid_threshold or invalid_usd",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "no_saved_card: buy once via checkout_url first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "More than 10 changes per hour"
          },
          "503": {
            "description": "Payments not enabled"
          }
        }
      }
    }
  }
}
