{
  "openapi": "3.1.0",
  "info": {
    "title": "PDF Inspector API",
    "version": "1.0.0",
    "summary": "Convert any PDF to clean, LLM-ready Markdown. Scanned pages are OCR'd automatically. Zero data retention.",
    "description": "Hosted API built on the open-source pdf-inspector library by Firecrawl (MIT). Independent service, not affiliated with Firecrawl. Without a key, one test call per day is allowed (up to 10 text pages, no OCR). Agents can create a key with POST /v1/keys; it works once the user buys credits. LLM-friendly docs: https://pdfinspector.com/llms.txt",
    "contact": {
      "email": "hello@pdfinspector.com",
      "url": "https://pdfinspector.com/docs/"
    }
  },
  "servers": [
    {
      "url": "https://api.pdfinspector.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    },
    {}
  ],
  "paths": {
    "/v1/convert": {
      "post": {
        "operationId": "convertPdf",
        "summary": "Convert a PDF to Markdown",
        "description": "Send a PDF file, URL or base64 string. Returns 200 with the result for up to 50 pages, or 202 with a job for larger files or when webhook_url is set. Send 'Accept: text/markdown' to get only the Markdown as plain text. Without a key, one test call per day is allowed (up to 10 text pages, no OCR).",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The PDF. Max 50 MB."
                  },
                  "pages": {
                    "type": "string",
                    "description": "1-indexed page selection",
                    "example": "1-3,7"
                  },
                  "ocr": {
                    "type": "string",
                    "enum": [
                      "auto",
                      "off",
                      "force"
                    ],
                    "default": "auto"
                  },
                  "per_page": {
                    "type": "boolean",
                    "default": false
                  },
                  "webhook_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConvertJsonRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Converted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Conversion"
                }
              },
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "202": {
            "description": "Accepted as a job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/md/{pdfUrl}": {
      "get": {
        "operationId": "markdownFromUrl",
        "summary": "Markdown shortcut: append a PDF URL, get plain Markdown",
        "description": "GET https://api.pdfinspector.com/md/https://example.com/report.pdf returns text/markdown. Works with any HTTP or web-fetch tool. Optional key via Authorization header or ?key= query parameter (use the header when possible). Without a key, one test call per day is allowed.",
        "parameters": [
          {
            "name": "pdfUrl",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Full URL of the PDF, including https://"
          },
          {
            "name": "pages",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ocr",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "auto",
                "off",
                "force"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Markdown",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/inspect": {
      "post": {
        "operationId": "inspectPdf",
        "summary": "Classify a PDF without converting it (uses no credits)",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "file_base64": {
                    "type": "string",
                    "contentEncoding": "base64"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Classification",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Inspection"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/text-items": {
      "post": {
        "operationId": "getTextItems",
        "summary": "Positioned text runs for pages with real text (no OCR)",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  },
                  "pages": {
                    "type": "string"
                  }
                }
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "file_base64": {
                    "type": "string"
                  },
                  "pages": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Text items",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TextItem"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/jobs/{id}": {
      "get": {
        "operationId": "getJob",
        "summary": "Get a long-document job (result is deleted after the first successful fetch or 1 hour)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/keys": {
      "post": {
        "operationId": "createKey",
        "summary": "Create an API key (no auth required)",
        "description": "Designed for AI agents. Returns a secret key immediately with 0 credits and a checkout_url. The key works once the user buys credits there. If an email is given, the checkout link is also sent to it.",
        "security": [],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Owner's email. Receives the checkout link."
                  },
                  "name": {
                    "type": "string",
                    "description": "Label, e.g. the project name."
                  },
                  "agent": {
                    "type": "string",
                    "description": "Which agent or tool created the key, e.g. 'claude-code'."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Key created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NewKey"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Current plan and credit balance for the key (or anonymous allowance)",
        "responses": {
          "200": {
            "description": "Usage",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "sk_ secret keys (server only) or pk_ publishable keys (browser, origin-restricted). Optional: without a key, the anonymous allowance applies."
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "ConvertJsonRequest": {
        "type": "object",
        "description": "Provide exactly one of url or file_base64.",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "file_base64": {
            "type": "string",
            "contentEncoding": "base64"
          },
          "pages": {
            "type": "string",
            "example": "1-3,7"
          },
          "ocr": {
            "type": "string",
            "enum": [
              "auto",
              "off",
              "force"
            ],
            "default": "auto"
          },
          "per_page": {
            "type": "boolean",
            "default": false
          },
          "webhook_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Metadata": {
        "type": "object",
        "properties": {
          "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"
            ],
            "description": "As written in the PDF, e.g. D:20240115103000+01'00'"
          },
          "mod_date": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "PdfType": {
        "type": "string",
        "enum": [
          "text_based",
          "scanned",
          "image_based",
          "mixed"
        ]
      },
      "Conversion": {
        "type": "object",
        "properties": {
          "pdf_type": {
            "$ref": "#/components/schemas/PdfType"
          },
          "confidence": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "page_count": {
            "type": "integer"
          },
          "markdown": {
            "type": "string",
            "description": "Main output. Tables are GFM Markdown tables."
          },
          "pages_ocr": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "Pages whose text came from OCR"
          },
          "pages_needing_ocr": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "Scanned pages that were not OCR'd (ocr: off, or anonymous calls)"
          },
          "pages_with_tables": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "pages_with_columns": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "has_encoding_issues": {
            "type": "boolean"
          },
          "metadata": {
            "$ref": "#/components/schemas/Metadata"
          },
          "pages": {
            "type": "array",
            "description": "Only with per_page: true",
            "items": {
              "type": "object",
              "properties": {
                "page": {
                  "type": "integer"
                },
                "markdown": {
                  "type": "string"
                },
                "source": {
                  "type": "string",
                  "enum": [
                    "native",
                    "ocr"
                  ]
                }
              }
            }
          },
          "processing_time_ms": {
            "type": "integer"
          },
          "usage": {
            "type": "object",
            "properties": {
              "pages": {
                "type": "integer",
                "description": "Regular pages, 1 credit each"
              },
              "ocr_pages": {
                "type": "integer",
                "description": "OCR pages, 15 credits each"
              },
              "credits_used": {
                "type": "integer"
              },
              "credits_remaining": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "null for anonymous calls"
              }
            }
          },
          "notices": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Human/agent-readable hints, e.g. that scanned pages were skipped because the call had no key."
          }
        }
      },
      "Inspection": {
        "type": "object",
        "properties": {
          "pdf_type": {
            "$ref": "#/components/schemas/PdfType"
          },
          "confidence": {
            "type": "number"
          },
          "page_count": {
            "type": "integer"
          },
          "pages_needing_ocr": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "pages_with_tables": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "pages_with_columns": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "is_complex_layout": {
            "type": "boolean"
          },
          "has_encoding_issues": {
            "type": "boolean"
          },
          "metadata": {
            "$ref": "#/components/schemas/Metadata"
          }
        }
      },
      "TextItem": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string"
          },
          "page": {
            "type": "integer"
          },
          "x": {
            "type": "number"
          },
          "y": {
            "type": "number"
          },
          "width": {
            "type": "number"
          },
          "height": {
            "type": "number"
          },
          "rotation": {
            "type": "number"
          },
          "font": {
            "type": "string"
          },
          "font_size": {
            "type": "number"
          },
          "is_bold": {
            "type": "boolean"
          },
          "is_italic": {
            "type": "boolean"
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "processing",
              "completed",
              "failed"
            ]
          },
          "result": {
            "$ref": "#/components/schemas/Conversion"
          },
          "error": {
            "$ref": "#/components/schemas/ErrorBody"
          }
        }
      },
      "NewKey": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "description": "sk_live_... Shown once. Store it as PDFINSPECTOR_API_KEY."
          },
          "credits_remaining": {
            "type": "integer",
            "description": "0 until credits are bought"
          },
          "checkout_url": {
            "type": "string",
            "format": "uri",
            "description": "Give this to the human to buy credits."
          },
          "dashboard_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Usage": {
        "type": "object",
        "description": "1 page = 1 credit; 1 OCR page = 15 credits. Monthly (subscription) credits are used first and do not roll over; pack credits expire 12 months after purchase.",
        "properties": {
          "plan": {
            "type": "string",
            "enum": [
              "anonymous",
              "credits",
              "builder",
              "scale"
            ]
          },
          "credits_remaining": {
            "type": "integer",
            "description": "Monthly + pack credits available now"
          },
          "monthly_credits": {
            "type": "integer"
          },
          "monthly_credits_remaining": {
            "type": "integer"
          },
          "monthly_resets_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "pack_credits_remaining": {
            "type": "integer"
          },
          "pack_credits_expire_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "anonymous_pages_remaining_today": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Only for calls without a key"
          },
          "buy_credits_url": {
            "type": "string",
            "format": "uri",
            "description": "Checkout link for a human"
          }
        }
      },
      "ErrorBody": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string",
            "description": "Human- and agent-readable. Safe to show to end users."
          },
          "next_action": {
            "type": "object",
            "description": "What an agent should do to fix it.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "create_key",
                  "buy_credits",
                  "retry_after",
                  "fix_request"
                ]
              },
              "method": {
                "type": "string"
              },
              "url": {
                "type": "string",
                "format": "uri"
              },
              "retry_after_seconds": {
                "type": "integer"
              }
            }
          },
          "docs": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorBody"
          }
        }
      }
    }
  }
}
