Tutorial

VIDEO | Master Financial Data Extraction with Eden AI's Financial Parser API

This step-by-step guide is for developers and engineering leaders looking to integrate Eden AI's Financial Parser API into their projects. Whether you're building an application that processes invoices, receipts, or other financial documents, this guide will walk you through the entire process.

VIDEO | Master Financial Data Extraction with Eden AI's Financial Parser API
TABLE OF CONTENTS

Mastering Financial Data Extraction with Eden AI's Financial Parser API

Dealing with invoices, receipts, and other financial documents can be a daunting task. These documents often come with complex layouts, including tables, handwritten notes, and non-standard formats, making data extraction a challenging endeavor. For developers and engineering leaders, the need for a robust solution to streamline this process is paramount.

Enter Eden AI's Financial Parser API—a state-of-the-art tool designed to simplify financial data extraction with advanced parsing capabilities. In this comprehensive guide, we'll explore how Eden AI's Financial Parser API can transform the way you handle financial documents.

We'll delve into its features, demonstrate its implementation, and provide actionable insights to help you integrate this powerful tool into your projects. By the end of this article, you'll have a clear understanding of how to leverage the Financial Parser API to enhance your data extraction processes.

Before diving into the implementation, let's break down some key concepts:

Financial Data Extraction API: A specialized API designed to extract structured data from financial documents such as invoices and receipts.

Receipt Parsing API: A subset of financial data extraction focused on parsing and extracting data from receipts.

OCR (Optical Character Recognition): A technology used to convert different types of documents, such as scanned paper documents, PDFs, or images captured by a digital camera, into editable and searchable data.

Prerequisites

To follow along with this guide, you'll need:

  • Basic knowledge of Python or JavaScript
  • Familiarity with RESTful APIs.
  • Access to Eden AI's platform. Sign up here.
  • A development environment set up with Python 3.7+ or Node.js 14+.

Solution Overview

The solution involves using Eden AI's Financial Parser API to extract data from financial documents. The process can be visualized as follows:

1. Document Input: Provide the document either as a URL or a local file.

2. API Request: Send the document to the Financial Parser API with specified parameters.

3. Data Extraction: The API processes the document and extracts relevant data.

4. Response Handling: Receive and handle the structured data for further use.

Step-by-Step Guide

Step 1: Accessing the Financial Parser API.

To begin, navigate to the Eden AI platform and locate the Financial Parser API. This API is designed to handle various document formats and extract data efficiently.

Python code snippet for accessing the Financial Parser API


import requests

url = "https://api.edenai.co/v1/financial_parser"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
  

Step 2: Preparing the Document

Decide whether your document is hosted online or stored locally. Use the appropriate method to provide the document to the API.

# Example for a local file files = {'file': open('path/to/your/document.pdf', 'rb')}

Step 3: Configuring API Parameters

Set the necessary parameters to customize the API request. This includes selecting providers, setting fallback options, and specifying document types.


# Example parameters
params = {
    "providers": ["openai", "google"],
    "fallback_providers": ["ibm"],
    "document_type": "invoice",
    "language": "en"
}

Step 4: Sending the API Request

Send the document and parameters to the Financial Parser API and handle the response.


# Sending the request
response = requests.post(url, headers=headers, files=files, data=params)
data = response.json()

Step 5: Handling the Response

Process the extracted data and integrate it into your application.


# Handling the response
if response.status_code == 200:
    extracted_data = data['results']
    print("Extracted Data:", extracted_data)
else:
    print("Error:", data['error'])

Final Result

Upon successful execution, the Financial Parser API will return structured data extracted from the document. This data can include customer information, merchant details, payment terms, and itemized lists. Here is the full overview:


from fastapi import FastAPI, File, UploadFile, Form, HTTPException
from fastapi.middleware.cors import CORSMiddleware
import requests
from typing import Optional, List
from pydantic import BaseModel, HttpUrl
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

app = FastAPI()

