This endpoint classifies documents into predefined business categories using our Gemma 3 27B model. Provide a Base64-encoded document and optionally include custom labels to merge with the defaults.
This endpoint does not use the OpenAI SDK. Call it directly with HTTPS.

Endpoint

  • Method: POST
  • Path: /classify/document

Request

{
  "document": "<base64-encoded document>",
  "additional_labels": ["string"]
}
  • document: Required. Base64-encoded contents of the file. Prefer sending the original binary Base64 rather than JSON-stringifying large payloads.
  • additional_labels: Optional. Array of extra labels to merge with the default set.

Supported document types

  • PDFs (application/pdf)
  • Images (PNG, JPEG, WEBP, TIFF)
  • Office documents (DOCX)
If the document cannot be parsed or converted to an image, the endpoint returns a 400 error.

Process flow

  1. Receive document upload as Base64
  2. Convert document pages to one or more images
  3. Send images and combined labels (default + additional) to Gemma 3 27B
  4. Parse model output and return matched labels

Response

{
  "labels": ["string"]
}

Default labels

The following labels are included by default. You can extend or narrow this set using additional_labels.
Invoice
Purchase Order
Receipt
Expense Report
Budget Report
Financial Statement
Balance Sheet
Income Statement
Cash Flow Statement
Tax Return
W2 Form
1099 Form
Pay Stub
Credit Note
Debit Note
Contract
Service Level Agreement(SLA)
Non - Disclosure Agreement(NDA)
Terms of Service
Privacy Policy
Memorandum of Understanding(MOU)
Letter of Intent(LOI)
Power of Attorney
Legal Notice
Compliance Report
Audit Report
Risk Assessment
Statement of Work(SOW)
Request for Proposal(RFP)
Request for Information(RFI)
Request for Quotation(RFQ)
Business Plan
Strategic Plan
Operational Procedure
Standard Operating Procedure(SOP)
Work Order
Change Request
Incident Report
Product Requirements Document(PRD)
Technical Specification
Architecture Document
API Documentation
User Manual
Installation Guide
Release Notes
Bug Report
Test Plan
Code Review
Database Schema
Network Diagram
Mermaid Diagram
UML Diagram
Project Charter
Project Plan
Gantt Chart
Status Report
Meeting Minutes
Action Items List
Risk Register
Stakeholder Analysis
Lessons Learned
Post - Mortem Report
Resume / CV
Job Description
Offer Letter
Employment Contract
Performance Review
Training Material
Employee Handbook
Organizational Chart
Leave Request
Timesheet
Benefits Summary
Marketing Plan
Campaign Brief
Brand Guidelines
Press Release
Case Study
White Paper
Product Brochure
Sales Proposal
Customer Testimonial
Market Research Report
Competitor Analysis
Sales Forecast
Email Correspondence
Memo
Newsletter
Presentation
Meeting Agenda
Conference Notes
Webinar Materials
FAQ Document
Quality Assurance Report
ISO Certification
Certificate of Compliance
Inspection Report
Warranty Document
Service Agreement

Examples

Set your API key first:
export INFERENCE_API_KEY=<your-api-key>
Prepare a Base64 file (macOS/Linux):
base64 -i ./sample.pdf -o ./sample.b64

cURL

curl -sS https://api.inference.net/classify/document \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<'JSON'
{
  "document": "$(cat sample.b64)",
  "additional_labels": ["Invoice", "Contract"]
}
JSON

TypeScript

import fs from "node:fs";

const API_URL = "https://api.inference.net/classify/document";
const API_KEY = process.env.INFERENCE_API_KEY ?? "";

async function classifyDocument(filePath: string, additionalLabels: string[] = []) {
  const fileBase64 = fs.readFileSync(filePath, { encoding: "base64" });
  const resp = await fetch(API_URL, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ document: fileBase64, additional_labels: additionalLabels }),
  });

  if (!resp.ok) {
    const text = await resp.text();
    throw new Error(`Request failed (${resp.status}): ${text}`);
  }

  const data = await resp.json() as { labels: string[] };
  return data.labels;
}

(async () => {
  const labels = await classifyDocument("./sample.pdf", ["Invoice", "Contract"]);
  console.log(labels);
})();

Python

import os
import base64
import json
import urllib.request

API_URL = "https://api.inference.net/classify/document"
API_KEY = os.getenv("INFERENCE_API_KEY", "")

def classify_document(file_path: str, additional_labels = None):
    with open(file_path, "rb") as f:
        file_b64 = base64.b64encode(f.read()).decode("utf-8")

    body = json.dumps({
        "document": file_b64,
        "additional_labels": additional_labels or []
    }).encode("utf-8")

    req = urllib.request.Request(
        API_URL,
        data=body,
        headers={
            "Authorization": f"Bearer {API_KEY}",
            "Content-Type": "application/json",
        },
        method="POST",
    )

    try:
        with urllib.request.urlopen(req) as r:
            return json.loads(r.read().decode("utf-8"))
    except urllib.error.HTTPError as e:
        raise RuntimeError(f"Request failed ({e.code}): {e.read().decode('utf-8')}")


if __name__ == "__main__":
    result = classify_document("./sample.pdf", ["Invoice", "Contract"])
    print(result["labels"])  # ["Invoice"]

Errors

  • 400 Bad Request: Missing or invalid document payload, unsupported type, or corrupted Base64
  • 401 Unauthorized: Invalid or missing API key
  • 413 Payload Too Large: File exceeds maximum size
  • 429 Too Many Requests: Rate limit exceeded
  • 5xx: Transient server issues

Notes & best practices

  • Prefer Base64 over URLs for simpler, predictable ingestion
  • Keep label lists concise and mutually exclusive when possible
  • Merge defaults + additional_labels to extend coverage without losing core categories