Skip to main content
Triage incoming email by tagging it. On each inbound message, an LLM picks a category and the agent assigns the matching label. The pattern is webhook → classify → assign label.

1. Create your labels once

curl -X POST https://api.sentvia.ai/v1/labels \
  -H "Authorization: Bearer sv_live_…" -H "Content-Type: application/json" \
  -d '{ "name": "Sales", "color": "#10b981" }'
# repeat for Support, Billing, Spam … keep the returned ids

2. Classify and assign on inbound

const KEY = process.env.SENTVIA_KEY!;
const API = "https://api.sentvia.ai/v1";
const LABELS = { Sales: "lbl_…", Support: "lbl_…", Billing: "lbl_…" };

export async function onInbound(message) {
  // classify with your LLM -> one of the label names
  const category = await classify(message.subject, message.body_text); // "Sales" | "Support" | ...
  const labelId = LABELS[category];
  if (!labelId) return;

  await fetch(`${API}/labels/${labelId}/assign`, {
    method: "POST",
    headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({ message_id: message.id }),
  });
}
The message’s labels array now includes the assigned label — visible on GET /messages/{id}, in search results, and in the dashboard. Remove a label with POST /labels/{id}/unassign.
Drive the webhook/inbound trigger exactly like the auto-reply agent — verify the signature, then branch on message.received.