> ## Documentation Index
> Fetch the complete documentation index at: https://docs.optieaseai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Backend API

> Optiease AI Backend REST API Documentation

<Note>
  The Optiease Backend provides AWS Lambda-based REST API endpoints for document management, template operations, email services, and client data integration.
</Note>

## Welcome

The Optiease Backend API is built on AWS Lambda with API Gateway integration deployed to `ap-southeast-2` region.

**Region:** `ap-southeast-2`\
**Environment:** `dev`

## Authentication

All API endpoints require an API Key for authentication. Include it in the request header:

```bash theme={null}
x-api-key: YOUR_API_KEY
```

<Warning>
  Never expose your API key in documentation or commit it to version control. Keep it secure in your environment variables.
</Warning>

## Available Endpoints

### Document Management

* **POST** `/store-document` - Store a document to cloud storage provider
  * Handler: `src/handlers/documents/store_document.py`
* **POST** `/get-folder-directories` - Retrieve folder structure from cloud storage
  * Handler: `src/handlers/documents/get_folder_directories.py`
* **POST** `/extract-document` - Extract text and data from documents
  * Handler: `src/handlers/documents/extract_document.py`
* **POST** `/identify-key-fields` - Identify and extract key fields from document text
  * Handler: `src/handlers/documents/identify_key_fields.py`

### Template Operations

* **POST** `/pre-filling` - Fill Word template with data
  * Handler: `src/handlers/templates/pre_filling.py`
* **POST** `/validate-document-template` - Validate a document template structure
  * Handler: `src/handlers/templates/validate_document_template.py`
* **POST** `/generate-document-template` - Generate a document template from samples
  * Handler: `src/handlers/templates/generate_document_template.py`

### Email Management

* **POST** `/send-email` - Send email via configured email provider
  * Handler: `src/handlers/email/send_email.py`
* **POST** `/generate-email-template` - Generate email template from samples
  * Handler: `src/handlers/email/generate_email_template.py`
* **POST** `/validate-email-template` - Validate email template structure
  * Handler: `src/handlers/email/validate_email_template.py`
* **POST** `/fill-email-template` - Fill email template with data and send
  * Handler: `src/handlers/email/fill_email_template.py`

### Client Data

* **POST** `/enter-client-data` - Import client data from external providers
  * Handler: `src/handlers/client/enter_client_data.py`

## Request Format

All requests must include:

* Content-Type: `application/json`
* x-api-key header with your API key

## Response Format

Successful responses return:

```json theme={null}
{
  "success": true,
  "message": "Operation description",
  "data": {
    "...": "response data"
  }
}
```

Error responses return:

```json theme={null}
{
  "error": "Error message",
  "code": "ERROR_CODE"
}
```
