{
  "openapi": "3.1.0",
  "info": {
    "title": "rc-doc API",
    "version": "0.1.0",
    "description": "Document parsing: PDF or image in, markdown and layout blocks out."
  },
  "servers": [
    {
      "url": "https://api.roughconsensus.com"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/v1/parse": {
      "post": {
        "operationId": "parse",
        "summary": "Parse a document",
        "description": "Synchronous. Send the document as the raw body, as a multipart `file` field, or as a JSON `url`. Request bodies are limited to 4.5 MB; use `url` for larger documents.",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Document URL, as an alternative to a body."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "https only, public host, no redirects, at most 100 MB."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Parsed document",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ParseResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "health",
        "security": [],
        "responses": {
          "200": {
            "description": "`ok`",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "error"
              ],
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "ParseResult": {
        "type": "object",
        "required": [
          "markdown",
          "pages",
          "usage"
        ],
        "properties": {
          "markdown": {
            "type": "string",
            "description": "All pages, joined by blank lines. Tables are HTML."
          },
          "pages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Page"
            }
          },
          "usage": {
            "type": "object",
            "required": [
              "pages",
              "seconds"
            ],
            "properties": {
              "pages": {
                "type": "integer"
              },
              "seconds": {
                "type": "number",
                "description": "Server-side wall time."
              }
            }
          }
        }
      },
      "Page": {
        "type": "object",
        "required": [
          "page",
          "markdown"
        ],
        "properties": {
          "page": {
            "type": "integer",
            "description": "1-based page index in the file."
          },
          "markdown": {
            "type": "string",
            "description": "Page body without running headers, footers and page numbers."
          },
          "printed_page": {
            "type": [
              "string",
              "null"
            ],
            "description": "Page number printed on the page, when found."
          },
          "degraded": {
            "type": "boolean",
            "description": "Present and true when the page was read with reduced quality."
          },
          "layout": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LayoutBlock"
            }
          }
        }
      },
      "LayoutBlock": {
        "type": "object",
        "required": [
          "label",
          "bbox",
          "content"
        ],
        "properties": {
          "label": {
            "type": "string",
            "enum": [
              "Caption",
              "Footnote",
              "Formula",
              "List-item",
              "Page-footer",
              "Page-header",
              "Picture",
              "Section-header",
              "Table",
              "Text",
              "Title"
            ]
          },
          "bbox": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "minItems": 4,
            "maxItems": 4,
            "description": "[x, y, width, height] as fractions of the page, origin top-left."
          },
          "content": {
            "type": "string",
            "description": "Markdown; HTML for tables."
          }
        }
      }
    }
  }
}
