Skip to main content
This guide shows how to integrate Doclo into a Next.js application, covering file uploads, API routes, and different execution patterns for production deployments.

Prerequisites

  • Node.js 18+
  • Next.js 14+ (App Router)
  • A Doclo API key

Installation

Project Structure

Environment Setup

Create a .env.local file:

Basic API Route: Synchronous Processing

For documents that process quickly (under 30 seconds):

Frontend: File Upload Component

Async Processing with Webhooks

For longer-running extractions, use async processing:

Webhook Handler

Receive completion notifications:

Polling for Results

Alternative to webhooks - poll for completion:
Frontend polling implementation:

Error Handling

Handle different error types appropriately:

Type-Safe Flow Results

Use TypeScript generics for type-safe extraction:

Server Actions (Next.js 14+)

Use Server Actions for a streamlined approach:
Use in a component:

Production Considerations

Rate Limiting

Protect your endpoints from abuse:

File Size Limits

Configure Next.js body size limits:

Caching

Cache flow information:

Next Steps

Webhook Handler

Detailed webhook implementation

Error Recovery

Handle failures gracefully

DocloClient

Full client reference

Webhooks

Webhook configuration