Skip to Content
NexPDF

AI extraction and classification

Pull structured data out of documents, or sort them into your own categories, with Claude.

English

Two endpoints read a document's text with Claude, Anthropic's model, and answer with JSON in the shape you ask for:

EndpointFieldsAnswers
POST /v1/ai/extractdocument; schema (a JSON Schema); prompt (optional){ "data": … }, following your schema
POST /v1/ai/classifydocument; labels (a JSON list); prompt (optional){ "label": …, "reason": … }

Any file convert accepts works, uploaded or by link. Scanned documents need text first: run OCR and send its result.

Extract data

Describe what you want with a JSON Schema whose top level is an object. The answer always parses and always matches the schema: required fields are present and types are right. Fields the document does not state come back empty or null rather than invented, so make a field optional (leave it out of required) when a document may not have it.

curl https://api.nexpdf.dev/v1/ai/extract \
  -H "Authorization: Bearer $NEXPDF_API_KEY" \
  -F document=@invoice.pdf \
  -F 'schema={
    "type": "object",
    "properties": {
      "invoice_number": {
        "type": "string"
      },
      "issue_date": {
        "type": "string",
        "format": "date"
      },
      "supplier": {
        "type": "string"
      },
      "total": {
        "type": "number"
      },
      "currency": {
        "type": "string",
        "description": "ISO 4217 code"
      },
      "lines": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "description": {
              "type": "string"
            },
            "amount": {
              "type": "number"
            }
          },
          "required": [
            "description",
            "amount"
          ]
        }
      }
    },
    "required": [
      "invoice_number",
      "issue_date",
      "supplier",
      "total",
      "currency",
      "lines"
    ]
  }'
{
  "data": {
    "invoice_number": "INV-2026-0412",
    "issue_date": "2026-11-03",
    "supplier": "Northwind Traders Ltd",
    "total": 1840.5,
    "currency": "EUR",
    "lines": [
      { "description": "Consulting, October", "amount": 1500 },
      { "description": "Travel", "amount": 340.5 }
    ]
  }
}

Schemas may use type, properties, required, items, enum, const, anyOf, format (such as date and email), description and $defs. Objects are closed: properties you did not list are never returned. minimum, maximum, minLength and maxLength are not supported and are ignored; check ranges in your code. A description on a field is the best place to say what you mean ("ISO 4217 code", "the date the invoice was issued, not the due date").

Classify documents

Give 2 to 100 labels, as names or as { "name", "description" } when a name alone is ambiguous. The answer is always one of your labels, with a sentence on what decided it.

curl https://api.nexpdf.dev/v1/ai/classify \
  -H "Authorization: Bearer $NEXPDF_API_KEY" \
  -F document=@incoming.pdf \
  -F 'labels=[
    "invoice",
    "receipt",
    {
      "name": "contract",
      "description": "An agreement to be signed or already signed"
    },
    {
      "name": "other",
      "description": "Anything else"
    }
  ]' \
  -F "prompt=Judge by the document itself, not by any cover letter."
{ "label": "invoice", "reason": "It lists amounts due with a payment deadline and an invoice number." }

Instructions

prompt adds your own instructions, up to 4,000 characters: "Amounts are in thousands", "Use the billing address, not the shipping address". The document's own text is treated as data, never as instructions, so a document cannot change what the model does.

Cost and limits

  • 1 unit per 4,000 characters of text, 2 at least, plus the conversion to PDF when the document is not one. A 10-page contract is usually about 8 units. The response's x-nexpdf-units header says what each request cost.
  • Up to 300,000 characters of text (about 100 pages). Longer documents are refused with 413 document_too_long rather than cut short, so an answer never silently comes from part of a document: split the document first.
  • If the model declines to process a document, the request fails with 422 ai_refused; if the answer would be longer than the model can write, with 422 ai_incomplete (ask for fewer fields). Neither is charged.

Privacy

The document's text is sent to Anthropic's API to answer the request. Under Anthropic's commercial terms, API data is not used to train its models, and NexPDF Cloud keeps nothing after the response. When documents must not leave your own network, use the NexPDF SDK instead, which extracts text and structure on your own servers. See security and privacy.

On this page