# Add CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Constants
EDEN_AI_API_TOKEN = os.getenv("EDEN_AI_API_KEY")
FINANCIAL_PARSER_URL = "https://api.edenai.run/v2/ocr/financial_parser"

class FinancialParserResponse(BaseModel):
    provider_responses: dict
    status: str

@app.post("/parse-financial-file/", response_model=FinancialParserResponse)
async def parse_financial_file(
    file: UploadFile = File(None),
    file_url: Optional[str] = Form(None),
    providers: str = Form("amazon,base64,microsoft,mindee"),
    fallback_providers: Optional[str] = Form(None),
    response_as_dict: bool = Form(True),
    attributes_as_list: bool = Form(False),
    show_base64: bool = Form(True),
    show_original_response: bool = Form(False),
    file_password: Optional[str] = Form(None),
    language: Optional[str] = Form("en"),
    document_type: str = Form("invoice"),
    convert_to_pdf: bool = Form(False)
):
    try:
        # Validate input
        if not file and not file_url:
            raise HTTPException(
                status_code=400,
                detail="Either file or file_url must be provided"
            )
        if file and file_url:
            raise HTTPException(
                status_code=400,
                detail="Cannot provide both file and file_url"
            )

        # Prepare headers
        headers = {
            "Authorization": f"Bearer {EDEN_AI_API_TOKEN}"
        }

        # Prepare the payload
        payload = {
            "providers": providers,
            "fallback_providers": fallback_providers,
            "response_as_dict": response_as_dict,
            "attributes_as_list": attributes_as_list,
            "show_base64": show_base64,
            "show_original_response": show_original_response,
            "language": language,
            "document_type": document_type,
            "convert_to_pdf": convert_to_pdf
        }

        if file_password:
            payload["file_password"] = file_password

        # Handle file upload vs URL
        if file:
            file_content = await file.read()
            files = {
                "file": (file.filename, file_content, file.content_type)
            }
            response = requests.post(
                FINANCIAL_PARSER_URL,
                data=payload,
                files=files,
                headers=headers
            )
        else:
            payload["file_url"] = file_url
            response = requests.post(
                FINANCIAL_PARSER_URL,
                json=payload,
                headers=headers
            )

        # Check if the request was successful
        response.raise_for_status()
        result = response.json()

        return {
            "provider_responses": result,
            "status": "success"
        }

    except requests.exceptions.RequestException as e:
        raise HTTPException(
            status_code=500,
            detail=f"Error communicating with Eden

Dig Deeper

To further enhance your implementation, consider exploring the following:

  • Advanced Features: Utilize additional parameters for more granular control over data extraction.
  • Security: Implement secure data handling practices to protect sensitive financial information.
  • Integration: Combine the Financial Parser API with other Eden AI services for a comprehensive AI-driven solution.

Conclusion

In this guide, we've explored how Eden AI's Financial Parser API can revolutionize the way you handle financial documents. By leveraging its advanced parsing capabilities, you can streamline data extraction processes, reduce manual effort, and improve accuracy. We encourage you to explore further, share your feedback, and check out related content on our platform.

Why Choose Eden AI for Financial Parsing?

Eden AI stands out as the best choice for AI workflow automation due to several reasons

Ease of Use

A no-code/low-code platform with a user-friendly interface.

Multi-Provider AI Access

Seamless integration with multiple AI services from different providers.

Cost Efficiency

Pay-as-you-go pricing and access to competitive AI pricing.

Scalability

Workflows can handle large-scale automation tasks with high performance.

Secure API Integration

Enterprise-grade security ensures data privacy and protection.

Additional Resources:

By integrating Eden AI's Financial Parser API into your projects, you can unlock new efficiencies and capabilities in financial data extraction. Start today and experience the power of AI-driven solutions!

Start Your AI Journey Today

  • Access 100+ AI APIs in a single platform.
  • Compare and deploy AI models effortlessly.
  • Pay-as-you-go with no upfront fees.
Start building FREE

Try Eden AI for free.

You can directly start building now. If you have any questions, feel free to chat with us!

Get startedContact sales