Classification is one of the cheapest and most reliable AI tasks, and it saves hours of inbox triage.
The prompt
LABELS = ["support", "sales", "billing", "partnership", "spam", "other"]
def classify(subject, body):
r = client.chat.completions.create(
model="claude-haiku-5-5",
temperature=0,
response_format={"type": "json_object"},
messages=[{"role": "user", "content": f"""Classify this email.
Return JSON: {{"label": one of {LABELS}, "urgency": 1-5, "summary": "one sentence", "language": "ISO code"}}
Subject: {subject}
Body: {body[:4000]}"""}],
)
return json.loads(r.choices[0].message.content)If your chosen model doesn't support response_format, remove it; the prompt and a json.loads with error handling are usually enough (reliable JSON guide).
Route it
c = classify(msg.subject, msg.text)
if c["label"] == "spam":
archive(msg)
elif c["urgency"] >= 4:
notify_oncall(msg, c["summary"])
else:
add_label(msg, c["label"])Draft replies (optional)
For support emails, generate a draft with a stronger model and your help articles, and save it as a draft for a human to approve, never auto-send.
Cost
Classification needs only a short output. With a small model and the body capped at a few thousand characters, thousands of emails cost very little. Check Usage Logs after the first day to see your real per-email cost.
Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.