Skip to main content

Installation

pip install classer

Quick Start

import classer

# Uses CLASSER_API_KEY environment variable
result = classer.classify(
    text="I can't log in",
    labels=["billing", "technical", "sales"]
)

print(result.label)      # "technical"
print(result.confidence) # 0.94

Configuration

Environment variable

export CLASSER_API_KEY=your-api-key

Client instance

from classer import ClasserClient

client = ClasserClient(
    api_key="your-api-key",
    timeout=30.0  # optional, in seconds
)

Methods

classify()

Single-label classification — returns the one best-matching label.
result = client.classify(
    text="I can't log in to my account",
    labels=["billing", "technical", "sales"],
    descriptions={                          # optional
        "billing": "Payment or invoice issues",
        "technical": "Login, bugs, errors",
        "sales": "Pricing or plan questions",
    },
    priority="standard",                    # optional: "standard" (default, <1s) or "fast" (<200ms)
    cache=True,                             # optional: set False to bypass cache
)

result.label        # "technical"
result.confidence   # 0.94
result.tokens       # 142
result.latency_ms   # 87.0
result.cached       # False
You can also reference a saved classifier instead of inline labels:
result = client.classify(
    text="I can't log in",
    classifier="support-tickets",       # or "support-tickets@v2"
)

Image input

# URL
result = client.classify(
    image="https://example.com/photo.jpg",
    labels=["cat", "dog", "bird"],
)

# Base64
result = client.classify(
    image=base64_string,
    labels=["cat", "dog", "bird"],
)

# Text + image together
result = client.classify(
    text="What animal is this?",
    image="https://example.com/photo.jpg",
    labels=["cat", "dog", "bird"],
)

result.visual_tokens  # image tokens used

File input (PDF, DOCX)

# Also accepts a URL or local file path. Can be combined with text and image inputs.
result = client.classify(
    file=base64_string,
    labels=["invoice", "receipt", "contract"],
)

result.tokens         # text tokens
result.visual_tokens  # page image tokens

tag()

Multi-label tagging — returns all labels that exceed the confidence threshold.
result = client.tag(
    text="Breaking: Tech stocks surge amid AI boom",
    labels=["politics", "technology", "finance", "sports"],
    threshold=0.5,                          # optional (default: 0.5)
    descriptions={"technology": "Tech industry news"},  # optional
    priority="standard",                    # optional: "standard" (default, <1s) or "fast" (<200ms)
    cache=True,                             # optional: set False to bypass cache
)

for t in result.labels:
    print(f"{t.label}: {t.confidence}")
# technology: 0.92
# finance: 0.78

result.tokens       # 200
result.latency_ms   # 203.0
result.cached       # False
Tag also accepts image and file parameters, same as classify.

classify_batch()

Classify multiple texts in a single request. Returns results in the same order as input.
result = client.classify_batch(
    texts=["I can't log in", "What's the pricing?", "My invoice is wrong"],
    labels=["billing", "technical", "sales"],
)

for r in result.results:
    print(f"{r.label}: {r.confidence}")

result.total_tokens  # total across all texts
result.latency_ms    # total request time
Image and file inputs are shared across all texts:
result = client.classify_batch(
    texts=["What is this?", "Describe the document"],
    file="report.pdf",
    labels=["report", "invoice", "contract"],
)

tag_batch()

Tag multiple texts in a single request. Returns results in the same order.
result = client.tag_batch(
    texts=["Tech stocks surge", "Election results are in"],
    labels=["politics", "technology", "finance"],
    threshold=0.5,
)

for r in result.results:
    for t in r.labels:
        print(f"{t.label}: {t.confidence}")

Module-level functions

All methods are also available as top-level convenience functions that use a default client (reads CLASSER_API_KEY from the environment):
import classer

result = classer.classify(text="...", labels=["a", "b"])
result = classer.tag(text="...", labels=["a", "b"], threshold=0.5)
result = classer.classify(file="document.pdf", labels=["a", "b"])
result = classer.classify_batch(texts=["x", "y"], labels=["a", "b"])
result = classer.tag_batch(texts=["x", "y"], labels=["a", "b"])

Error Handling

from classer import ClasserClient, ClasserError

client = ClasserClient(api_key="your-key")

try:
    result = client.classify(
        text="Hello",
        labels=["greeting", "question"]
    )
except ClasserError as e:
    print(f"Error: {e.message}")
    print(f"Status: {e.status}")    # HTTP status code (e.g. 400, 401, 422, 429)
    print(f"Detail: {e.detail}")    # Error detail from the API
StatusMeaning
400Bad request — invalid parameters
401Unauthorized — missing or invalid API key
402Insufficient balance
422Validation error
429Rate limit exceeded

Types

ClassifyResponse

@dataclass
class ClassifyResponse:
    label: Optional[str] = None
    confidence: Optional[float] = None
    tokens: int = 0
    visual_tokens: int = 0
    latency_ms: float = 0.0
    cached: bool = False

TagResponse

@dataclass
class TagResponse:
    labels: list[TagLabel]  # empty list when nothing matches
    tokens: int = 0
    visual_tokens: int = 0
    latency_ms: float = 0.0
    cached: bool = False

TagLabel

@dataclass
class TagLabel:
    label: str
    confidence: float

BatchClassifyResponse

@dataclass
class BatchClassifyResponse:
    results: list[BatchClassifyResult]
    total_tokens: int = 0
    latency_ms: float = 0.0

BatchClassifyResult

@dataclass
class BatchClassifyResult:
    label: Optional[str] = None
    confidence: Optional[float] = None
    tokens: int = 0
    visual_tokens: int = 0
    error: Optional[str] = None
    cached: bool = False

BatchTagResponse

@dataclass
class BatchTagResponse:
    results: list[BatchTagResult]
    total_tokens: int = 0
    latency_ms: float = 0.0

BatchTagResult

@dataclass
class BatchTagResult:
    labels: list[TagLabel]
    tokens: int = 0
    visual_tokens: int = 0
    error: Optional[str] = None
    cached: bool = False

ClasserError

class ClasserError(Exception):
    message: str
    status: Optional[int]
    detail: Optional[str]

Requirements

  • Python 3.9+
  • httpx