# Invoice OCR Extractor

> Containerized FastAPI service for extracting Pydantic-validated JSON from invoice images and PDFs via OCR and LLMs.

Invoice OCR Extractor is a free AI agent skill on Agensi by Onur Aslanhan, in APIs & Backend. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Onur Aslanhan](https://www.agensi.io/creators/onur-aslanhan)
- Category: [APIs & Backend](https://www.agensi.io/skills/apis-backend)
- Version: 1.0
- Last updated: 2026-11-26
- Security: scan passed (2026-11-26); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/invoice-ocr-extractor
- Tags: api, finance, ocr, fastapi, openrouter, pydantic

## About this skill

Typing invoice data into a spreadsheet by hand is slow and error-prone. This skill gives your AI agent a small local service that reads an invoice image or PDF and returns the key fields as clean, validated JSON.

### What it does
- **Reads invoices:** accepts JPEG, PNG and PDF files and extracts the text with Tesseract OCR (PDFs are handled through Poppler).
- **Returns structured JSON:** an LLM via OpenRouter maps the text to fixed fields: company, invoice number, date, customer, subtotal, tax rate and line items.
- **Checks the output:** the result is validated against a Pydantic schema, so malformed or incomplete answers are rejected with a clear error instead of being passed along silently.
- **English and Turkish OCR:** both Tesseract language packs are included.
- **Runs locally in Docker:** all dependencies are packaged in the included Dockerfile.

### How it works
1. Your agent creates a `.env` file with your own OpenRouter API key (the free tier is enough).
2. It builds and starts the Docker container (port 8000).
3. It sends your invoice to the `/extract-invoice` endpoint.
4. It returns the validated JSON to you.

### What you need
- Docker installed and running
- A free OpenRouter API key (your own, no Agensi tool balance is used)

### Good for
- Pulling invoice fields into a spreadsheet, script or accounting workflow
- Quickly checking what a scanned invoice says, in structured form
- A starting point for your own invoice-processing pipeline (the full source is included)

### Privacy
The text of your invoice is sent to OpenRouter and the model provider behind it. Avoid confidential invoices unless you are comfortable with that. The service itself runs on your machine, and your API key stays in your local `.env` file.

### Known limitations
- Only the first page of a PDF is processed.
- Logos and stylized header text can be misread, so double-check the company name.
- No image preprocessing (deskewing, contrast fixes), so clear and upright scans work best.
- Uses OpenRouter's free model routing, so the model that answers can change and output quality may vary between runs.
- OCR is set up for English and Turkish; other languages need extra Tesseract language packs.

## Requires

- Docker
- OpenRouter account (free API key)
- Git

Terminal: runs Docker locally. Network: calls OpenRouter. Env var: OPENROUTER_API_KEY. Invoice text is sent to OpenRouter's LLM.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Invoice OCR Extractor skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does this skill improve upon simply sending OCR text to a standard LLM?

Pydantic validation catches malformed or incomplete LLM output, so bad responses are rejected with a clear error instead of passing through.

### What files and assets are included in this package?

The package includes the complete Python source code, a pre-configured Dockerfile for containerized deployment, and a requirements file containing all necessary dependencies for FastAPI and Tesseract.

### Can I host this service entirely on my own infrastructure?

Yes, the skill is fully containerized with Docker, meaning it can be deployed on any local machine, private server, or cloud provider that supports container runtimes without worrying about local dependency conflicts.

### Are there any limitations regarding document length or language?

The skill currently extracts data from the first page of any submitted PDF and is optimized for English and Turkish text; however, it can be customized to support additional Tesseract language packs.

### Are there any external accounts or API keys required to use this skill?

You will need an active OpenRouter API key to power the LLM-based text-to-JSON mapping, as well as Docker installed on your host machine for the easiest setup.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
