Open OCR CLI
Agent-first, provider-neutral document extraction for the command line.
Turn images, PDFs, and public URLs into text or validated structured data — through Gemini, Kimi K3, Meta Muse Spark, OpenRouter, or any OpenAI-compatible endpoint — behind one consistent extraction contract.
Quick start · Modes · Commands · Agents and MCP · Providers · Full CLI reference
Quick start
Requires Node.js 20.19+, 22.13+, or 24+ and one provider key
(--dry-run needs none).
npm install --global open-ocr-cli
export GEMINI_API_KEY="your-key"
open-ocr-cli extract invoice.pdf
Switch providers with a flag:
open-ocr-cli extract invoice.pdf --provider kimi # MOONSHOT_API_KEY
open-ocr-cli extract invoice.pdf --provider openrouter \
--model moonshotai/kimi-k3 # OPENROUTER_API_KEY
Keys are read only from the environment or a project .env — never from a flag
or config file. With no arguments the CLI prints help and never prompts, so
scripts and CI stay deterministic; interactive, init, and doctor cover the
guided paths.
Also available as a Docker image
(ghcr.io/cyanxxy/open-ocr-cli), a GitHub Action
(cyanxxy/open-ocr-cli@v3), and a Homebrew formula.
Extraction modes
| Mode | Command | Best for |
|---|---|---|
| Simple | extract --mode simple |
General text, layout, equations, image descriptions |
| Template | extract --preset <id> |
Invoices, receipts, resumes, business cards |
| Custom schema | extract --schema <file> |
Your own validated JSON structure |
| Agentic | extract --mode agentic |
Iterative field recovery and targeted region re-OCR |
| Web | web <urls...> |
Grounded extraction from public URLs |
Schemas are validated locally — both the schema and the model's returned value — before anything is written. Invalid JSON or a schema mismatch is never persisted as a success.
Agentic mode uses a two-loop design: an outer document loop evaluates confidence and coverage, while an inner loop lets the model call one tool (structure analysis, batch field extraction, region re-OCR), inspect the result, and decide what to do next. The document is sent once.
Commands
| Command | Purpose |
|---|---|
extract <inputs...> |
Extract files, directories, globs, or binary stdin (-) |
web <urls...> |
Grounded extraction from up to 20 public HTTP(S) URLs |
run --request <file> |
Execute a versioned machine-protocol request |
mcp |
Serve OCR tools over the Model Context Protocol stdio transport |
capabilities · schema |
Advertise providers, modes, limits, error codes; print JSON Schemas |
init · doctor · interactive |
Configure, diagnose, and explore |
status [output] |
Audit a completed or interrupted batch |
presets · models · providers |
Discover templates, model IDs, and provider profiles |
# Recursive, resumable batch
open-ocr-cli extract ./documents --output ./results --concurrency 4 --resume
# Structured invoice artifacts (markdown + JSON + CSV)
open-ocr-cli extract ./invoices --preset invoice --format all --output ./invoice-results
# Validate the full plan without credentials, API calls, or writes
open-ocr-cli extract ./documents --dry-run
Extracted content and JSONL events go to stdout; progress and diagnostics go
to stderr — every command composes safely in a pipeline.
Flags, configuration keys, batch semantics, cost controls, and exit codes: packages/cli/README.md
Agents and MCP
Three entry points wrap the same job engine: extract (human-facing), run
(versioned protocol), and mcp (Model Context Protocol).
Machine protocol — run executes a protocol v2 request validated against
published Draft 2020-12 JSON Schemas, returning a typed result object or an
ordered JSONL event stream with stable sequence numbers and typed error codes
carrying recovery hints:
open-ocr-cli capabilities --json
open-ocr-cli run --request request.json --response-format jsonl
MCP server — open-ocr-cli mcp starts a stdio server exposing
ocr_extract, ocr_run_agentic, and ocr_web, plus an
open-ocr://capabilities resource. The host must open MCP revision
2026-07-28; clients that use the earlier initialize handshake are rejected:
{
"mcpServers": {
"open-ocr": {
"command": "open-ocr-cli",
"args": ["mcp"]
}
}
}
MCP local inputs use the same typed { "type": "path", "path": "…" } objects
as the machine protocol. Partial document results carry a typed
partialReason and nextAction; the separate extract --jsonl v1 dialect is
published through open-ocr-cli schema jsonl-v1.
Agent skill — a validated skill for Claude Code, Codex, and compatible
agents ships at
integrations/open-ocr/skills/open-ocr/SKILL.md
and in the npm package under skills/open-ocr/.
All three are reference-first: large bodies land in .open-ocr-results/<runId>
artifacts instead of flooding an agent's context, cancellation is honored, and
under mcp stdout carries only transport messages.
Providers
| Profile | Default model | Documents | Structured output | Agent tools |
|---|---|---|---|---|
gemini |
gemini-3.5-flash |
Images and native PDFs | Yes | Native Interactions API |
kimi |
kimi-k3 |
Images; PDFs via Kimi file extraction | Yes | OpenAI-compatible tool calls |
muse |
muse-spark-1.1 |
PNG, JPEG, WebP, GIF, PDF | Yes | OpenAI-compatible tool calls |
openrouter |
google/gemini-3.5-flash |
Model-dependent | Model-dependent | Model-dependent |
openai-compatible |
Required | Images; PDF not assumed | Endpoint-dependent | Endpoint-dependent |
Named profiles supply endpoints, credential variable names, and multimodal wire
formats; openrouter and openai-compatible take arbitrary upstream model IDs.
Any provider can also run through Cloudflare AI Gateway with --gateway cloudflare, including BYOK.
Model catalogs, reasoning levels, cost estimates, and gateway configuration are documented in the CLI reference.
Limits and guarantees
| Constraint | Limit |
|---|---|
| Formats | PNG · JPEG · WebP · GIF · HEIC · HEIF · PDF (video is rejected) |
| Size | Images 70 MB raw · PDFs 50 MB and 1,000 pages |
| Batches | 1,000 files and 5,120 MB by default; concurrency 1–16 |
| Output | Markdown · JSON · CSV · JSONL · agent audit steps |
Every discovered input gets a succeeded, partial, failed, or skipped result — no silent loss. Batches are fingerprinted and resumable, output is lock-guarded and no-clobber, and truncated, blocked, or schema-invalid model responses fail closed rather than being written as success.
There is no backend and no telemetry: documents go to the selected provider or gateway and nowhere else. Web OCR rejects credentials in URLs, localhost, private ranges, and tunnel hosts, and pins DNS across redirects. Report vulnerabilities privately via SECURITY.md.
Repository layout
One npm workspace, two packages over a shared extraction engine:
| Path | What it is |
|---|---|
packages/engine |
@open-ocr/engine — providers, extraction modes, agent loop, protocol types. Private, never published; the CLI bundles it at build time. |
packages/cli |
The published open-ocr-cli npm package: CLI, machine protocol, and MCP server over one job service. |
integrations/open-ocr/skills |
Agent skill source of truth (packages/cli/skills is a generated copy). |
evals/ |
Evaluation corpus and runner. |
examples/ |
A custom JSON Schema and a protocol request (.open-ocr-cli.example.json is the annotated config file). |
scripts/ |
Release, packaging, skill-sync, and smoke-test tooling. |
Both packages are typechecked without DOM libraries on purpose: a browser API
reaching this code fails the build rather than failing at runtime. Anything
host-specific — such as region cropping — enters the engine through an adapter
the host supplies (packages/cli/src/nodeRegionCropper.ts).
Contributing
Setup, PR gates, and release steps are in CONTRIBUTING.md. Behavior changes need tests or evaluation evidence; the evaluation suite is documented in evals/README.md.
Issues · Releases · Changelog · Security · Code of Conduct
MIT Licensed — see LICENSE