Text classification and clustering remain essential pipelines for turning unstructured business text into structured decisions. Traditional machine learning approaches require labeled datasets, feature engineering, and retraining cycles. Large language models collapse that overhead into a single API call, turning natural language instructions into production classifiers or semantic grouping engines without managing model weights or training infrastructure.
From Tokens to Requests: Why Pricing Structure Matters
Business documents rarely fit into a single sentence. A support ticket thread, a legal contract, or a PDF export of customer feedback can run to thousands of tokens. On token-based providers, every extra word in the prompt increases cost. When you run classification or clustering over high volumes of long-form text, that scaling becomes a budget constraint.
Oxlo.ai is a developer-first AI inference platform with request-based pricing. You pay one flat cost per API request regardless of prompt length. For long-context classification workloads, this can be 10-100x cheaper than token-based billing. You can add few-shot examples, detailed instructions, or entire document pages without watching the meter run. See https://oxlo.ai/pricing for current plan details.
Zero-Shot Classification with Structured Outputs
Zero-shot classification is the fastest way to deploy an LLM as a classifier. You describe the categories in natural language, optionally supply a JSON schema, and the model returns structured labels. This removes the need for historical training data and lets you change categories by editing a string rather than retraining a model.
Because Oxlo.ai is fully OpenAI SDK compatible, you can drop the base URL into existing code. The example below uses JSON mode to enforce a structured response.
import openai
import json
client = openai.OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key="YOUR_OXLO_API_KEY"
)
SYSTEM_PROMPT = (
"You are a ticket classifier. "
"Classify the input into exactly one category: Billing, Technical, Account, or Sales. "
"Respond with valid JSON in the format {\"category\": \"...\", \"confidence\": \"low|medium|high\"}."
)
def classify_ticket(text: str) -> dict:
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": f"Ticket text: {text}"}
],
response_format={"type": "json_object"},
temperature=0.1
)
return json.loads(response.choices[0].message.content)
ticket = "I was charged twice on March 12 and still see no refund."
print(classify_ticket(ticket))
Llama 3.3 70B works well for general-purpose English classification. If your pipeline handles multilingual inputs or agentic routing, Qwen 3 32B is a strong alternative on Oxlo.ai.
Few-Shot Classification for Niche Domains
Zero-shot accuracy drops when categories are subtle or domain-specific. Few-shot prompting recovers performance by showing the model concrete examples of each label. In a token-based system, those examples are billed as extra input tokens. On Oxlo.ai, they are simply part of the request, so the cost stays flat no matter how many examples you include.
FEW_SHOT_EXAMPLES = [
{"role": "user", "content": "Doc: 'Patient reports chest pain radiating to left arm.'\nLabel:"},
{"role": "assistant", "content": "{\"category\": \"Cardiology\", \"urgency\": \"high\"}"},
{"role": "user", "content": "Doc: 'Routine annual blood work, all markers within normal range.'\nLabel:"},
{"role": "assistant", "content": "{\"category\": \"General\", \"urgency\": \"low\"}"}
]
def classify_clinical_note(note: str) -> dict:
messages = [
{"role": "system", "content": "Classify clinical notes into Cardiology, General, or Neurology. Respond with JSON."}
] + FEW_SHOT_EXAMPLES + [
{"role": "user", "content": f"Doc: '{note}'\nLabel:"}
]
response = client.chat.completions.create(
model="deepseek-r1-671b",
messages=messages,
response_format={"type": "json_object"},
temperature=0.1
)
return json.loads(response.choices[0].message.content)
For complex reasoning over nuanced categories, DeepSeek R1 671B MoE on Oxlo.ai provides strong chain-of-thought performance before returning the final JSON label.
LLM-Powered Clustering Strategies
Clustering is traditionally an unsupervised embedding problem. LLMs improve it in two ways: by producing better semantic embeddings, and by directly assigning human-readable labels to discovered groups.
Strategy 1: Embedding-based clustering. Feed text through an embedding model, then apply a density or centroid algorithm. Oxlo.ai hosts BGE-Large and E5-Large embedding models through a standard OpenAI-compatible embeddings endpoint.
import numpy as np
from sklearn.cluster import HDBSCAN
def cluster_texts(texts: list[str]) -> list[int]:
res = client.embeddings.create(
model="bge-large",
input=texts
)
embeddings = np.array([d.embedding for d in res.data])
clusterer = HDBSCAN(min_cluster_size=3, metric="euclidean")
return clusterer.fit_predict(embeddings).tolist()
documents = [
"Refund not processed after cancellation.",
"Server returns 502 on checkout API.",
"Login fails after password reset.",
"Unexpected charge on credit card."
]
labels = cluster_texts(documents)
Strategy 2: Direct LLM assignment. When your corpus fits into context, you can ask the model to read every item, propose clusters, and assign items to them. This yields human-readable cluster names in one step. With DeepSeek V4 Flash offering a 1M context window on Oxlo.ai, you can pass hundreds of summaries or survey responses in a single request. Because Oxlo.ai bills per request, one large batch call costs the same as one short query.
Handling Long Documents in Classification Pipelines
Enterprise text often arrives as PDFs, email threads, or transcribed meetings. Chunking introduces boundary errors, so passing the full document is preferable when the model supports it. Oxlo.ai offers several long-context options, including Kimi K2.6 with 131K context and DeepSeek V4 Flash with 1M context. Combined with flat per-request pricing, this means classifying a 50-page contract costs the same unit as classifying a tweet. No token arithmetic is required.
Putting It Together: A Unified Pipeline
The following pattern ties embedding-based clustering with LLM labeling. It runs entirely against Oxlo.ai endpoints and requires no local GPU.
import json
from collections import defaultdict
def classify_and_label(texts: list[str]) -> dict:
# Step 1: embed and cluster
labels = cluster_texts(texts)
# Step 2: build clusters
clusters = defaultdict(list)
for text, label in zip(texts, labels):
if label != -1:
clusters[label].append(text)
# Step 3: ask LLM to name each cluster
results = {}
for cid, docs in clusters.items():
prompt = (
f"You are given {len(docs)} documents from a single cluster. "
"Propose a short category name and a one-line description. "
"Respond with JSON: {\"name\": \"...\", \"description\": \"...\"}"
)
response = client.chat.completions.create(
model="qwen-3-32b",
messages=[
{"role": "system", "content": prompt},
{"role": "user", "content": "\n".join(f"- {d}" for d in docs)}
],
response_format={"type": "json_object"},
temperature=0.2
)
results[cid] = {
"documents": docs,
"label": json.loads(response.choices[0].message.content)
}
return results
This pipeline uses Qwen 3 32B for multilingual labeling, but you can substitute Llama 3.3 70B or Kimi K2.6 depending on language and context requirements.
Selecting the Right Model on Oxlo.ai
Oxlo.ai hosts 45+ models across 7 categories. For text classification and clustering, these are the most relevant:
- General-purpose classification: Llama 3.3 70B
- Multilingual reasoning or agentic routing: Qwen 3 32B
- Deep reasoning over complex categories: DeepSeek R1 671B MoE
- Efficient long-context clustering: DeepSeek V4 Flash (1M context)
- Advanced reasoning with vision support: Kimi K2.6 (131K context)
- Embeddings: BGE-Large, E5-Large
All models are accessible through the same base URL with no cold starts, so you can A/B test classifiers by changing a single string.
Getting Started
You can start building classification and clustering pipelines on Oxlo.ai with the Free tier, which includes 60 requests per day and a 7-day full-access trial. Upgrade to Pro or Premium for higher daily volumes, or contact the team for Enterprise dedicated GPUs and custom migration pricing.
Point your OpenAI SDK to https://api.oxlo.ai/v1, pick a model from the list above, and run your first classifier. For plan details, visit https://oxlo.ai/pricing.
Top comments (0)