Skip to main content
Build your first document extraction flow using the Doclo SDK.

Prerequisites

Node.js 18+ installed
pnpm, npm, or yarn
Basic TypeScript knowledge
An AI provider API key (OpenRouter, OpenAI, or Anthropic)

Installation

Install the core packages:
These two packages include everything you need:
  • @doclo/flows - Flow builder and all processing nodes
  • @doclo/providers-llm - LLM/VLM provider integrations

API Key Setup

This guide uses OpenRouter as a gateway to multiple AI providers. You can also use native provider keys directly.
1

Get an OpenRouter API Key

Sign up at openrouter.ai, navigate to the Keys section, and generate a new API key.
2

Create environment file

Create a .env.local file in your project root:
3

Load environment variables

For Node.js scripts, install dotenv:
Then import it at the top of your script:

Your First Flow: Invoice Extraction

Create a file called invoice-extract.ts:

Run the Example

1

Add a test PDF

Save an invoice PDF as invoice.pdf in your project directory.
2

Run the script

3

View the output

Understanding the Flow

This example demonstrates two key Doclo features: The routing logic:
  • Low quality (poor scans, handwritten) → gemini-2.5-pro for maximum accuracy
  • Medium quality (decent scans) → gemini-2.5-flash for balanced performance
  • High quality (clean digital docs) → gemini-2.5-flash-lite for speed and cost
The result object contains:

Alternative Providers

Use createVLMProvider for a single provider, or buildLLMProvider for fallback chains:

Troubleshooting

Make sure packages are installed:
  • Check .env.local exists with your key
  • Make sure you imported dotenv/config at the top of your file
  • Restart your dev server if using Next.js
  • Check your OpenRouter usage
  • Add credits to your account
  • Use buildLLMProvider() with retry logic for production
  • Make required fields optional if data might not exist
  • Check your schema uses valid JSON Schema format
  • Review the error message for which field failed

Next Steps

Concepts

Understand flows, nodes, and providers

Nodes Reference

Explore all processing nodes

Providers

Configure LLM and OCR providers

Consensus Voting

Improve accuracy with multi-provider voting