{
  "openapi": "3.1.0",
  "info": {
    "title": "DocuParse API",
    "version": "1.0.0",
    "summary": "Extract structured JSON from receipts, invoices, and business PDFs.",
    "description": "Submit a document to POST /extract, then take delivery of the result via webhook or GET /documents/{document_id}. Billed per document regardless of page count.",
    "contact": {
      "name": "DocuParse Support",
      "url": "https://docuparseapi.com/docs"
    },
    "termsOfService": "https://docuparseapi.com/terms"
  },
  "servers": [
    {
      "url": "https://docuparseapi.com/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/extract": {
      "post": {
        "operationId": "extractDocument",
        "summary": "Submit a receipt or invoice for extraction",
        "description": "Accepts PDF, JPG, PNG, or CSV up to 10 MB. Returns a document_id. Take delivery of the extracted fields via webhook or GET /documents/{document_id}. Counts as one document against your monthly quota.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "PDF, JPG, PNG, or CSV. Maximum 10 MB."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document accepted for extraction",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubmitResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/AuthError"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/QuotaError"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/documents/{document_id}": {
      "get": {
        "operationId": "getDocument",
        "summary": "Retrieve an extraction result",
        "parameters": [
          {
            "name": "document_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The document_id returned by POST /extract"
          }
        ],
        "responses": {
          "200": {
            "description": "Current state of the document",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/AuthError"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    }
  },
  "webhooks": {
    "extractionCompleted": {
      "post": {
        "summary": "Fired when a document finishes extraction successfully",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentResponse"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "extractionFailed": {
      "post": {
        "summary": "Fired when extraction fails for a document",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ErrorResponse"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "batchCompleted": {
      "post": {
        "summary": "Fired once when a batch upload finishes",
        "responses": {
          "200": {
            "description": "Acknowledged"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key with the dex_ prefix. Server-side only."
      }
    },
    "schemas": {
      "SubmitResponse": {
        "type": "object",
        "required": [
          "success",
          "document_id",
          "status"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "const": true
          },
          "document_id": {
            "type": "string",
            "examples": [
              "doc_9f3c1b7a4e"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued"
            ]
          },
          "message": {
            "type": "string"
          }
        }
      },
      "DocumentResponse": {
        "type": "object",
        "required": [
          "success",
          "document_id",
          "status"
        ],
        "properties": {
          "success": {
            "type": "boolean"
          },
          "document_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "completed",
              "failed"
            ]
          },
          "data": {
            "$ref": "#/components/schemas/ExtractedData"
          },
          "error": {
            "$ref": "#/components/schemas/ErrorDetail"
          }
        }
      },
      "ExtractedData": {
        "type": "object",
        "description": "Normalized fields. Monetary values are decimal strings.",
        "properties": {
          "document_type": {
            "type": "string",
            "enum": [
              "receipt",
              "invoice",
              "purchase_order",
              "expense_report",
              "unknown"
            ]
          },
          "invoice_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "receipt_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "due_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "examples": [
              "USD"
            ]
          },
          "merchant": {
            "type": [
              "string",
              "null"
            ]
          },
          "merchant_address": {
            "type": [
              "string",
              "null"
            ]
          },
          "merchant_email": {
            "type": [
              "string",
              "null"
            ]
          },
          "customer": {
            "type": [
              "string",
              "null"
            ]
          },
          "subtotal": {
            "type": [
              "string",
              "null"
            ]
          },
          "tax": {
            "type": [
              "string",
              "null"
            ]
          },
          "tax_rate": {
            "type": [
              "string",
              "null"
            ]
          },
          "discount": {
            "type": [
              "string",
              "null"
            ]
          },
          "total": {
            "type": [
              "string",
              "null"
            ]
          },
          "payment_method": {
            "type": [
              "string",
              "null"
            ]
          },
          "line_items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "description": {
                  "type": "string"
                },
                "quantity": {
                  "type": "number"
                },
                "price": {
                  "type": "string"
                },
                "line_total": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "vat_rate": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          },
          "shipping": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "confidence": {
            "type": [
              "number",
              "null"
            ],
            "description": "Worker quality score from 0 to 100, or null."
          },
          "needs_review": {
            "type": "boolean",
            "description": "Whether the extraction should be manually reviewed."
          },
          "document_number": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ErrorDetail": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "MISSING_API_KEY",
              "INVALID_API_KEY",
              "REVOKED_API_KEY",
              "LIMIT_EXCEEDED",
              "UNSUPPORTED_FILE_TYPE",
              "FILE_TOO_LARGE_AUTHENTICATED",
              "NO_FILE_PROVIDED",
              "EXTRACTION_FAILED",
              "INTERNAL_ERROR"
            ]
          },
          "message": {
            "type": "string"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "const": false
          },
          "document_id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "error": {
            "$ref": "#/components/schemas/ErrorDetail"
          }
        }
      }
    },
    "responses": {
      "AuthError": {
        "description": "MISSING_API_KEY, INVALID_API_KEY, or REVOKED_API_KEY",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "ValidationError": {
        "description": "UNSUPPORTED_FILE_TYPE, FILE_TOO_LARGE_AUTHENTICATED, or NO_FILE_PROVIDED",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "QuotaError": {
        "description": "LIMIT_EXCEEDED \u2014 monthly document quota reached",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "ServerError": {
        "description": "EXTRACTION_FAILED or INTERNAL_ERROR",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    }
  }
}
