Skip to main content
POST
Classify

Overview

The /classify endpoint scores a piece of text against a set of labels you define and returns a softmax-normalised probability distribution. Each label is scored using a rubric - a yes/no question that describes what the label means. The label with the highest score is returned as top_label.

Request

string
The text to classify. Provide exactly one of text, chunks, or document. If both text and document are given, the OCR text is appended after text.
array
A batch of inputs to classify against the same labels and system_prompt. Each item is { "id": string, "text": string }; the id is echoed back on the matching result so you can correlate them. Use this instead of sending one request per chunk: the shared profile (labels + system prompt) is billed once for the whole request instead of once per chunk. Cannot be combined with text or document. Capped at 50 chunks per request.
string
A base64-encoded file to classify. Supported formats: JPEG, PNG, TIFF, single-page PDF, multi-page PDF. The file is processed via AWS Textract OCR and the extracted text is used as input. Either text or document must be provided.
string
MIME type of the document (e.g. "image/jpeg", "application/pdf"). Required when document is provided.
array
required
One or more label definitions. Must contain at least one item - sending an empty array returns 422.
boolean
default:"false"
When false (default), the labels are treated as mutually exclusive options: scores are a softmax distribution that sums to 1.0 and exactly one top_label is returned. When true, each label is scored independently (its own yes/no decision), so several labels can apply to the same input at once. Scores are independent probabilities that do not sum to 1, and every label whose score meets threshold is returned in matched_labels. Use this to attach multiple tags to a single input. Capped at 16 labels in multi-label mode.
number
default:"0.5"
Only used when multi_label is true. A label is included in matched_labels when its independent score is greater than or equal to this value. All scores are still returned, so you can also re-threshold client-side.

Response

string
Name of the highest-scoring label.
object
Map of label name → probability score. All values sum to 1.0.
array
Full label list with name, score, and rubric, in the same order as the request.
array
Per-input results. Always present: for a single text/document request it has one element (with id "0") and the top-level top_label/scores/labels mirror it. For a chunks request there is one element per chunk, each carrying its own calibrated scores.
integer
Number of inputs classified (1 for single-input requests).
string | null
The raw text extracted from the document via OCR. null if no document was provided.
Score semantics: In single-label mode, scores are relative probabilities that sum to 1 — a score of 0.85 means 85% of the probability mass relative to the other labels. In multi-label mode, each label’s score is an independent probability that it applies, so scores do not sum to 1 and should be compared against threshold individually.

Error responses

Authentication

Include your API key in every request using the x-api-key header.

Examples

Basic topic classification

Response:

Support ticket triage

Response:

Classifying a document

Pass a base64-encoded image or PDF in the document field. The OCR text is extracted automatically and classified against your labels. The raw OCR output is returned as ocr_text.
Response:

Multi-label: attaching several tags to one input

Set multi_label: true to score each label independently, so more than one can apply to the same input. Every label whose score meets threshold is returned in matched_labels. This avoids sending the same input once per tag.
Response: billing and churn_risk both cleared the threshold; scores are independent and do not sum to 1.

Batch: classifying many chunks against one profile

Send a chunks array to classify many inputs against the same labels in one request. Each chunk still gets its own calibrated scores, but the shared profile (labels + system_prompt) is billed once for the whole request instead of once per chunk. Results are returned in results, correlated by id.
Response: one entry per chunk, correlated by id. Top-level fields mirror the first result.
chunks and multi_label can be combined: every chunk is scored independently against every label.

Writing good rubrics

The rubric is the most important part of a classify request. It is phrased as a yes/no question the model uses to score each label. The model scores how strongly the text “answers yes” to the question. Rules of thumb:
  • Be specific. Vague rubrics produce low-confidence, noisy scores.
  • Frame as a direct yes/no question. “Does this text describe X?” works better than “X content”.
  • Avoid negations. “Is this text NOT about finance?” will confuse the model. Use a positive label instead.
  • Keep rubrics independent. Overlapping rubrics (e.g. “Is this medical?” and “Is this about health?”) will split probability mass unpredictably.

How it works

  1. For each label, the model scores the text against the label’s rubric.
  2. Raw scores are real-valued numbers (not probabilities).
  3. Softmax normalisation is applied across all label scores so they sum to 1.0.
  4. The label with the highest normalised score is returned as top_label.
The endpoint always returns a winner - even if the model is uncertain. If you need a confidence threshold, apply it yourself on the scores field.

Notes

  • Single-label mode supports up to 26 labels; multi-label mode is capped at 16. Batch requests are capped at 50 chunks. Larger sets cost more since each label (and each chunk) is a separate calibrated model call, run with bounded concurrency.
  • In single-label mode, scores are relative, not absolute. A top score of 0.4 in a 10-label request can still be the correct answer - it just means probability mass was spread across many labels.
  • Batch (chunks) exists to reduce cost: the shared profile is billed once per request instead of once per chunk. Calibration is identical to sending each chunk separately.
  • Multi-label and batch requests do not return a reasoning field.

Authorizations

x-api-key
string
header
required

Body

application/json
text
string
required

The text to classify.

labels
object[]
required

One or more label definitions. Must contain at least one item.

Response

Successful classification

top_label
string

Name of the highest-scoring label.

scores
object

Map of label name to probability score. All values sum to 1.0.

labels
object[]

Full label list with name, score, and rubric, in the same order as the request.