Analysis API Endpoints
The Analysis API suite provides endpoints for processing uploaded loan documents using AI-driven extraction and financial modeling. These endpoints are protected and require a valid user session.
Authentication
All endpoints require a valid Supabase authentication session. Requests should include the necessary session cookies or authorization headers.
Bank Statement Analysis
Processes bank statement files to extract transaction history, calculate balances, and identify risk patterns.
POST /api/analyze/bank-statement
Content-Type: application/json
Request Body
| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| documentId | string | Yes | The UUID of the document in the loan_documents table. |
| applicationId | string | Yes | The UUID of the associated loan application. |
| organizationId | string | Yes | The UUID of the organization. |
| aiProvider | string | No | Optional. Specify a specific provider (e.g., openai, anthropic). |
Response
Returns an object containing summarized metrics and detailed transaction data:
- Summary: Average/min/max balances, total credits/debits, and net income.
- Enhanced Analysis: Fraud risk scores, detected EMIs, cashflow volatility, and overall health scores.
- Transactions: Structured list of all extracted transactions.
Financial Statement Analysis
Extracts data from Balance Sheets, Profit & Loss statements, or Income Tax Returns (ITR).
POST /api/analyze/financial-statement
Content-Type: application/json
Request Body
| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| documentId | string | Yes | The UUID of the document. |
| applicationId | string | Yes | The UUID of the application. |
| organizationId | string | Yes | The UUID of the organization. |
| statementType | string | Yes | One of: balance_sheet, profit_loss, itr. |
| aiProvider | string | No | Optional AI provider selection. |
Response
Returns extracted financial fields and calculated ratios (e.g., debt-to-equity, DSCR, current ratio) based on the statement type.
GST Returns Analysis
Analyzes GST filings to verify business turnover and tax compliance.
GET /api/analyze/gst-returns
Fetches existing GST analysis records for a specific application.
- Query Parameter:
applicationId(required)
POST /api/analyze/gst-returns
Content-Type: application/json OR multipart/form-data
Supports two modes:
- Existing Document: Provide
documentIdandapplicationIdin a JSON body. - Direct Upload: Provide
file,applicationId, anddocumentTypevia FormData.
Reconciliation Analysis
Cross-references data between bank statements, GST returns, and financial statements to identify discrepancies.
GET /api/analyze/reconciliation
Fetches the latest reconciliation report for an application.
- Query Parameter:
applicationId(required)
POST /api/analyze/reconciliation
Triggers a new reconciliation process.
Content-Type: application/json
Request Body
| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| applicationId | string | Yes | The application ID to reconcile. |
Note: This endpoint automatically aggregates data from existing bank, GST, and financial analyses. Ensure those analyses are completed before calling this endpoint.
Credit Memo Generation
Generates a comprehensive AI-powered credit assessment memo based on all available application data.
POST /api/analyze/credit-memo
Content-Type: application/json
Request Body
| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| applicationId | string | Yes | The UUID of the application. |
| organizationId | string | Yes | The UUID of the organization. |
| aiProvider | string | No | Optional AI provider selection. |
Response
Returns a structured credit memo including:
- Executive Summary: Overview of the loan request and borrower.
- Financial Analysis: Summary of bank and financial statement findings.
- Risk Assessment: Identified risks and suggested mitigations.
- Recommendation: Preliminary credit decision recommendation.
Error Handling
The Analysis APIs return standard HTTP status codes:
400 Bad Request: Missing required fields or invalid statement types.401 Unauthorized: Missing or invalid authentication.404 Not Found: The specified document or application does not exist.500 Internal Server Error: AI processing failure or database connection issues.
Example error response:
{
"error": "Document not found",
"status": 404
}