Parse a bank statement
One endpoint: send a PDF, get JSON back. This page covers everything you need; the interactive reference lets you try calls from the browser.
Authentication
Send your API key in the X-API-Key header. Create and revoke keys on your dashboard.
Keep keys on your server; never put them in a web or mobile app.
Request
POST https://lekhaapi.com/v1/statements as multipart/form-data:
| Field | Required | Description |
|---|---|---|
file | Yes | The statement PDF, up to 20 MB and 500 pages. |
password | No | The PDF's password, if it has one. Used once to open the file, never stored. |
Using Postman? Import the Lekha API collection and set its apiKey variable.
curl https://lekhaapi.com/v1/statements \ -H "X-API-Key: $LEKHA_KEY" \ -F file=@statement.pdf \ -F password=OPTIONAL
import os, requests r = requests.post( "https://lekhaapi.com/v1/statements", headers={"X-API-Key": os.environ["LEKHA_KEY"]}, files={"file": open("statement.pdf", "rb")}, data={"password": "OPTIONAL"}, timeout=120, ) if r.ok: statement = r.json() else: print(r.json()["error"]["code"])
import fs from "node:fs"; const form = new FormData(); form.append("file", new Blob([fs.readFileSync("statement.pdf")]), "statement.pdf"); const res = await fetch("https://lekhaapi.com/v1/statements", { method: "POST", headers: { "X-API-Key": process.env.LEKHA_KEY }, body: form, }); const body = await res.json(); if (!res.ok) console.error(body.error.code);
Response
On success you get 200 and the statement. Amounts are strings (for example "1250.50") so no paise are lost to
floating point; parse them as decimals. Fields the statement doesn't print are null.
{
"bank": "kotak",
"parser": "bank",
"pages": 3,
"ifsc": "KKBK0000123",
"account_holder": "A Customer",
"account_number": "1234567890",
"period_start": "2024-04-01",
"period_end": "2024-04-30",
"opening_balance": "1000.00",
"closing_balance": "2899.50",
"transactions": [
{"date": "2024-04-02", "value_date": "2024-04-02", "description": "UPI/SHOP/111/UPI",
"debit": "100.50", "credit": "0", "balance": "899.50", "reference": "UPI-111"}
],
"balance_check": {"passed": true, "checked_rows": 2, "first_mismatch_index": null, "expected": null, "found": null}
}
| Field | Description |
|---|---|
bank | Detected bank: kotak, indian_bank or sbi. For other banks, the name we recognise from the IFSC code (for example hdfc, icici, axis) or unknown. |
parser | bank: read by a parser built for this bank's layout. generic: read by our fallback for other banks (see below). |
pages | PDF pages, which is also the number of credits charged. |
transactions[] | In date order, oldest first. date is the posting date; value_date when the statement prints one. debit and credit are positive amounts, "0" on the side that doesn't apply. balance is negative when the account is overdrawn. |
balance_check | Each row's balance must equal the previous balance minus debit plus credit, and the last balance must match closing_balance when printed. If not, passed is false and first_mismatch_index points at the first row that doesn't add up, with the expected and found balances. |
Response headers X-Credits-Charged and X-Credits-Remaining show the cost of the call and your balance after it.
Checking your credits
GET https://lekhaapi.com/v1/account with the same X-API-Key header returns {"credits_remaining": 450}.
It's free, so check before sending a large statement.
When the balance check fails
It usually means the PDF itself is incomplete (pages removed, or a partial download), not that a row was misread. Show the result to a person rather than trusting it automatically, and if you think we got it wrong, send the error details to support@lekhaapi.com.
Errors
Errors return a non-2xx status and a body like {"error": {"code": "wrong_password", "message": "..."}}. Match on code; the
message is for people and may change. Failed calls never use credits.
| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_pdf | The file isn't a readable PDF. |
| 400 | password_required | The PDF is encrypted; send password. |
| 400 | wrong_password | The password didn't open the PDF. |
| 401 | invalid_api_key | Missing, unknown or revoked key. |
| 402 | insufficient_credits | The document has more pages than your balance. Buy credits on the dashboard. |
| 403 | account_on_hold | A payment on the account is disputed; the API resumes when the dispute is resolved. |
| 413 | file_too_large | Over 20 MB. |
| 413 | too_many_pages | Over 500 pages. |
| 422 | scanned_pdf | No text layer (a scan or photo). Use the statement downloaded from net banking or emailed by the bank. |
| 422 | unsupported_bank | We don't support this bank's format yet. |
Supported banks
- Kotak Mahindra Bank: monthly e-statements (2022 onwards), annual statements, and the app/net banking "Account Statement" export.
- Indian Bank: net banking statements in both the older 8-column and newer 6-column layouts.
- State Bank of India: account statements downloaded from YONO or internet banking (password-protected PDFs: send the
passwordfield).
Other banks
Statements from other banks go through a generic reader. It answers only when every row's change in balance matches an amount on that
row, so a result always passes the balance check; otherwise you get unsupported_bank and no credits are used. It reads dates,
amounts and balances; descriptions and account details are best effort, and it takes the first date on a row as date.
Need another bank? Write to support@lekhaapi.com.
Using an AI coding agent
Point Claude Code, Cursor, Copilot or any other agent at https://lekhaapi.com/llms.txt: the whole API on one plain-text page, written for LLMs. Tools that read schemas can use the OpenAPI spec. For example:
Read https://lekhaapi.com/llms.txt, then add a function that sends a bank statement PDF to Lekha API and returns the transactions. Read the key from the LEKHA_KEY environment variable and handle the error codes it lists.
MCP server
To let Claude, Cursor, VS Code or another MCP client parse statements on your computer directly, add the lekha-mcp server. It reads the PDF from disk, can save CSV or JSON, and checks your credits. With uv installed, for Claude Code:
claude mcp add lekha --env LEKHA_KEY=your-key -- uvx lekha-mcp
Other clients take "command": "uvx", "args": ["lekha-mcp"] with LEKHA_KEY in env; the
setup page has the config for each one and a one-click extension for Claude Desktop.
Statements are personal financial data: if an agent works with real ones, keep them out of logs, commits and chats.
Privacy
Statements are processed in memory and discarded when the response is sent. We don't store files, passwords or extracted data. Your API key is stored only as a hash. See the privacy policy.