EasyDoc Documentation

repository·main·Indexed 22 days ago

https://github.com/easydoc-ai/easydoc

A multimodal document processing API that converts unstructured documents (PDF, Word, PPT, etc.) into structured, hierarchical JSON for LLM pipelines. Features include asynchronous parsing via POST /api/v1/parse, result retrieval via GET /api/v1/parse/{task_id}/result, and multiple parsing modes (lite, pro, premium) to balance speed and accuracy.

Tokens
3.3K
Snippets
11
Records
19
Agent score
78%

What's inside EasyDoc

  1. Configure parsing mode and page ranges

    main

    When interacting with the EasyDoc API, you can customize the parsing behavior using the following parameters:

    • mode: Controls the balance between parsing speed and accuracy. Supported values are lite, pro, and premium.
    • start_page and end_page: Allows you to specify a subset of the document to parse instead of the entire file.
  2. Convert Parsed JSON Data to Markdown

    main

    Once you have retrieved the JSON result, you can transform it into Markdown by following these steps:

    1. Build a Tree Structure: The raw JSON contains a flat list of nodes with parent_id references. Use a recursive function to build a hierarchical tree.
    2. Define Parsing Rules: Create a function to map node types (e.g., Text, Title, Table, Figure) to Markdown syntax.
    3. Flatten the Tree: Recursively traverse the tree to generate a single Markdown string.

    Implementation Example

    def rule(node, depth):
        txt = ""
        if node["type"] == "Text":
            txt = node["text"]
        elif node["type"] == "Title":
            title_level = "#" * depth
            txt = f"{title_level} {node['text']}"
        elif node["type"] in ("Table", "Figure"):
            txt = f"\n```{'table' if node['type'] == 'Table' else 'figure'}\n"
            txt += node.get("vlm_understanding", node["text"]) + "\n```\n"
        return f"\n{txt}\n"
    
    def tree_flat(tree, depth=1):
        rst = ""
        for node in tree:
            rst += rule(node, depth)
            if node.get("type") == "Title":
                rst += tree_flat(node["children"], depth + 1)
        return rst
    
    def build_tree(nodes, parent_id=-1):
        tree = []
        for node in nodes:
            if node["parent_id"] == parent_id:
                children = build_tree(nodes, node["id"])
                node["children"] = children
                tree.append(node)
        return tree
    
    # Usage:
    # 1. Build tree from JSON
    tree = build_tree(json_data.get("data", {}).get("task_result", {}).get("nodes", []))
    # 2. Convert to Markdown
    rst = tree_flat(tree)
    print(rst)
  3. Obtain an EasyDoc API Key

    main

    To use the EasyDoc REST API, you must first generate an API key from the official dashboard:

    1. Log in to EASYDOC.
    2. Navigate to API Keys in the left-hand menu.
    3. Click Create API Key to generate your credentials.

    Use this key in the api-key header for all subsequent API requests.

    APIKEY = "your API key here"
  4. Troubleshoot parsing result API errors

    main

    If a request fails, the API returns a 200 OK status but with "success": false. Use the errCode to identify and resolve the issue.

    Error CodeDescriptionRecommended Action
    API_UNAUTHORIZEDAPI key validation failed.Verify your api-key is correct and included in the headers.
    INVALID_PARAMETERMissing or invalid values.Check documentation for required parameters and validate your request.
    INTERNAL_SERVER_ERRORUnknown system error.Retry the request after a short interval; contact support if it persists.
    INSUFFICIENT_RESOURCESSystem resources (CPU/RAM/Storage) are low.Reduce request size/complexity or contact support.
    INVALID_DOCUMENT_FORMATUnsupported or unprocessable file format.Ensure the file follows supported formats; convert the file if necessary.
    {
        "success": false,
        "errCode": "CONSOLE_UNAUTHORIZED",
        "errMessage": "Unauthorized access to API service"
    }
  5. Troubleshoot parse API error codes

    main

    If success is false, check the err_code to identify the issue:

    Error CodeError MessageDescription
    API_UNAUTHORIZEDUnauthorized access to API serviceAPI key validation failed.
    INVALID_PARAMETERInvalid parameter.General parameter error, including missing or invalid values.
    INTERNAL_SERVER_ERRORInternal server error.Triggered when the system encounters an unknown error.
    INSUFFICIENT_RESOURCESInsufficient resources.Triggered when system resources (CPU, memory, or storage) are insufficient.
    INVALID_DOCUMENT_FORMATInvalid document format.Triggered when the uploaded file format is not supported or cannot be processed.
  6. Upload and parse a file using the Python example script

    main

    The upload_and_parse.py script demonstrates a complete workflow: uploading a file to create a parsing task, polling the API for status updates, and retrieving the final result.

    Run the script from the examples/ directory:

    python upload_and_parse.py

    Workflow details:

    • Upload: Sends a file to the API to initiate a task.
    • Polling: Checks the task status (e.g., PENDING, PROGRESSING) until completion.
    • Retrieval: Prints the JSON parsing result once the task is finished.
  7. Retrieve parsing results with GET api/v1/parse/{task_id}/result

    main

    Once a parsing task has been created, use the GET api/v1/parse/{task_id}/result endpoint to fetch the structured JSON output.

    Request Details

    • Endpoint: https://api.easydoc.sh/api/v1/parse/{task_id}/result
    • Authentication: Pass your key in the api-key header.
    • Path Parameter:
      • {task_id}: The unique ID returned by the initial POST api/v1/parse request.

    Response

    When the task is complete, the response contains the parsed document data (titles, chapters, paragraphs, lists, tables, and charts).

    curl "https://api.easydoc.sh/api/v1/parse/{task_id}/result"  \\
    -X GET \
    -H "api-key: your-api-key"
  8. Create a parsing task with POST api/v1/parse

    main

    Use the POST api/v1/parse endpoint to upload a file and initiate a document parsing task. This converts unstructured documents into structured JSON data.

    Request Details

    • Endpoint: https://api.easydoc.sh/api/v1/parse
    • Authentication: Pass your key in the api-key header.
    • Supported File Types:
      • PDF (.pdf)
      • Text (.txt)
      • Word (.docx, .doc)
      • PowerPoint (.pptx, .ppt)
    • File Size Limit: 100 MB per file.
    • Parameters:
      • file: The document to be parsed.
      • mode: The parsing mode (e.g., lite for faster processing).

    Response

    Upon success, the API returns a task_id. You must use this ID to retrieve the results later.

    curl https://api.easydoc.sh/api/v1/parse \
    -X POST \
    -H "api-key: your-api-key" \
    -F "file=@demo_document.pdf" \
    -F "mode=lite"
  9. Retrieve a parsing task result via GET /api/v1/parse/{task_id}/result

    main

    Use the GET /api/v1/parse/{task_id}/result endpoint to fetch the outcome of a previously initiated parsing task. You must provide the unique task_id in the URL path and include your api-key in the request headers for authentication.

    Path Parameter:

    • task_id (String): The unique identifier of the parsing task.

    Required Header:

    • api-key (String): Your valid API key.
    curl -X GET "https://api.easydoc.sh/api/v1/parse/{task_id}/result" \
      -H "api-key: your-api-key"