/docutray:docutrayfrom docutray
When the DocuTray MCP tools are available (e.g. installed with the DocuTray plugin), use them first; otherwise use docutray-cli (or the Python/Node SDKs / REST API) to convert documents to structured data, identify document types, manage extraction schemas (types), split a file with several documents into typed segments and extract each one, run processing steps, write/test/save DSL validation rules, and create custom document types. Covers install, authentication (recommended for agents: `docutray login --oauth`, which drives an OAuth browser flow without exposing the API key to the conversation; alternatives: DOCUTRAY_API_KEY env var, --api-key flag, --base-url for staging), and troubleshooting. Use this skill whenever a task involves docutray, document conversion, document-type identification, splitting a bundle or multi-document file, or extraction schemas.
Ships in docutray. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
DocuTray is an AI-powered document processing platform. The CLI (@docutray/cli) and SDKs convert documents (PDF, JPEG, PNG, GIF, BMP, WebP) into structured JSON using extraction schemas called document types.
Use it for any task that touches DocuTray: setting up auth, converting documents, identifying document types, splitting a file that holds several documents, listing or inspecting types, running processing steps, writing/testing/saving DSL validation rules, or designing custom document types and schemas.
The CLI is the canonical interface in this skill. Python, Node, and REST equivalents live in references/.
If your tool list includes any DocuTray MCP server (the DocuTray plugin, the claude.ai connector, or one added with claude mcp add) — tools such as convert_document, identify_document, list_document_types and get_conversion_status — use those tools first. They authenticate with OAuth: no API key, no CLI install. Use the rest of this skill to choose document types, design schemas and read results, mapping each CLI command to the equivalent tool:
| CLI (or SDK) | MCP tool |
|---|---|
docutray convert <file> -t <type> | convert_document (file URL or base64; waits briefly) |
docutray convert status <id> / convert … --async polling | get_conversion_status with the conversion_id |
docutray identify <file> --types a,b | identify_document, then get_identification_status |
docutray split <file> --types a,b | split_document, then get_split_status (no cropping: see Section 4) |
docutray types list [--search …] | list_document_types |
docutray types get <code> | get_document_type |
docutray types rules get <code> | get_document_type (dslRules) |
docutray types rules test <code> --data data.json --rules rules.dsl | validate_document_data (document_type, data, optional dslRules override) |
docutray types rules set <code> rules.dsl / --clear | update_document_type_validation_rules (exactly one of documentTypeId / codeType, plus dslRules; null clears) |
Use the CLI, an SDK or the REST API (sections below) only when the MCP tools are not available, or for operations they do not cover (creating or editing schemas, running steps, exporting types). Rule writes through MCP require docutray:document_types:write; test proposed rules with validate_document_data before saving.
| Project marker | Integration path | Reference |
|---|---|---|
| Agent / shell / no project | CLI (default) | references/setup/cli.md |
pyproject.toml or requirements.txt | Python SDK | references/setup/python.md |
package.json or tsconfig.json | Node SDK | references/setup/node.md |
| Other languages | REST API | references/setup/rest.md |
For agents working without a project context, default to the CLI path.
dt_live_). It is shown only once.Never hardcode keys. Use DOCUTRAY_API_KEY.
Recommended for agents — docutray login --oauth (requires @docutray/cli >= 0.3.2). The CLI prints the authorization URL to stderr, opens the user's browser, waits for the callback, and writes the resulting API key to ~/.config/docutray/config.json. The agent never sees the unmasked key — the success JSON only includes a masked form (<first-4>****<last-4>).
docutray login --oauth
# stderr → "Open this URL to authorize: https://app.docutray.com/api/auth/oauth2/authorize?..."
# stderr → "Opening browser for authentication..."
# (user authorizes in their browser; if Claude Code can't reach the user's browser
# directly, surface the URL so the user can open it themselves)
# stdout ← {"message":"Login successful","apiKey":"dtXJ****dWhx",
# "organizationId":"...","organizationName":"...",
# "configPath":"/Users/.../config.json"}
Useful related flags:
docutray login --oauth --no-browser # print URL only; don't auto-open
docutray login --oauth --timeout 60 # default 180s
docutray login --oauth --base-url https://staging.docutray.com
When OAuth isn't possible (CI, headless server, no browser) — fall back to the env var:
export DOCUTRAY_API_KEY="dt_live_your_key_here"
This works in any shell and overrides the config file. Other non-interactive forms when the user already has a key in hand:
docutray login --api-key dt_live_your_key_here # flag form
docutray login dt_live_your_key_here # positional form
Bare docutray login is interactive — it requires a TTY and errors with Non-interactive mode requires --api-key flag or api-key argument inside an agent shell. Only useful when the user runs it themselves (e.g. ! docutray login in Claude Code).
Credentials live at ~/.config/docutray/config.json. The env var takes precedence when both are set.
docutray status
Successful output shows authenticated: true, the masked API key, the credential source (env var or config file), and the active base URL. If a user authenticated in another terminal, run docutray status to confirm.
SDK and REST setup details: see
references/setup/{python,node,rest}.md. Troubleshooting: seereferences/setup/troubleshooting.md.
Convert a document to structured JSON using a document type code.
# Synchronous (default) — output goes to stdout as JSON
docutray convert invoice.pdf --type electronic-invoice
# Save to a file via shell redirection
docutray convert invoice.pdf -t electronic-invoice > result.json
# A public URL is also accepted as the source
docutray convert https://example.com/doc.pdf -t electronic-invoice
# Async with status updates on stderr (useful for large docs)
docutray convert large-doc.pdf -t electronic-invoice --async --timeout 600
# Webhook notification on completion
docutray convert receipt.jpg -t receipt --webhook-url https://example.com/hook
# Attach metadata
docutray convert invoice.pdf -t electronic-invoice \
--metadata '{"ref":"order-123"}'
Flags (full list — there is no --output and no --format; save to file with shell redirection):
| Flag | Required | Description |
|---|---|---|
-t, --type=<code> | yes | Document type code (run docutray types list to see available codes) |
--async | no | Use async polling; status updates are emitted to stderr |
--json | no | Force JSON output (default when piped) |
--metadata=<json> | no | Attach JSON metadata to the conversion |
--timeout=<seconds> | no | Polling timeout for async (default 300) |
--webhook-url=<url> | no | POST a notification when conversion completes |
Response shape — top-level data whose keys come from the active document-type schema. Example values are illustrative and depend on the schema (DocuTray's default org schemas often use Spanish keys):
{
"data": {
"moneda": "EUR",
"fecha_emision": "2026-04-12",
"total": 1500.00,
"detalle": [
{ "descripcion": "Servicios", "cantidad": 1, "importe": 1500.00 }
]
}
}
Validation is informational: convert and convert status return extracted data even when validation fails. validation is an outcome {valid, errors: [], warnings: []}, null when the type has neither schema nor rules, or {"status":"error"} when checks could not complete or no record exists. The last case does not mean invalid data. Older deployments may omit the field. Inspect it explicitly; conversion success is not a validity gate.
# Recover a result after an async timeout; this queries once, without polling
docutray convert status conv_abc123 --json
Requires @docutray/cli >= 0.6.0 for convert status and validation display.
Depth:
references/platform/convert.md— async patterns, SDK/REST equivalents, batch processing, error recovery.
Detect the best-matching document type for a file or URL among a candidate set you provide. Returns the top match plus alternatives ranked by confidence.
--types is required in practice. Calling docutray identify <file> without it returns {"error":"Validation error","status":400} (the CLI --help lists --types as optional, but the API rejects requests without it). Pass a non-empty comma-separated list of document type codes — narrow it to the plausible candidates for your document.
# Always pass --types with candidate codes
docutray identify document.pdf --types invoice,receipt,contract
# URL source (also requires --types)
docutray identify https://example.com/doc.pdf --types invoice,factura_internacional
# Async with status polling
docutray identify document.pdf --types invoice,receipt --async
Flags: --async, --json, --types <comma-separated codes>. There is no --output flag, no -t/--type (singular).
Picking candidate codes. Use file-name / context hints first; if you need to look up codes, run docutray types list --json | jq -r '.data[].codeType' and choose plausible ones. Don't pass every available code — some types in the list may not be usable by your org and will return 403 You do not have permission to use the following document types: ….
Response shape (no data wrapper; document_type is an object):
{
"document_type": {
"code": "invoice",
"name": "Invoice",
"confidence": 0.99
},
"alternatives": [
{ "code": "factura_internacional", "name": "Factura Internacional", "confidence": 0.2 },
{ "code": "otro", "name": "Otro/No identificado", "confidence": 0.01 }
]
}
Confidence interpretation (read .document_type.confidence):
>= 0.9 — high; safe to feed straight into convert.0.7 – 0.9 — moderate; review or ask the user.< 0.7 — low; verify manually or check whether a custom type is needed.Depth:
references/platform/identify.md.
A file that holds several documents (a scanned bundle, an expense report with its receipts, a photo of three receipts) must be split before converting: convert and identify assume one document per file. Split returns one segment per document — page range, document type among your candidates (or the implicit otro), and in beta the regions where it sits on each page. It does not extract data. Requires @docutray/cli 0.7.0+ (Node SDK docutray 0.3.0+, Python SDK docutray 0.4.0+ with the docutray[split] extra for cropping).
# Segments only (1 to 20 candidates; never pass "otro")
docutray split bundle.pdf --types factura,boleta --json
# Split, crop every non-"otro" segment locally and convert it with its type
docutray split bundle.pdf -t factura,boleta --extract --json \
| jq '.segments[] | select(.conversion.status == "SUCCESS") | {index, code: .document_type.code, data: .conversion.data}'
# Save the crops (segment-<index>-<code>.pdf|png, or the image's extension) without converting
docutray split photo.jpg -t boleta --output-dir crops
# Start now, read later
docutray split bundle.pdf -t factura --no-wait
docutray split status <split_id>
Flags: -t/--types (required), --extract, --output-dir, --metadata (flat values with a local file, or a URL with --extract/--output-dir), --timeout (default 1800 s), --no-wait, --json. A FAILED split exits 1. With --extract, a segment that fails gets an error (or, after a conversion timeout, its conversion_id to read with docutray convert status), the others go on, all segments are still printed with the split_id, and the exit code is 1; a conversion can end ERROR (.conversion.status). split status exits 0 in any state: read .status.
A timeout does not cancel the split (a 100-page split can take over 25 minutes). The error names the split_id: read it with docutray split status <split_id>. Never re-run split on the same file to retry — that starts and bills a second split.
Reading the result: statuses end in SUCCESS or FAILED (not ERROR). pages are 1-based and inclusive and two consecutive segments can share a page. confidence_level is high/medium/low (review low). regions is [{page, box: {x0,y0,x1,y1}}] on a 0–1 scale, without margin, or null; flags.multiple_documents_on_page marks segments whose crops deserve a look. Skip otro segments: nothing to extract. Billing: the split counts the file's pages; each conversion of a crop counts its own pages.
Limits: PDF ≤ 100 pages or a single-page image (multi-page TIFF → convert to PDF). A TIFF segment that covers only part of the image cannot be cropped by the CLI (that segment gets an error): convert the TIFF to PNG or PDF before splitting. 400 for otro in the list or > 20 distinct codes; 403 names inaccessible codes; 422 for longer PDFs or password-protected ones.
With MCP, split_document + get_split_status return the same segments but do not crop. If the CLI is available, use docutray split --extract instead (do not split twice); with only MCP, crop the returned segments with an SDK helper and send each crop to convert_document, or report the segments.
Depth:
references/platform/split.md— cropping rules (2 % margin, 200 dpi), MCP, Node (docutray/split) and Python (docutray[split]) helpers, REST and webhooks, errors and limitations.
Read-only operations. To create or update types, see Section 7 (Custom Types).
# List (paginated, search by name)
docutray types list
docutray types list --search invoice
docutray types list --limit 50 --page 2
# Get full details (metadata + JSON Schema) for a single type
docutray types get factura
docutray types get factura --json | jq .jsonSchema # extract just the schema
# Export a type definition (full shape including jsonSchema)
docutray types export factura # to stdout
docutray types export factura -o factura.json # to file
docutray types export factura --force -o factura.json
Subcommands: list, get, export, create, update, rules get/set/test. (No view or delete subcommand exists — use get for inspection; type lifecycle is managed via --draft / --publish on update, or via the dashboard.)
list response — {"data":[…], "pagination":{"total","page","limit"}}. Each item has id, codeType, name, description, isPublic, isDraft, status, createdAt, updatedAt. The identifier field is codeType (not code); pipe with jq -r '.data[].codeType' to extract codes for --types on identify.
get / export response — flat JSON object (no data envelope). Returns the full type definition: the metadata fields above, plus jsonSchema (the actual extraction schema), promptHints, identifyPromptHints, conversionMode (json | toon | multi_prompt), keepPropertyOrdering, conversionSpec (the export mapping, verbatim as stored, or null), and dslRules (business-rule text or null). Extract the schema with jq .jsonSchema. (Schema exposure landed in @docutray/cli/0.3.2; in 0.3.1 only metadata was returned.)
conversionSpec is absent from list items — only the single-type endpoints return it. In human (non---json) output, types get summarizes it on an Export spec line rather than dumping it: 2 sheets, 13 columns, 13 columns, 0 columns (stored but empty), (none) (no spec), or (present) when the shape isn't summarizable. JSON output is never summarized. (Reading the field in JSON works on 0.3.x too — 0.4.0 adds the summary line and the write flags.)
types export supports -o, --output (and --force for overwrite). convert does not.
Depth:
references/platform/types.md— full response shapes, SDK/REST equivalents.
Execute and monitor processing pipelines configured in the DocuTray dashboard.
# Run a step on a local file (waits for completion by default)
docutray steps run extract-fields invoice.pdf
# Run on a URL
docutray steps run extract-fields https://example.com/doc.pdf
# Async — return immediately with execution status
docutray steps run extract-fields invoice.pdf --no-wait
# Attach metadata or a webhook
docutray steps run extract-fields invoice.pdf \
--metadata '{"ref":"order-123"}' \
--webhook-url https://example.com/hook
# Check the status of an async execution
docutray steps status exec_abc123
steps run flags: --no-wait, --json, --metadata, --webhook-url. steps status flag: --json.
Depth:
references/platform/steps.md— pipeline configuration, polling patterns, error recovery.
When no existing type fits, design a new document type. The high-level flow:
docutray types list --search <term> and docutray identify <file> --types <candidates> before creating anything.docutray types create (full flag set) or docutray types update <code>. Both accept --schema (file path or inline JSON), --name, --description, --prompt-hints, --identify-hints, --conversion-mode {json|toon|multi_prompt}, --conversion-spec, --keep-ordering, --publish/--draft. create additionally requires --code; update additionally accepts --no-conversion-spec.--code invoice in org Acme is stored as acme_invoice, and the bare code 404s). Run docutray convert <sample> -t "$(… --json | jq -r .codeType)" and iterate.docutray types create \
--name "Custom Invoice" \
--code custom-invoice \
--description "Acme Corp invoice format" \
--schema schema.json \
--prompt-hints "Dates DD/MM/YYYY; comma is decimal separator." \
--identify-hints "Acme Corp logo top-left; PO numbers start with 'PO-'." \
--publish
Schema design — quick rules:
required and nullable: "type": ["string", "null"]. Guarantees the key always appears, with null when missing."format": "date" for dates, enum for fixed value sets, array with items for tabular/repeating data.conversionSpec)A type can also carry a conversion spec — the mapping from extracted JSON to CSV/Excel columns used by tray export. The schema decides what gets extracted; the spec decides how it lands in a spreadsheet. Two shapes:
{ "columns": [{ "header": "Total", "jsonPath": "$.total" }] } // single table
{ "sheets": [{ "name": "Detalle", "columns": [ /* … */ ] }] } // multi-sheet
Columns take header (required) plus optional jsonPath, type (data | formula), and formula. Paths select from the type's own jsonSchema.
# Set at creation — accepts inline JSON, a bare-spec file, or a full `types export` payload
docutray types create --name "Invoice" --code invoice --description "…" \
--schema schema.json --conversion-spec spec.json
docutray types update invoice --conversion-spec spec.json # replace
docutray types update invoice --no-conversion-spec # clear (mutually exclusive with the above)
docutray types get invoice # → "Export spec: 5 columns" (≠ "(none)")
The --schema asymmetry: create --schema <export payload> carries the embedded conversionSpec over, so types export → types create round-trips the mapping with no extra flags. update --schema <export payload> deliberately does not — an update only touches the fields you name; use --conversion-spec to change it. An explicit --conversion-spec wins over an embedded one.
Silent drop: against an API deployment predating
conversionSpecsupport the field is accepted and discarded — no error, and the CLI can't detect it. Always confirm withdocutray types get <code>.
Depth:
references/advanced/custom-types-workflow.md(decision tree, progressive disclosure stages, multi-document files, prompt-hint cookbook),references/advanced/schema-design.md(field-type combinations, nesting, complex examples), andreferences/advanced/conversion-spec.md(export mapping: both shapes,jsonPathauthoring, full flag semantics, SDK types).
dslRules)Read the actual jsonSchema and existing dslRules first. Write rules for the user’s business constraints using those field names, then dry-run before saving, checking representative valid and invalid data. JSON Schema checks structure; DSL checks business logic. Most operators skip missing/null subjects: use required when presence matters.
docutray types rules get acme_invoice --raw > rules.dsl
# Edit rules.dsl, then validate only the extracted data object (not the convert envelope)
docutray types rules test acme_invoice --data extracted.json --rules rules.dsl
# After reviewing the test results, replace the saved rules and read back
docutray types rules set acme_invoice rules.dsl
docutray types rules get acme_invoice
# Test saved rules by omitting --rules
docutray types rules test acme_invoice --data extracted.json
# Remove all rules only when requested
docutray types rules set acme_invoice --clear
Requires CLI 0.6.0+. set takes a positional file, inline DSL or - for stdin, not --file or --rules; --clear cannot accompany a rules argument. test requires --data (JSON file, inline JSON or -) and accepts --rules (file, inline DSL or -); only one input can use stdin. test exit codes: 0 valid, 1 invalid, 2 error (including invalid DSL, input or API failures). Empty rule input is rejected: omit --rules to test stored rules; use set --clear to remove them. Only organization-owned types can be changed; public platform types cannot.
With MCP, use get_document_type, then validate_document_data with the proposed dslRules override, then update_document_type_validation_rules, and read back. A dry-run never saves rules. Compilation errors include line/column diagnostics; fix them before retrying.
Read Validation rules for DSL syntax, examples, MCP parameters, SDK/REST equivalents, and result interpretation.
Out of scope for this skill: pipeline creation (steps design).
# Pick plausible candidate types from context/filename, then identify
TYPE=$(docutray identify document.pdf --types invoice,receipt,factura_internacional --json \
| jq -r '.document_type.code')
docutray convert document.pdf -t "$TYPE"
for f in documents/*.pdf; do
docutray convert "$f" -t electronic-invoice > "${f%.pdf}.json"
done
docutray split bundle.pdf -t factura,boleta --extract --json > bundle.json; status=$?
# Empty or segment-less bundle.json: the command failed before the result (stderr has the error)
jq -e '.segments' bundle.json > /dev/null || echo "split failed (exit $status)"
# Exit code 1 with segments: some failed (crop, start or conversion)
jq -r '.segments[] | select(.error or (.conversion and .conversion.status != "SUCCESS")) | .index' bundle.json
docutray types list --search invoice
docutray types get electronic-invoice
docutray convert invoice.pdf -t electronic-invoice
| Symptom | Cause | Fix |
|---|---|---|
command split not found / Command split not found | CLI older than 0.7.0 | Upgrade: npm i -g @docutray/cli@latest, then docutray split --help |
Non-interactive mode requires --api-key flag or api-key argument | Bare docutray login invoked without a TTY (agent / CI) | Use docutray login --oauth (preferred), docutray login --api-key dt_live_..., the positional form, or set DOCUTRAY_API_KEY |
| OAuth login hangs / never returns | User hasn't authorized in browser yet, or callback can't reach localhost:9876 | Wait up to 180s (default --timeout); pass --timeout <seconds> to shorten; verify port 9876 is free; use --no-browser and surface the URL to the user manually |
| OAuth logged into the wrong organization | The user has several DocuTray orgs and chose another one on the consent screen, or the CLI is older than 0.5.0 (it picked one on its own) | Re-run docutray login --oauth and pick the organization on the consent screen; upgrade first with npm i -g @docutray/cli@latest if docutray --version is below 0.5.0. Headless fallback: create an API key in that org's dashboard and run docutray login --api-key <key> |
Error: Nonexistent flag: --output (or --format) on convert | Flag does not exist | Use shell redirection > result.json |
401 Unauthorized | Missing or invalid key | Verify with docutray status; re-export DOCUTRAY_API_KEY |
403 Forbidden | Key lacks permissions | Issue a new key in the dashboard |
404 Not Found on convert/get | Document type code wrong | docutray types list --search <term> |
Document type "<code>" not found right after creating it | The API prefixes org-owned types, so the code you passed to --code is not the stored codeType | Read .codeType from the types create --json response (or types list --search) and use that |
415 Unsupported Format | File type not supported | Convert to JPEG/PNG/PDF/etc. |
413 File Too Large | > 100MB | Split or compress |
429 Rate Limited | Throttled | Honor Retry-After |
PROCESSING stuck on a step | Pipeline failure | docutray steps status <id> for details |
{"error":"Validation error","status":400} from docutray identify | Bare docutray identify <file> requires --types. The CLI --help shows it as optional but the API rejects requests without it | Pass --types <comma-separated codes> with plausible candidates (e.g. --types invoice,receipt) |
403 You do not have permission to use the following document types: … from identify | Some codes returned by types list aren't usable by your org | Drop the offending codes from the --types list; try a smaller candidate set |
400 from split mentioning otro | otro is always an implicit candidate | Remove otro from --types |
422 from split | PDF over 100 pages, multi-page TIFF, or password-protected PDF | Split the PDF into ≤ 100-page parts; convert TIFFs to PDF; remove the user password |
| Low identify confidence | No matching type among the candidates passed | Widen the --types list, or design a custom type (Section 7) |
command types:view not found / types:delete not found | Subcommand doesn't exist | Use types get / there is no delete subcommand |
Export spec doesn't appear after types create/update --conversion-spec (types get shows (none)) | API deployment predates conversionSpec support — the field is accepted and silently discarded, and the CLI can't detect it | Verify with docutray types get <code> after every write; if it stays (none), the deployment needs updating |
--conversion-spec and --no-conversion-spec rejected together | The two flags are mutually exclusive | Pass one: --conversion-spec <file|json> to set, --no-conversion-spec to clear |
Depth:
references/setup/troubleshooting.md(env var/config conflicts, proxy/TLS, version checks) andreferences/setup/rest.md(full error code table).
| Detail | Value |
|---|---|
| CLI package | @docutray/cli (0.6.0+ for rules and conversion validation, 0.7.0+ for split) |
| API key prefix | dt_live_ |
| Production base URL | https://app.docutray.com |
| Staging base URL | https://staging.docutray.com |
| Auth env var | DOCUTRAY_API_KEY |
| Auth config file | ~/.config/docutray/config.json |
| HTTP auth header | Authorization: Bearer <key> |
| Source argument | Local file path or public URL (convert, identify, split, steps run) |
| Supported formats | JPEG, PNG, GIF, BMP, WebP, TIFF, PDF (split: PDF ≤ 100 pages or a single-page image) |
| Max file size | 100 MB |
| Convert response | { "data": { ...schema-driven keys... }, "validation": outcome | null | {"status":"error"} } |
| Pipeline statuses | ENQUEUED → PROCESSING → SUCCESS | ERROR (split: SUCCESS | FAILED) |
| Python min version | 3.10+ |
| Node min version | 20+ |
references/advanced/conversion-spec.md (opens in a new tab)references/advanced/custom-types-workflow.md (opens in a new tab)references/advanced/schema-design.md (opens in a new tab)references/advanced/validation-rules.md (opens in a new tab)references/platform/convert.md (opens in a new tab)references/platform/identify.md (opens in a new tab)references/platform/split.md (opens in a new tab)references/platform/steps.md (opens in a new tab)references/platform/types.md (opens in a new tab)references/setup/cli.md (opens in a new tab)references/setup/node.md (opens in a new tab)references/setup/python.md (opens in a new tab)references/setup/rest.md (opens in a new tab)references/setup/troubleshooting.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub docutray/docutray-skills --plugin docutray