---
title: "Classify a document"
method: POST
path: "/v1/documents/classify"
tags: ["Documents"]
---

# Classify a document

`POST /v1/documents/classify`

## Request

- Base URL: `https://console.nace.ai`
- URL: `https://console.nace.ai/v1/documents/classify`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/nace/apis/drex-api/docs/v1/documents/classify/post.ts> (a function with typed inputs; its response is checked against the schema)

Classifies a document, or each page, into your classes.

- **Body:** the document service's request for this operation. [Classify](/docs/ndi/classify) lists its options and result.
- **`source`:** a `url`, or a `workspace_file` you uploaded. Classify reads the original file, so a `parse_result` source answers `422`. Upload one with `POST /v1/documents/upload-grants`.
- **Billing:** admitted only with reserved free/prepaid credit or explicitly enabled pay-as-you-go. Execution stops at its funded limit. Final credits are charged once after successful completion. A job that fails or is cancelled before completion is not charged.
- **Retries:** the same `Idempotency-Key` with the same body returns the same job. With a different body, it answers `409`.

## Query parameters

- `wait_seconds` integer

## Headers

- `Idempotency-Key` string

## Request body

- DocumentClassifyRequest: Classifies one document against the classes you supply.
  - `classes` ClassifyClass[], required: Caller-defined classes to score the document against.
    - `criteria` string[]: Optional extra rules the model should apply when scoring this class.
    - `description` string: What belongs in this class. Used as model guidance.
    - `id` string, required: Stable caller-defined id returned on labels. Not the reserved other group.
    - `label` string, required: Human-readable class name shown in results.
    - `subclasses` ClassifySubclass[]: Optional finer labels nested under this class.
      - `criteria` string[]
      - `description` string
      - `id` string, required
      - `label` string, required
  - `context` ClassifyContext: Caller-supplied context about the document being classified. Today this carries only the audited entity's name. Direction-sensitive categories (``supplier_invoice`` vs ``sales_invoice``, ``customer_purchase_order`` vs ``purchase_order``, and similar pairs across the taxonomy) read the same document two different ways depending on which side of it is the audited entity, and the model is never told that otherwise. Naming it here lets the decision read the document's own buyer/supplier or issuer/recipient cues against the right side.
    - `entity_aliases` string[]: Other names the audited entity is known by in its documents (trading names, former names, abbreviations).
    - `entity_name` string, nullable: The audited entity's name, exactly as it would appear on its own letterhead or as the counterparty on a document it did not issue. Omit when the caller does not know it or it does not apply; direction-sensitive categories are then decided without the hint, as they always have been.
  - `corpus_sources` WorkspaceFileSource[]: Workspace files the run can see besides `source`.
    - `file_id` string, uuid, required: File id from GET /v1/workspaces/{workspace_id}/files.
    - `type` 'workspace_file'
    - `workspace_id` string, uuid, required: Workspace that owns the file.
  - `granularity` 'document' | 'page': Score the whole document once, or return one unit per selected page.
  - `name` string, nullable: Optional display name for the run.
  - `output` ClassifyOutputOptions
    - `delivery` 'progressive' | 'complete': Progressive publishes labels on the running job before the reason finishes. Complete waits for reasons (or their failure) before any result. Only meaningful when include_reason is true. Does not change the final result.
    - `include_reason` boolean: When true, each label may include a short reason string.
    - `max_alternatives` integer: How many ranked labels to return per unit, including the winner.
  - `page_ranges` PageRange[], nullable: One-based inclusive page ranges to classify. Omit to use the whole document.
    - `end` integer, required: Last page of the range, 1-based and inclusive.
    - `start` integer, required: First page of the range, 1-based and inclusive.
  - `parse_mode` 'low' | 'medium' | 'high': How much parsing effort to use: Low uses native OCR, Medium routes to the best parser, and High adds page verification and correction.
  - `project_id` string, uuid, nullable: Caller-minted grouping id; jobs submitted together share it. Not a server-side resource.
  - `source` object, required: One of two kinds: - **A URL:** `{"type":"url","url":"https://...","file_name":"a.pdf"}` - **A workspace file:** `{"type":"workspace_file","workspace_id":"...","file_id":"..."}` Classify reads the original file, so it doesn't take a `parse_result` source (`422`).
  - `unknown_policy` 'allow' | 'force_best': allow may mark a unit unknown. force_best commits an ambiguous unit to one of your classes instead of abstaining. A blank or unreadable page the model sees is assigned the closest listed class — the closed decode vocabulary has no page-state tokens. A unit that could not be parsed is still returned unknown. Pages never read by any model because of document size are also returned unknown and disclosed as classification_unread_pages.

## Response `200`

The job finished within `wait_seconds`, or this is a replay of its Idempotency-Key.

