← Back to blog
·7 min read

Dify + Lekha: Build Financial Document Workflows

Connect Lekha to Dify to build no-code AI workflows that parse Indian bank statements, salary slips, and ITRs without writing backend code.

difyai workflowfinancial document parsingbank statementai agentno codeindian fintechdocument automation

Dify is one of the most popular open-source LLM application platforms today. It lets you wire together AI models, tools, and APIs through a visual canvas — no backend code required. If you're building a loan origination workflow, a KYC pipeline, or an income verification bot, connecting Dify to Lekha gets you structured financial data from Indian documents in minutes.

This guide walks through setting up Lekha as a custom API tool in Dify and building a complete bank statement analysis workflow from scratch.

What You'll Build

By the end of this guide you'll have a Dify workflow that:

  • Accepts a bank statement PDF as input (from a form, webhook, or chatbot)
  • Calls Lekha to extract structured JSON — transactions, balances, income signals
  • Passes the extracted data to an LLM for analysis
  • Returns a human-readable credit summary to your app or chatbot
  • No custom server code needed.

    Prerequisites

  • A Dify account (self-hosted or Dify Cloud at dify.ai)
  • A Lekha API key — get one at lekhadev.com
  • A bank statement PDF for testing (any major Indian bank)
  • Step 1: Register Lekha as a Custom Tool in Dify

    Dify supports any REST API as a custom tool via its OpenAPI schema importer. The Lekha extract endpoint is a single POST call, so the schema is minimal.

    Go to Tools → Custom → Create Tool in your Dify dashboard and paste this schema:

    openapi: 3.0.0
    info:
      title: Lekha Financial Document API
      version: 1.0.0
    servers:
      - url: https://lekhadev.com/api/v1
    paths:
      /extract:
        post:
          operationId: extractDocument
          summary: Extract structured data from an Indian financial document
          requestBody:
            required: true
            content:
              multipart/form-data:
                schema:
                  type: object
                  properties:
                    file:
                      type: string
                      format: binary
                      description: PDF or image of the financial document
                  required:
                    - file
          responses:
            "200":
              description: Extracted document data as structured JSON
    

    Under Authentication, select API Key and enter:

  • Header name: x-api-key
  • Value: your Lekha API key (lk_live_...)
  • Save the tool. It now appears in your Dify tool palette as extractDocument.

    Step 2: Build the Bank Statement Analysis Workflow

    Create a new Workflow in Dify (not a chatflow — workflows give you more control over data passing).

    Your canvas will have these nodes:

    Node 1: Start

    Add a File input variable called statement_pdf. Set the type to File, allowed types to PDF.

    This is what your users upload — a bank statement from HDFC, SBI, ICICI, or any other Indian bank.

    Node 2: Lekha Extract Tool

    Add a Tool node and select your custom extractDocument tool.

    Map the input:

  • file → {{start.statement_pdf}}
  • The tool node will call Lekha and return a JSON payload like this:

    {
      "success": true,
      "data": {
        "bank": "HDFC Bank",
        "account_number": "XXXX1234",
        "period": { "from": "2026-08-01", "to": "2026-10-31" },
        "opening_balance": 42500,
        "closing_balance": 87320,
        "transactions": [
          {
            "date": "2026-08-05",
            "description": "SALARY CREDIT - INFOSYS",
            "amount": 95000,
            "type": "credit",
            "balance": 137500
          }
        ],
        "summary": {
          "total_credits": 285000,
          "total_debits": 240180,
          "average_monthly_balance": 64800,
          "salary_credits": [95000, 95000, 95000]
        }
      }
    }
    

    Node 3: LLM Analysis

    Add an LLM node. Connect it to the Lekha output.

    System prompt:

    You are a credit analyst reviewing Indian bank statements for loan eligibility.
    Analyze the provided bank statement data and produce a concise credit summary.
    Focus on: income stability, monthly obligations, cash flow patterns, and any red flags.
    

    User prompt:

    Here is the extracted bank statement data:
    

    {{lekha_extract.output}}

      Provide:
    • Monthly income (average, stability)
    • Major recurring debits (EMIs, rent, utilities)
    • Average monthly balance
    • Cash flow health (1-5 score with explanation)
    • Recommended loan eligibility (yes/no with reason)

    Keep the response under 300 words.

    Node 4: End

    Add an End node and output both:

  • raw_data → {{lekha_extract.output}}
  • analysis → {{llm.output}}
  • Your workflow is complete. Click Publish.

    Step 3: Expose It via a Chatbot or API

    Dify workflows can be called in three ways:

    Option A: Embed in a Dify Chatbot

    Create a chatbot in Dify, add your workflow as a tool, and deploy the chat widget to your loan application page. Users can upload statements and get instant eligibility checks.

    Option B: Call via Dify's Workflow API
    import FormData from "form-data";
    import fs from "fs";
    

    const form = new FormData(); form.append("inputs", JSON.stringify({})); form.append("response_mode", "blocking"); form.append("user", "applicant-123"); form.append("files[0][type]", "document"); form.append("files[0][transfer_method]", "local_file"); form.append("files[0][upload_file_id]", await uploadToDify(statementBuffer));

    const response = await fetch("https://api.dify.ai/v1/workflows/run", { method: "POST", headers: { Authorization: Bearer ${process.env.DIFY_API_KEY}, ...form.getHeaders(), }, body: form, });

    const result = await response.json(); console.log(result.data.outputs.analysis);

    Option C: Trigger from N8N or Zapier

    If you're already using N8N for automation, add an HTTP node that calls your Dify workflow API endpoint. This is useful for processing statements that arrive as email attachments or from a CRM.

    Step 4: Handle Multiple Document Types

    Lekha auto-detects the document type. The same Dify tool handles:

    | Document | What Lekha Returns | | -------------- | -------------------------------------- | | Bank statement | Transactions, balances, salary credits | | Salary slip | CTC, in-hand, deductions, PF | | ITR | Taxable income, sources, TDS paid | | Form 16 | Employer, TDS, gross salary breakdown | | CAS statement | Portfolio value, fund-wise holdings | | CIBIL report | Score, accounts, overdue amounts |

    To handle multiple types in one workflow, branch on the document_type field in Lekha's response using an IF/ELSE node:

    IF lekha_extract.output.data.document_type == "bank_statement"
      → bank statement analysis LLM
    ELSE IF lekha_extract.output.data.document_type == "salary_slip"
      → salary verification LLM
    ELSE
      → generic document LLM
    

    Production Considerations

    Rate limits: Lekha handles up to 100 concurrent extractions on the Growth plan. For batch processing, stagger your Dify workflow triggers. File size: Lekha accepts PDFs up to 10 MB. Most Indian bank statements are well under 2 MB. If your users upload scanned images, Dify can pre-process them before passing to Lekha. Error handling: Add a Condition node after the Lekha tool that checks lekha_extract.output.success. Route failures to a fallback LLM node that asks the user to re-upload. Data privacy: Lekha processes documents in-memory and does not store them. Your Dify instance should also be configured to not log file contents — set LOG_LEVEL=info in your Dify .env and ensure file inputs are excluded from conversation history.

    Try It on the Playground

    Before wiring up Dify, test your bank statements directly at lekhadev.com/playground. You'll see the exact JSON structure Lekha returns, which helps you design your LLM prompts.

    Full API documentation is at lekhadev.com/docs.

    FAQ

    Does Dify support file uploads in workflows? Yes. Dify workflows support file input variables of type PDF, image, or document. Files are uploaded to Dify first, then passed to tool nodes as references. Can I use a self-hosted Dify instance with Lekha? Yes. Lekha is a hosted API — it doesn't matter whether your Dify instance is on Dify Cloud or self-hosted on your own infrastructure. As long as your server has outbound internet access, the Lekha API call will work. What Indian banks does Lekha support? Lekha supports all major Indian banks: SBI, HDFC, ICICI, Axis, Kotak, PNB, Canara, Union Bank, Bank of India, Bank of Baroda, IndusInd, Yes Bank, Federal Bank, IDFC First, IDBI, RBL, South Indian Bank, AU Small Finance Bank, Bandhan Bank, and more. Run /supported on the API or check lekhadev.com/docs for the full list. How do I handle multi-page statements spanning several months? Pass the full multi-page PDF as a single file. Lekha processes all pages together and returns a unified transaction list sorted by date. See our multi-page PDF guide for edge cases.

    Ready to add financial document intelligence to your Dify workflows? Sign up at lekhadev.com and get your API key in under two minutes. The free tier includes 50 extractions per month — enough to prototype your entire workflow before you need a paid plan.