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:@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 calledinvoice-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-profor maximum accuracy - Medium quality (decent scans) →
gemini-2.5-flashfor balanced performance - High quality (clean digital docs) →
gemini-2.5-flash-litefor speed and cost
Alternative Providers
UsecreateVLMProvider for a single provider, or buildLLMProvider for fallback chains:
- Single Provider
- With Fallback
- Native Keys
Troubleshooting
Cannot find module '@doclo/flows'
Cannot find module '@doclo/flows'
Make sure packages are installed:
OPENROUTER_API_KEY is undefined
OPENROUTER_API_KEY is undefined
- Check
.env.localexists with your key - Make sure you imported
dotenv/configat the top of your file - Restart your dev server if using Next.js
429 Rate Limit Exceeded
429 Rate Limit Exceeded
- Check your OpenRouter usage
- Add credits to your account
- Use
buildLLMProvider()with retry logic for production
Schema validation failed
Schema validation failed
- 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