- DocumentJob: The document service job, with artifact links rewritten for Drex and cost set to its recorded customer wallet charge. Pending or unknown cost is null. Upstream service tariffs are separate.
  - `job_id` string, uuid, required
  - `kind` 'parse' | 'split' | 'classify' | 'extract' | 'ground', required
  - `status` 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled', required
  - `result` unknown
  - `credits` integer, nullable: Credits the job used; final once `usage_final` is true. Drex charges the job's final billable usage once, at the USD price pinned when it was admitted (see Models & pricing). `credits` is the document service's usage count, not a multiplier for the per-page or per-target price. A failed job is never charged, including when it produced partial results. A job cancelled before completion is not charged, including delivered parts.
  - `usage_final` boolean
  - `timing` DocumentTiming: Original server-side Parse service timing, in milliseconds. Total includes preparation, NDI queueing/processing and active final result preparation. Upload, browser network/rendering and idle time awaiting another client read are excluded. The first usable published preview and final result use the same origin. Missing measurements remain null. Historical jobs can omit timing.
    - `received_at` string, date-time, required: When the original Parse handler received its request, before authentication and admission. Replays preserve this origin.
    - `observed_at` string, date-time, required: Server time of this timing snapshot.
    - `completed_at` string, date-time, nullable, required: First time the service prepared the terminal response, preserved across subsequent reads.
    - `elapsed_ms` integer, nullable, required: Current server elapsed estimate, or frozen total_ms once completed.
    - `total_ms` integer, nullable, required: Frozen service duration: preparation_ms + queue_ms + ndi_processing_ms + result_preparation_ms. Null until completed. delivery_wait_ms is excluded.
    - `first_response_ms` integer, nullable, required: Original request to first usable preview publication on the server. For atomic delivery, equals total_ms. Null if not measured; browser rendering and transport are excluded.
    - `breakdown` DocumentTimingBreakdown, required
      - `preparation_ms` integer, nullable, required: Original Drex request receipt to NDI job creation, including authentication, admission, source checks and internal submission.
      - `queue_ms` integer, nullable, required: NDI job creation to its processing start.
      - `ndi_processing_ms` integer, nullable, required: NDI processing start to finish, including document finalization.
      - `result_preparation_ms` integer, nullable, required: Active result-read request work after NDI finishes, including internal transfer, funding settlement and result preparation.
      - `delivery_wait_ms` integer, nullable, required: Idle interval after NDI finishes and before the request that prepares the final result begins. Excluded from total_ms; reopening a completed job does not inflate processing time.
      - `document_finalization_ms` integer, nullable, required: All requested previews being saved to NDI finishing; included inside ndi_processing_ms, not an additional summand. Null if publication milestones were not measured.
  - `cost` DocumentCost
    - `currency` 'USD', required
    - `pricing_version` string, required
    - `total_usd` string, required: Exact decimal USD wallet charge.
    - `lines` DocumentCostLine[], required
      - `operation` 'parse' | 'split' | 'classify' | 'extract' | 'ground', required
      - `quantity` integer, required
      - `unit` 'page' | 'target', required
      - `execution` 'fresh' | 'reused', required
      - `unit_price_usd` string, required
      - `amount_usd` string, required
      - `reuse_reason` string, nullable, required

## Other responses

- `202`: The job was created and hasn't finished: its `status` is `queued` or `running`. Poll `GET /v1/documents/jobs/{id}`.
- `401`: Missing or invalid API key (`authentication_error`, code `invalid_api_key`).
- `402`: The account has insufficient available funds (`insufficient_credit`) or an unpaid invoice (`payment_required`).
- `409`: The Idempotency-Key was already used for a different request (`conflict_error`, code `idempotency_conflict`).
- `413`: The request body is over 1,000,000 bytes (`invalid_request_error`, code `payload_too_large`).
- `422`: The body is not valid JSON, names a source the account doesn't own (code `invalid_source`), or the document service refused it (`invalid_request_error`).
- `429`: Over the account's requests per minute for document routes, or the document service is throttling this account (`rate_limit_error`); or the free or low-balance prepaid account already has 50 unfinished document jobs and browser runs (code `job_limit_reached`, wait for one to finish).
- `500`: Something failed on Drex's side (`internal_error`).
- `502`: The document service refused Drex's own request (`upstream_error`, code `ndi_refused_drex`). Retry later.
- `503`: Document billing is not configured (code `document_billing_not_configured`), the job is not confirmed yet (code `job_pending`; retry with the same key), or the document service is unavailable.
- `504`: The document service timed out (`upstream_error`).
- `529`: The public API is paused (code `service_disabled`) (`overloaded`).

---

[API](https://skmtc.dev/nace/apis/drex-api.md) - [All operations](https://skmtc.dev/nace/apis/drex-api/llms.txt) - [OpenAPI document](https://skmtc.dev/nace/apis/drex-api/revisions/a0e62d925a61?raw)
