### Error Handling Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Provides guidance and examples for handling various types of errors that may occur during API interactions, including validation, rate limiting, and general API errors. ```APIDOC ## Error Handling ### Description This section details how to handle potential errors when using the Reducto API, including specific exceptions for validation, rate limits, and general API issues. It demonstrates a robust approach to API request management. ### Method Exception Handling (SDK/Code) ### Endpoint N/A (General error handling concept) ### Parameters N/A ### Request Example (Python SDK) ```python import asyncio from reducto import Reducto, ReductoError, RateLimitError, ValidationError client = Reducto(api_key="sk_live_abc123def456") async def safe_parse(document_url): try: result = await client.parse( document_url=document_url, extract_tables=True ) return result except ValidationError as e: # Handle invalid input print(f"Validation error: {e.message}") print(f"Invalid fields: {e.fields}") return None except RateLimitError as e: # Handle rate limiting print(f"Rate limit exceeded. Retry after: {e.retry_after} seconds") await asyncio.sleep(e.retry_after) return await safe_parse(document_url) # Retry the request except ReductoError as e: # Handle general API errors print(f"API error: {e.status_code} - {e.message}") return None except Exception as e: # Handle unexpected errors print(f"Unexpected error: {str(e)}") return None # Example usage: # await safe_parse("https://example.com/document.pdf") ``` ### Response #### Success Response Returns the result of the operation if successful, or `None` if an error occurred and was handled. #### Response Example (Error Scenarios) ``` # Example output for ValidationError: Validation error: Invalid document URL provided. Invalid fields: ['document_url'] # Example output for RateLimitError: Rate limit exceeded. Retry after: 60 seconds # Example output for ReductoError: API error: 404 - Document not found ``` ``` -------------------------------- ### Initialize Reducto Client - Python Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Initializes the Reducto client in Python using an API key for authentication. This client can then be used to interact with the Reducto API. ```python from reducto import Reducto client = Reducto(api_key="sk_live_abc123def456") ``` -------------------------------- ### Full Document Processing Pipeline with Python SDK Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Demonstrates a complete document processing pipeline using the Python SDK, including uploading, parsing, splitting into sections, and structured data extraction based on a schema. Requires the reducto-sdk package. ```python from reducto import Reducto client = Reducto(api_key="sk_live_abc123def456") # Complete document processing pipeline async def process_contract(file_path): # 1. Upload document upload = await client.upload(file_path) # 2. Parse document parsed = await client.parse( file_id=upload.file_id, extract_tables=True ) # 3. Split into sections sections = await client.split( file_id=upload.file_id, max_section_length=3000 ) # 4. Extract structured data from each section extracted_data = [] for section in sections.sections: data = await client.extract( content=section.content, schema={ "parties": ["string"], "obligations": ["string"], "dates": ["date"], "amounts": ["number"] } ) extracted_data.append({ "section": section.title, "data": data.extracted_data }) return { "parsed_content": parsed.content, "sections": sections.table_of_contents, "extracted_data": extracted_data } # Execute pipeline result = await process_contract("contract.pdf") ``` -------------------------------- ### Authenticate with API Key - Bash Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Demonstrates how to set the Reducto API key as an environment variable and use it for authenticated requests to the Parse API. ```bash # Store API key as environment variable export REDUCTO_API_KEY="sk_live_abc123def456" # Make authenticated request curl -X POST https://api.reducto.ai/parse \ -H "Authorization: Bearer $REDUCTO_API_KEY" \ -H "Content-Type: application/json" \ -d '{"document_url": "https://example.com/doc.pdf"}' ``` -------------------------------- ### Configure Reducto AI Webhook Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Sets up a webhook to receive real-time notifications for document processing events like parsing completion, data extraction, and batch completion. Requires an API key and specifies the callback URL, events to subscribe to, and a webhook secret for verification. ```bash curl -X POST https://api.reducto.ai/webhooks \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "url": "https://yourapp.com/webhooks/reducto", "events": ["parse.completed", "extract.completed", "batch.completed"], "secret": "whsec_your_webhook_secret" }' ``` -------------------------------- ### Authentication Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt API key authentication for all Reducto.ai endpoints. ```APIDOC ## Authentication ### Description API key authentication is required for all endpoints. Store your API key securely and include it in the `Authorization` header as a Bearer token. ### Method Use the `Authorization` header with a Bearer token. ### Example (Bash) ```bash export REDUCTO_API_KEY="sk_live_abc123def456" curl -X POST https://api.reducto.ai/parse \ -H "Authorization: Bearer $REDUCTO_API_KEY" \ -H "Content-Type: application/json" \ -d '{"document_url": "https://example.com/doc.pdf"}' ``` ### Example (Python SDK) ```python from reducto import Reducto client = Reducto(api_key="sk_live_abc123def456") # Now you can use the client to make authenticated requests # For example: # response = client.parse(document_url="https://example.com/doc.pdf") ``` ### Parameters #### Header Parameters - **Authorization** (string) - Required - Bearer token with your API key (e.g., `Bearer YOUR_API_KEY`). ``` -------------------------------- ### Parse Document with Python SDK Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Parses a document from a given URL using the Python SDK, with an option to extract tables. Requires the reducto-sdk package. ```python result = client.parse( document_url="https://example.com/document.pdf", extract_tables=True ) print(result.content.text) ``` -------------------------------- ### Pipeline Processing API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Demonstrates how to chain multiple Reducto AI API calls to create complex document processing workflows, such as uploading, parsing, splitting, and extracting structured data. ```APIDOC ## Pipeline Processing ### Description This example demonstrates a complete document processing pipeline using the Reducto SDK, including uploading, parsing, splitting, and structured data extraction. ### Method Asynchronous Function Call (SDK) ### Endpoint N/A (Conceptual pipeline) ### Parameters (Conceptual) - **file_path** (string) - Required - The local path to the document file. - **schema** (object) - Required - The schema for data extraction. ### Request Example (Python SDK) ```python from reducto import Reducto client = Reducto(api_key="sk_live_abc123def456") async def process_contract(file_path): # 1. Upload document upload = await client.upload(file_path) # 2. Parse document parsed = await client.parse( file_id=upload.file_id, extract_tables=True ) # 3. Split into sections sections = await client.split( file_id=upload.file_id, max_section_length=3000 ) # 4. Extract structured data from each section extracted_data = [] for section in sections.sections: data = await client.extract( content=section.content, schema={ "parties": ["string"], "obligations": ["string"], "dates": ["date"], "amounts": ["number"] } ) extracted_data.append({ "section": section.title, "data": data.extracted_data }) return { "parsed_content": parsed.content, "sections": sections.table_of_contents, "extracted_data": extracted_data } # Execute pipeline result = await process_contract("contract.pdf") ``` ### Response #### Success Response (Conceptual) The response is a dictionary containing the results of each stage of the pipeline: - **parsed_content**: The fully parsed document content. - **sections**: A table of contents for the document sections. - **extracted_data**: Structured data extracted from each section according to the provided schema. #### Response Example (Conceptual) ```json { "parsed_content": {"text": "...", "tables": [], "figures": []}, "sections": [{"title": "Introduction", "page": 1}, ...], "extracted_data": [ { "section": "Introduction", "data": { "parties": ["Party A", "Party B"], "obligations": ["Payment obligation"], "dates": ["2023-01-01"], "amounts": [10000] } }, ... ] } ``` ``` -------------------------------- ### Parse Documents with Reducto AI API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Demonstrates how to use the Reducto AI API to parse various document types including PDFs with OCR, Excel files with sheet selection, and images with orientation detection and quality enhancement. Requires an API key and specifies document URLs and relevant options. ```bash # Parse PDF with OCR curl -X POST https://api.reducto.ai/parse \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "document_url": "https://example.com/scanned.pdf", "ocr": true, "language": "en" }' # Parse Excel with sheet selection curl -X POST https://api.reducto.ai/parse \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "document_url": "https://example.com/data.xlsx", "sheets": ["Sheet1", "Summary"], "preserve_formulas": true }' # Parse image with text detection curl -X POST https://api.reducto.ai/parse \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "document_url": "https://example.com/receipt.jpg", "detect_orientation": true, "enhance_quality": true }' ``` -------------------------------- ### Webhook Configuration API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Configure a webhook to receive real-time notifications for document processing events like parsing completion, data extraction, and batch completion. ```APIDOC ## POST /webhooks ### Description Configure a webhook endpoint to receive real-time notifications for document processing events. ### Method POST ### Endpoint /webhooks ### Parameters #### Request Body - **url** (string) - Required - The URL of your webhook endpoint. - **events** (array of strings) - Required - A list of events to subscribe to (e.g., `"parse.completed"`, `"extract.completed"`, `"batch.completed"`). - **secret** (string) - Optional - A secret key to sign webhook events for verification. ### Request Example ```json { "url": "https://yourapp.com/webhooks/reducto", "events": ["parse.completed", "extract.completed", "batch.completed"], "secret": "whsec_your_webhook_secret" } ``` ### Response #### Success Response (200) - **webhook_id** (string) - The unique identifier for the configured webhook. - **url** (string) - The configured webhook URL. - **events** (array of strings) - The list of subscribed events. - **created_at** (string) - The timestamp when the webhook was created. #### Response Example ```json { "webhook_id": "wh_abc123", "url": "https://yourapp.com/webhooks/reducto", "events": ["parse.completed", "extract.completed", "batch.completed"], "created_at": "2024-10-09T12:00:00Z" } ``` ``` -------------------------------- ### Parse API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Converts documents into structured components including text, tables, and figures. ```APIDOC ## POST /parse ### Description Converts documents into structured components including text, tables, and figures. ### Method POST ### Endpoint https://api.reducto.ai/parse ### Parameters #### Request Body - **document_url** (string) - Required - URL of the document to process. - **extract_tables** (boolean) - Optional - Whether to extract tables from the document. - **extract_figures** (boolean) - Optional - Whether to extract figures from the document. ### Request Example ```json { "document_url": "https://example.com/document.pdf", "extract_tables": true, "extract_figures": true } ``` ### Response #### Success Response (200) - **status** (string) - Status of the job. - **job_id** (string) - Unique identifier for the processing job. - **content** (object) - Extracted content from the document. - **text** (string) - Extracted text content. - **tables** (array) - Array of extracted tables. - **page** (integer) - Page number where the table was found. - **data** (array of arrays) - Table data. - **figures** (array) - Array of extracted figures. - **page** (integer) - Page number where the figure was found. - **type** (string) - Type of the figure (e.g., "chart"). - **url** (string) - URL to the extracted figure image. #### Response Example ```json { "status": "success", "job_id": "job_abc123", "content": { "text": "Document text content...", "tables": [ { "page": 1, "data": [["Header1", "Header2"], ["Value1", "Value2"]] } ], "figures": [ { "page": 2, "type": "chart", "url": "https://storage.reducto.ai/figures/xyz789.png" } ] } } ``` ``` -------------------------------- ### Submit Batch Job via cURL Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Submits a batch processing job for multiple documents via cURL, specifying the operation, document list, options, and a callback URL for notifications. Requires an API key. ```bash # Submit batch job curl -X POST https://api.reducto.ai/batch \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "operation": "parse", "documents": [ {"url": "https://example.com/doc1.pdf"}, {"url": "https://example.com/doc2.pdf"}, {"url": "https://example.com/doc3.pdf"} ], "options": { "extract_tables": true, "extract_figures": false }, "callback_url": "https://yourapp.com/webhook/batch-complete" }' # Response { "batch_id": "batch_abc123", "status": "processing", "total_documents": 3, "completed": 0 } # Check batch status curl -X GET https://api.reducto.ai/batch/batch_abc123 \ -H "Authorization: Bearer YOUR_API_KEY" # Response { "batch_id": "batch_abc123", "status": "completed", "total_documents": 3, "completed": 3, "failed": 0, "results": [ {"document_url": "https://example.com/doc1.pdf", "status": "success", "result_id": "result_1"}, {"document_url": "https://example.com/doc2.pdf", "status": "success", "result_id": "result_2"}, {"document_url": "https://example.com/doc3.pdf", "status": "success", "result_id": "result_3"} ] } ``` -------------------------------- ### Parse Document with JavaScript SDK Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Parses a document from a given URL using the JavaScript SDK, with options to extract tables and figures. Requires the reducto-sdk package and an API key. ```javascript const { Reducto } = require('reducto-sdk'); const client = new Reducto({ apiKey: 'sk_live_abc123def456' }); async function processDocument() { const result = await client.parse({ documentUrl: 'https://example.com/document.pdf', extractTables: true, extractFigures: true }); return result.content; } ``` -------------------------------- ### Upload Local Document via cURL Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Uploads a local PDF document to Reducto AI using cURL for subsequent processing. Requires an API key and returns a file ID and upload URL. ```bash # Upload file directly curl -X POST https://api.reducto.ai/upload \ -H "Authorization: Bearer YOUR_API_KEY" \ -F "file=@/path/to/document.pdf" # Response { "file_id": "file_xyz789", "upload_url": "https://storage.reducto.ai/uploads/xyz789.pdf", "expires_at": "2024-10-16T00:00:00Z" } # Use uploaded file with Parse API curl -X POST https://api.reducto.ai/parse \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "file_id": "file_xyz789", "extract_tables": true }' ``` -------------------------------- ### Parse Document - Bash Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Basic document parsing using the Reducto Parse API. It takes a document URL and options to extract tables and figures. Returns a job ID and structured content including text, tables, and figures. ```bash curl -X POST https://api.reducto.ai/parse \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "document_url": "https://example.com/document.pdf", "extract_tables": true, "extract_figures": true }' ``` -------------------------------- ### Extract API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Generates structured JSON fields from documents using schemas or prompts. ```APIDOC ## POST /extract ### Description Generates structured JSON fields from documents using schemas or prompts. ### Method POST ### Endpoint https://api.reducto.ai/extract ### Parameters #### Request Body - **document_url** (string) - Required - URL of the document to process. - **schema** (object) - Required - Defines the structure of the data to extract. - Example: `{"invoice_number": "string", "date": "date", "total_amount": "number"}` ### Request Example ```json { "document_url": "https://example.com/invoice.pdf", "schema": { "invoice_number": "string", "date": "date", "total_amount": "number", "line_items": [ { "description": "string", "quantity": "number", "price": "number" } ] } } ``` ### Response #### Success Response (200) - **status** (string) - Status of the extraction. - **extracted_data** (object) - The structured data extracted from the document. - **confidence** (number) - Confidence score of the extraction (0.0 to 1.0). #### Response Example ```json { "status": "success", "extracted_data": { "invoice_number": "INV-2024-001", "date": "2024-03-15", "total_amount": 1250.00, "line_items": [ { "description": "Consulting Services", "quantity": 10, "price": 125.00 } ] }, "confidence": 0.95 } ``` ``` -------------------------------- ### Split API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Breaks large documents into logical subsections and generates a table of contents. ```APIDOC ## POST /split ### Description Breaks large documents into logical subsections and generates a table of contents. ### Method POST ### Endpoint https://api.reducto.ai/split ### Parameters #### Request Body - **document_url** (string) - Required - URL of the document to process. - **max_section_length** (integer) - Optional - Maximum word count for each section. - **generate_toc** (boolean) - Optional - Whether to generate a table of contents. ### Request Example ```json { "document_url": "https://example.com/report.pdf", "max_section_length": 5000, "generate_toc": true } ``` ### Response #### Success Response (200) - **status** (string) - Status of the splitting operation. - **sections** (array) - Array of document sections. - **id** (string) - Unique identifier for the section. - **title** (string) - Title of the section. - **pages** (array of integers) - Page numbers included in the section. - **content** (string) - Text content of the section. - **word_count** (integer) - Word count of the section. - **table_of_contents** (array) - Generated table of contents. - **section_id** (string) - ID of the section. - **title** (string) - Title of the section. - **page** (integer) - Starting page number of the section. #### Response Example ```json { "status": "success", "sections": [ { "id": "section_1", "title": "Executive Summary", "pages": [1, 2], "content": "Executive summary text...", "word_count": 450 }, { "id": "section_2", "title": "Financial Analysis", "pages": [3, 4, 5], "content": "Financial analysis content...", "word_count": 1200 } ], "table_of_contents": [ {"section_id": "section_1", "title": "Executive Summary", "page": 1}, {"section_id": "section_2", "title": "Financial Analysis", "page": 3} ] } ``` ``` -------------------------------- ### Batch Processing API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Enables processing multiple documents in batches for efficiency. You can specify the operation, documents, and options, and provide a callback URL for completion notifications. ```APIDOC ## POST /batch ### Description Submits a batch job to process multiple documents concurrently. Specifies the operation, a list of documents, processing options, and a callback URL for results. ### Method POST ### Endpoint /batch ### Parameters #### Request Body - **operation** (string) - Required - The operation to perform on each document (e.g., "parse"). - **documents** (array) - Required - A list of document objects, each with a "url" field. - **url** (string) - Required - The URL of the document. - **options** (object) - Optional - Options for the specified operation (e.g., `extract_tables`). - **callback_url** (string) - Optional - A URL to send a notification to when the batch job is complete. ### Request Example ```bash curl -X POST https://api.reducto.ai/batch \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "operation": "parse", "documents": [ {"url": "https://example.com/doc1.pdf"}, {"url": "https://example.com/doc2.pdf"}, {"url": "https://example.com/doc3.pdf"} ], "options": { "extract_tables": true, "extract_figures": false }, "callback_url": "https://yourapp.com/webhook/batch-complete" }' ``` ### Response #### Success Response (200) - **batch_id** (string) - The unique identifier for the batch job. - **status** (string) - The initial status of the batch job (e.g., "processing"). - **total_documents** (integer) - The total number of documents in the batch. - **completed** (integer) - The number of documents successfully processed so far. #### Response Example ```json { "batch_id": "batch_abc123", "status": "processing", "total_documents": 3, "completed": 0 } ``` ## GET /batch/{batch_id} ### Description Retrieves the current status and results of a previously submitted batch job. ### Method GET ### Endpoint /batch/{batch_id} ### Parameters #### Path Parameters - **batch_id** (string) - Required - The ID of the batch job to check. ### Response #### Success Response (200) - **batch_id** (string) - The ID of the batch job. - **status** (string) - The current status of the batch job (e.g., "completed"). - **total_documents** (integer) - The total number of documents in the batch. - **completed** (integer) - The number of documents successfully processed. - **failed** (integer) - The number of documents that failed processing. - **results** (array) - A list of results for each document in the batch. - **document_url** (string) - The URL of the document. - **status** (string) - The processing status for this document ("success" or "failed"). - **result_id** (string) - An identifier for the result of this document's processing. #### Response Example ```json { "batch_id": "batch_abc123", "status": "completed", "total_documents": 3, "completed": 3, "failed": 0, "results": [ {"document_url": "https://example.com/doc1.pdf", "status": "success", "result_id": "result_1"}, {"document_url": "https://example.com/doc2.pdf", "status": "success", "result_id": "result_2"}, {"document_url": "https://example.com/doc3.pdf", "status": "success", "result_id": "result_3"} ] } ``` ``` -------------------------------- ### Split Document - Bash Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Split a large document into logical subsections using the Reducto Split API. It takes a document URL and parameters for section length and table of contents generation, returning section details and a TOC. ```bash curl -X POST https://api.reducto.ai/split \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "document_url": "https://example.com/report.pdf", "max_section_length": 5000, "generate_toc": true }' ``` -------------------------------- ### Fill PDF Form Fields - Bash Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Programmatically fill form fields in documents like PDFs using the Reducto Edit API. It takes a document URL, a dictionary of fields to fill, and the desired output format, returning a URL for the modified document. ```bash curl -X POST https://api.reducto.ai/edit \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "document_url": "https://example.com/form.pdf", "fields": { "applicant_name": "John Doe", "application_date": "2024-10-09", "email": "john.doe@example.com", "signature": "data:image/png;base64,iVBORw0KG..." }, "output_format": "pdf" }' ``` -------------------------------- ### Handle API Errors with Python SDK Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Provides robust error handling for API requests using the Python SDK, catching specific errors like ValidationError, RateLimitError, and general ReductoError, along with unexpected exceptions. Requires the reducto-sdk package and asyncio. ```python from reducto import Reducto, ReductoError, RateLimitError, ValidationError import asyncio client = Reducto(api_key="sk_live_abc123def456") async def safe_parse(document_url): try: result = await client.parse( document_url=document_url, extract_tables=True ) return result except ValidationError as e: # Handle invalid input print(f"Validation error: {e.message}") print(f"Invalid fields: {e.fields}") return None except RateLimitError as e: # Handle rate limiting print(f"Rate limit exceeded. Retry after: {e.retry_after} seconds") await asyncio.sleep(e.retry_after) return await safe_parse(document_url) except ReductoError as e: # Handle general API errors print(f"API error: {e.status_code} - {e.message}") return None except Exception as e: # Handle unexpected errors print(f"Unexpected error: {str(e)}") return None ``` -------------------------------- ### Extract Data with Schema (Financial Services) Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Extract structured data from financial documents like bank statements by providing a predefined schema. ```APIDOC ## POST /extract (Financial Services Example) ### Description Extract specific financial data points from documents such as bank statements by defining a JSON schema for the expected output. ### Method POST ### Endpoint /extract ### Parameters #### Request Body - **document_url** (string) - Required - The URL of the financial document. - **schema** (object) - Required - A JSON schema defining the structure and data types of the information to extract (e.g., account number, statement period, transactions). ### Request Example ```python # Extract data from bank statements client = Reducto(api_key="sk_live_abc123def456") statement_schema = { "account_number": "string", "statement_period": { "start_date": "date", "end_date": "date" }, "opening_balance": "number", "closing_balance": "number", "transactions": [ { "date": "date", "description": "string", "amount": "number", "type": "string" } ], "total_deposits": "number", "total_withdrawals": "number" } result = await client.extract( document_url="bank_statement.pdf", schema=statement_schema ) ``` ### Response *(Note: The specific success response structure for extraction is not detailed, but it would typically be a JSON object conforming to the provided schema, populated with extracted data.)* ``` -------------------------------- ### Extract Data with Schema (Legal) Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Extract key information from legal documents like contracts by defining a schema for contract details, parties, dates, and terms. ```APIDOC ## POST /extract (Legal Example) ### Description Extract critical information from legal documents, such as contracts, by providing a JSON schema that specifies fields like contract type, parties involved, effective dates, and payment terms. ### Method POST ### Endpoint /extract ### Parameters #### Request Body - **document_url** (string) - Required - The URL of the legal document. - **schema** (object) - Required - A JSON schema defining the structure and data types of the information to extract (e.g., contract type, parties, dates, obligations). ### Request Example ```python # Extract key information from contracts contract_schema = { "contract_type": "string", "parties": [ { "name": "string", "role": "string", "address": "string" } ], "effective_date": "date", "termination_date": "date", "payment_terms": { "amount": "number", "frequency": "string", "due_date": "string" }, "key_obligations": ["string"], "termination_clauses": ["string"], "governing_law": "string" } result = await client.extract( document_url="contract.pdf", schema=contract_schema ) ``` ### Response *(Note: The specific success response structure for extraction is not detailed, but it would typically be a JSON object conforming to the provided schema, populated with extracted legal data.)* ``` -------------------------------- ### Parse Document API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt This API endpoint allows you to parse a document from a URL, with options to extract tables and figures. ```APIDOC ## POST /parse ### Description Parses a document from a given URL and extracts content, including tables and figures. ### Method POST ### Endpoint /parse ### Parameters #### Query Parameters - **document_url** (string) - Required - The URL of the document to parse. - **extract_tables** (boolean) - Optional - Whether to extract tables from the document. Defaults to false. - **extract_figures** (boolean) - Optional - Whether to extract figures from the document. Defaults to false. ### Request Example ```python # Python SDK example result = client.parse( document_url="https://example.com/document.pdf", extract_tables=True ) ``` ### Response #### Success Response (200) - **content** (object) - The parsed content of the document. - **text** (string) - The extracted text from the document. - **tables** (array) - Extracted tables (if `extract_tables` is true). - **figures** (array) - Extracted figures (if `extract_figures` is true). #### Response Example ```json { "content": { "text": "This is the extracted text...", "tables": [...], "figures": [...] } } ``` ``` -------------------------------- ### Edit API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Fills out form fields in documents like PDFs and DOCX files programmatically. ```APIDOC ## POST /edit ### Description Fills out form fields in documents like PDFs and DOCX files programmatically. ### Method POST ### Endpoint https://api.reducto.ai/edit ### Parameters #### Request Body - **document_url** (string) - Required - URL of the document to process. - **fields** (object) - Required - Key-value pairs of form fields and their values. - Example: `{"applicant_name": "John Doe", "application_date": "2024-10-09"}` - **output_format** (string) - Optional - The desired output format (e.g., "pdf", "docx"). Defaults to the input format. ### Request Example ```json { "document_url": "https://example.com/form.pdf", "fields": { "applicant_name": "John Doe", "application_date": "2024-10-09", "email": "john.doe@example.com", "signature": "data:image/png;base64,iVBORw0KG..." }, "output_format": "pdf" } ``` ### Response #### Success Response (200) - **status** (string) - Status of the editing operation. - **output_url** (string) - URL to the processed document. - **fields_modified** (integer) - Number of fields that were modified. - **download_expires_at** (string) - Timestamp when the output URL expires. #### Response Example ```json { "status": "success", "output_url": "https://storage.reducto.ai/edited/form_filled_xyz.pdf", "fields_modified": 4, "download_expires_at": "2024-10-16T00:00:00Z" } ``` ``` -------------------------------- ### Extract Data with Schema - Bash Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Extract structured data from a document using the Reducto Extract API with a predefined schema. It takes a document URL and a schema object, returning the extracted data with a confidence score. ```bash curl -X POST https://api.reducto.ai/extract \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "document_url": "https://example.com/invoice.pdf", "schema": { "invoice_number": "string", "date": "date", "total_amount": "number", "line_items": [ { "description": "string", "quantity": "number", "price": "number" } ] } }' ``` -------------------------------- ### Document Upload API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Allows uploading local files for processing. The uploaded file can then be referenced by its file ID in other API calls. ```APIDOC ## POST /upload ### Description Uploads a local file to Reducto AI for processing. Returns a file ID that can be used in subsequent API calls. ### Method POST ### Endpoint /upload ### Parameters #### Request Body - **file** (file) - Required - The local file to upload. ### Request Example ```bash curl -X POST https://api.reducto.ai/upload \ -H "Authorization: Bearer YOUR_API_KEY" \ -F "file=@/path/to/document.pdf" ``` ### Response #### Success Response (200) - **file_id** (string) - The unique identifier for the uploaded file. - **upload_url** (string) - A temporary URL for the uploaded file. - **expires_at** (string) - The expiration time of the upload URL. #### Response Example ```json { "file_id": "file_xyz789", "upload_url": "https://storage.reducto.ai/uploads/xyz789.pdf", "expires_at": "2024-10-16T00:00:00Z" } ``` ## POST /parse (using file_id) ### Description Parses a document using its previously uploaded file ID. ### Method POST ### Endpoint /parse ### Parameters #### Request Body - **file_id** (string) - Required - The ID of the uploaded file. - **extract_tables** (boolean) - Optional - Whether to extract tables from the document. Defaults to false. ### Request Example ```bash curl -X POST https://api.reducto.ai/parse \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "file_id": "file_xyz789", "extract_tables": true }' ``` ``` -------------------------------- ### Parse Document API Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Parse various document types, with options for OCR, sheet selection in Excel files, and text detection in images. ```APIDOC ## POST /parse ### Description Parse various document types, supporting format-specific options like OCR for scanned PDFs, sheet selection for Excel files, and text detection for images. ### Method POST ### Endpoint /parse ### Parameters #### Request Body - **document_url** (string) - Required - The URL of the document to parse. - **ocr** (boolean) - Optional - Set to `true` to enable Optical Character Recognition for scanned documents (e.g., PDFs). - **language** (string) - Optional - The language code for OCR processing (e.g., `"en"` for English). - **sheets** (array of strings) - Optional - For Excel files, specify the names of the sheets to parse. - **preserve_formulas** (boolean) - Optional - For Excel files, set to `true` to keep formulas intact. - **detect_orientation** (boolean) - Optional - For image files, set to `true` to automatically detect and correct page orientation. - **enhance_quality** (boolean) - Optional - For image files, set to `true` to improve image quality for better text extraction. ### Request Example ```json # Parse PDF with OCR { "document_url": "https://example.com/scanned.pdf", "ocr": true, "language": "en" } # Parse Excel with sheet selection { "document_url": "https://example.com/data.xlsx", "sheets": ["Sheet1", "Summary"], "preserve_formulas": true } # Parse image with text detection { "document_url": "https://example.com/receipt.jpg", "detect_orientation": true, "enhance_quality": true } ``` ### Response *(Note: Response structure for /parse is not detailed in the provided text, but typically would include job status, extracted data, or a URL to the processed document.)* ### Error Response Example ```json { "error": { "code": "invalid_document", "message": "The provided document format is not supported", "details": { "file_type": "application/x-unknown", "supported_types": ["application/pdf", "image/png", "image/jpeg"] } }, "status": "error" } ``` ``` -------------------------------- ### Handle Reducto AI Webhook Events in Node.js (Express) Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt An Express.js application to handle incoming webhook events from Reducto AI. It verifies the webhook signature using a shared secret and processes different event types such as 'parse.completed', 'extract.completed', and 'batch.completed'. ```javascript // Express.js webhook handler const express = require('express'); const crypto = require('crypto'); const app = express(); app.use(express.json()); app.post('/webhooks/reducto', (req, res) => { const signature = req.headers['x-reducto-signature']; const secret = process.env.WEBHOOK_SECRET; // Verify webhook signature const hash = crypto .createHmac('sha256', secret) .update(JSON.stringify(req.body)) .digest('hex'); if (hash !== signature) { return res.status(401).send('Invalid signature'); } // Process webhook event const { event, data } = req.body; switch (event) { case 'parse.completed': console.log('Document parsed:', data.job_id); // Handle parsed document break; case 'extract.completed': console.log('Data extracted:', data.job_id); // Handle extracted data break; case 'batch.completed': console.log('Batch completed:', data.batch_id); // Handle batch completion break; } res.status(200).send('OK'); }); ``` -------------------------------- ### Extract Legal Contract Information with Reducto AI (Python) Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Extracts key data points from legal contracts, such as contract type, parties involved, effective dates, payment terms, and governing law. Uses a predefined schema to structure the extracted information. ```python # Extract key information from contracts contract_schema = { "contract_type": "string", "parties": [ { "name": "string", "role": "string", "address": "string" } ], "effective_date": "date", "termination_date": "date", "payment_terms": { "amount": "number", "frequency": "string", "due_date": "string" }, "key_obligations": ["string"], "termination_clauses": ["string"], "governing_law": "string" } result = await client.extract( document_url="contract.pdf", schema=contract_schema ) ``` -------------------------------- ### Process Healthcare Records with Reducto AI (Python) Source: https://context7.com/context7/docs_reducto_ai-overview/llms.txt Processes patient records from healthcare documents like lab reports, extracting key information defined by a specific schema. Supports HIPAA compliance by automatically redacting Personally Identifiable Information (PII). ```python # Process patient records with HIPAA compliance lab_report_schema = { "patient_id": "string", "test_date": "date", "tests": [ { "name": "string", "result": "string", "unit": "string", "reference_range": "string", "status": "string" } ], "ordering_physician": "string", "lab_name": "string" } result = await client.extract( document_url="lab_report.pdf", schema=lab_report_schema, redact_pii=True # Automatic PII redaction ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.