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

export CLASSER_API_KEY=your-api-key

Client instance

from classer import ClasserClient

client = ClasserClient(
    api_key="your-api-key",
    base_url="https://api.classer.ai",  # optional
    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",
    },
    model="qwen",                           # optional (default: "qwen")
)

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"
)

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.3,                          # optional (default: 0.3)
    descriptions={"technology": "Tech industry news"},  # optional
    model="qwen",                           # optional
)

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

Module-level functions

Both 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)

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
    latency_ms: float = 0.0
    cached: bool = False

TagResponse

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

TagLabel

@dataclass
class TagLabel:
    label: str
    confidence: float

ClasserError

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

Requirements

  • Python 3.9+
  • httpx