Skip to navigation

Classification Overview

Classification assigns a document to exactly one of the categories you define and returns the match as structured JSON. You describe the possible document types with classifications, and Extend returns the matched type and a confidence score by default. Use it to route incoming documents (invoices vs. bills of lading vs. purchase orders), gate downstream processing, or branch a workflow based on document type.

Quick start

We’ll classify a freight invoice into one of several logistics document types. For this quick start we’ve uploaded the file here.

A freight invoice document

Grab a key from the Developers page and store it as the EXTEND_API_KEY environment variable. If you’re using an SDK, see the installation instructions.

export EXTEND_API_KEY="your_api_key_here"

The /classify endpoint takes a file and a config with the classifications you want to choose between.

from extend_ai import Extend
client = Extend()
result = client.classify(
file={
"url": "https://extend-public-files.s3.us-east-2.amazonaws.com/freight-invoice.pdf",
},
config={
"classifications": [
{
"id": "invoice",
"type": "invoice",
"description": "An invoice or bill requesting payment for goods or services.",
},
{
"id": "bill_of_lading",
"type": "bill_of_lading",
"description": "A bill of lading documenting a shipment of goods.",
},
{
"id": "purchase_order",
"type": "purchase_order",
"description": "A purchase order authorizing a purchase.",
},
{
"id": "other",
"type": "other",
"description": "Any other document type.",
},
],
},
)
print(result)

Want to classify your own document? Upload it first, then pass the returned file id instead of a url (reusing the same config).

with open("freight_invoice.pdf", "rb") as f:
uploaded = client.files.upload(file=f)
result = client.classify(file={"id": uploaded.id}, config=config)

Example response

After you run the code snippet above, you’ll see a response like this. Extend picks the best-matching category and returns an output with the matched classification and a numerical confidence score.

{
"object": "classify_run",
"id": "clr_Xj8mK2pL9nR4vT7qY5wZ",
"status": "PROCESSED",
"output": {
"id": "invoice",
"type": "invoice",
"confidence": 0.97,
"insights": []
}
}

Key fields

FieldWhat it contains
output.idThe id of the matched classification, as defined in your classifications. Branch your logic on this — it’s stable.
output.typeThe type of the matched classification.
output.confidenceNumerical confidence in the match (0 to 1), returned by default.
output.insightsReasoning behind the classification decision. Not always included in latest classifier versions.

For full request/response details, see the Create Classify Run API reference.

Use the output

Branch your logic on the returned id, and use confidence to decide when to route a document to manual review. Match on id rather than type: the id is a stable identifier you control, while type and description are part of the prompt that steers the classification decision and may change as you tune accuracy.

output = result.output
if output.confidence < 0.8:
print(f"Low confidence ({output.confidence}) — route to review")
elif output.id == "invoice":
print("Send to the invoice extractor")

For the full output shape and shared types, see Response Format.

Sync vs async

The example above calls the synchronous /classify endpoint. We also have an asynchronous /classify_runs endpoint that should be used for large files and high volume use cases.

See Async Processing for the full comparison, polling options, and webhook setup.

Save it as a processor

The quick start runs with an inline config, which is perfect for getting started. To reuse a configuration across runs — and to version it, measure its accuracy, and optimize it — save it as a classifier, a kind of processor. Processors are the saved entities you iterate on in the dashboard, run evaluation sets against, and improve with Composer.

Configuration

The quick start sends just file and config.classifications. To control how classification runs, pass more options inside config. Here are the most commonly used ones; for the full reference, see Configuration.

Classifications

The classifications array is the heart of every classifier — the set of categories the model chooses from. Each entry needs a unique id, a type returned in the output, and a description (your biggest lever on accuracy). At least one classification must have the type "other" as a catch-all.

{
"config": {
"classifications": [
{ "id": "invoice", "type": "invoice", "description": "An invoice or bill requesting payment." },
{ "id": "other", "type": "other", "description": "Any other document type." }
]
}
}

Base processor

Choose the processor based on your accuracy, latency, and cost needs. Both include numerical confidence scores (0 to 1) by default. If you omit baseProcessor, Extend uses classification_standard.

ProcessorWhen to use
classification_standardBest balance of accuracy, speed, and cost (default).
classification_instantFastest, lowest-cost classification.

Classification rules

Steer the model with plain-language rules — useful for disambiguating categories that look similar.

{
"config": {
"classificationRules": "When differentiating invoices from purchase orders, the most important signal is whether payment is being requested."
}
}

For every option, including advanced options like context, page ranges, and memory, see the Configuration reference.


Next steps