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

text
string
The text to classify. Either text or document must be provided. If both are given, the OCR text is appended after text.
document
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.
document_mime_type
string
MIME type of the document (e.g. "image/jpeg", "application/pdf"). Required when document is provided.
labels
array
required
One or more label definitions. Must contain at least one item - sending an empty array returns 422.

Response

top_label
string
Name of the highest-scoring label.
scores
object
Map of label name → probability score. All values sum to 1.0.
labels
array
Full label list with name, score, and rubric, in the same order as the request.
ocr_text
string | null
The raw text extracted from the document via OCR. null if no document was provided.
Score semantics: Scores are relative probabilities, not absolute confidence values. A score of 0.85 means the model assigned 85% of its probability mass to that label relative to the others. If you need a confidence threshold (e.g. only act if the top score exceeds 0.7), apply it yourself on the scores field.

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:

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

  • There is no hard limit on the number of labels, but performance degrades with very large sets (>20) since each label requires a separate model call.
  • 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.

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.