API Documentation
Classify text, images, and PDFs with a single API call. Get accurate labels and confidence scores for your content.
Quickstart
Get started with OpenClassifier in minutes. All you need is an API key and a few lines of code.
Base URL
https://api.openclassifier.aiAuthentication
Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYRate Limits
| Plan | Requests/min | Requests/day |
|---|---|---|
| Free | 20 | 1,000 |
| Pro | 100 | 50,000 |
| Enterprise | Custom | Unlimited |
Text Classification
Classify text content into predefined labels. Supports both single-label and multi-label classification.
/classify/textRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
content | string | Yes | The text to classify |
labels | string[] | object | Yes | Array of labels or object with category keys |
Single-Label Example
curl -X POST https://api.openclassifier.ai/classify/text \
-H "Authorization: Bearer $OPENCLASSIFIER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"content": "The package arrived damaged and I want a refund",
"labels": ["shipping", "returns", "billing", "general"]
}'Response
{
"success": true,
"results": {
"label": "returns",
"confidence": 0.94
}
}Multi-Label Example
Classify text across multiple categories simultaneously by passing an object with category keys:
curl -X POST https://api.openclassifier.ai/classify/text \
-H "Authorization: Bearer $OPENCLASSIFIER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"content": "Your service is terrible, I have been waiting for weeks!",
"labels": {
"intent": ["complaint", "inquiry", "feedback", "request"],
"sentiment": ["positive", "neutral", "negative"],
"urgency": ["low", "medium", "high"]
}
}'Response
{
"success": true,
"results": {
"intent": { "label": "complaint", "confidence": 0.97 },
"sentiment": { "label": "negative", "confidence": 0.95 },
"urgency": { "label": "high", "confidence": 0.88 }
}
}Image Classification
Classify images into predefined labels. Supports batch classification of multiple images in a single request.
/classify/imageRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
inputs | array | Yes | Array of image objects with url or base64 |
labels | string[] | Yes | Array of classification labels |
Example Request
curl -X POST https://api.openclassifier.ai/classify/image \
-H "Authorization: Bearer $OPENCLASSIFIER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{ "url": "https://example.com/document1.png" },
{ "url": "https://example.com/document2.png" }
],
"labels": ["invoice", "receipt", "contract", "letter"]
}'Response
{
"success": true,
"results": [
{
"input": "https://example.com/document1.png",
"label": "invoice",
"confidence": 0.92
},
{
"input": "https://example.com/document2.png",
"label": "receipt",
"confidence": 0.89
}
]
}Supported Image Formats
- JPEG / JPG
- PNG
- GIF (first frame only)
- WebP
Maximum image size: 20MB per image
PDF Classification
Classify PDF documents by analyzing each page. Pages are converted to high-resolution images and classified in parallel for fast processing.
/classify/pdfRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
input | object | Yes | Object with url or base64 of the PDF |
labels | string[] | Yes | Array of classification labels |
mode | string | No | per_page (default) or document |
Classification Modes
- per_page: Returns classification for each page individually
- document: Also returns an aggregated classification for the entire document based on page votes
Example Request
curl -X POST https://api.openclassifier.ai/classify/pdf \
-H "Authorization: Bearer $OPENCLASSIFIER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": { "url": "https://example.com/document.pdf" },
"labels": ["invoice", "contract", "report", "letter"],
"mode": "document"
}'Response
{
"success": true,
"totalPages": 3,
"results": [
{ "page": 1, "label": "invoice", "confidence": 0.94 },
{ "page": 2, "label": "invoice", "confidence": 0.91 },
{ "page": 3, "label": "invoice", "confidence": 0.89 }
],
"documentLabel": {
"label": "invoice",
"confidence": 0.91
}
}How It Works
- PDF is fetched from URL or decoded from base64
- Each page is converted to a high-resolution image (2x scale)
- All pages are classified in parallel for speed
- Results are returned per-page with optional document-level aggregation
Maximum PDF size: 50MB, Maximum pages: 100
Code Examples
Quick examples to get you started in your preferred language.
Python
import requests
# Single-label classification
response = requests.post(
"https://api.openclassifier.ai/classify/text",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"content": "I need to change my delivery address",
"labels": ["shipping", "returns", "billing", "account"]
}
)
result = response.json()
print(result["results"]["label"], result["results"]["confidence"])
# PDF classification
response = requests.post(
"https://api.openclassifier.ai/classify/pdf",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"input": {"url": "https://example.com/document.pdf"},
"labels": ["invoice", "contract", "report"],
"mode": "document"
}
)
result = response.json()
print(f"Document type: {result['documentLabel']['label']}")TypeScript / JavaScript
// Classify a PDF document
const response = await fetch(
"https://api.openclassifier.ai/classify/pdf",
{
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
input: { url: "https://example.com/document.pdf" },
labels: ["invoice", "contract", "report"],
mode: "document"
})
}
);
const data = await response.json();
console.log("Document type:", data.documentLabel.label);
console.log("Pages classified:", data.totalPages);Error Handling
All errors return a consistent JSON structure with an error code and message.
Error Response Format
{
"success": false,
"error": {
"code": "INVALID_REQUEST",
"message": "Content is required"
}
}Error Codes
| Code | HTTP Status | Description |
|---|---|---|
INVALID_REQUEST | 400 | Missing or invalid parameters |
INVALID_JSON | 400 | Malformed JSON in request body |
INVALID_PDF | 400 | PDF could not be processed |
UNAUTHORIZED | 401 | Invalid or missing API key |
RATE_LIMITED | 429 | Too many requests |
CLASSIFICATION_FAILED | 500 | Classification could not be completed |
INTERNAL_ERROR | 500 | Unexpected server error |