Examples
Code examples showing how to integrate Supp into your project. Each example uses the supp-ts SDK.
Starter Template
Clone the full working Next.js project with interactive demos for every SDK feature.
git clone https://github.com/supp-support/supp-ts-starter
cd supp-ts-starter && npm installInstall
npm install supp-tsClassify a Message
$0.20Classify a customer message into one of 315 intents with a confidence score.
import { Supp } from "supp-ts";
const supp = new Supp(process.env.SUPP_SECRET_KEY);
const result = await supp.classify("I need a refund for my last order");
console.log(result.intent); // "refund_initiation"
console.log(result.confidence); // 0.94
console.log(result.actionType); // "template"
console.log(result.cost); // 0.20Classify with Priority
$0.23Get intent classification and urgency scoring in a single call.
const result = await supp.classifyWithPriority(
"Our entire production database is down and customers can't access anything"
);
console.log(result.intent); // "service_outage"
console.log(result.priority); // "critical"
// Or score priority separately ($0.03):
const { priority } = await supp.priorityScore("When do you open?");
// priority → "low"Set Up Routing Rules
Map intents to actions — create GitHub issues, post to Slack, send template responses, or escalate to humans.
// Route bug reports to GitHub
await supp.routing.create({
intent: "bug_report",
actionType: "mcp_action",
actionConfig: {
integration_provider: "github",
github_owner: "acme",
github_repo: "app",
github_labels: ["bug"],
},
});
// Auto-respond to password reset requests
await supp.routing.create({
intent: "password_reset",
actionType: "template",
actionConfig: {
response_template:
"To reset your password, visit {{app_url}}/reset.",
},
});
// Bulk route all billing intents to Slack
await supp.routing.bulkUpdate({
intents: ["refund_request", "invoice_dispute", "payment_failed"],
actionType: "mcp_action",
actionConfig: { integration_provider: "slack", channel: "#billing" },
});Manage Conversations
List, view, and reply to support conversations.
// List escalated tickets
const tickets = await supp.conversations.list({
status: "escalated",
priority: "high",
limit: 10,
});
// Get full conversation with messages
const convo = await supp.conversations.get("conv_abc123");
for (const msg of convo.messages) {
console.log(`[${msg.senderType}] ${msg.body}`);
}
// Reply and resolve
await supp.conversations.reply("conv_abc123", {
message: "This has been fixed in v2.1.4.",
resolve: true,
});Embed the Widget
Add the Supp chat widget to any website with a single script tag.
<!-- Add before </body> -->
<script
src="https://supp.support/widget.js"
data-api-key="pk_live_YOUR_KEY"
data-position="bottom-right"
data-theme="light"
defer
></script>import Script from "next/script";
export default function Layout({ children }) {
return (
<html>
<body>
{children}
<Script
src="https://supp.support/widget.js"
data-api-key={process.env.NEXT_PUBLIC_SUPP_KEY}
strategy="lazyOnload"
/>
</body>
</html>
);
}Next.js API Route
Use the SDK in a server-side API route to classify messages from your frontend.
import { NextRequest, NextResponse } from "next/server";
import { Supp, SuppError } from "supp-ts";
const supp = new Supp(process.env.SUPP_SECRET_KEY!);
export async function POST(request: NextRequest) {
try {
const { message } = await request.json();
const result = await supp.classify(message);
return NextResponse.json({
intent: result.intent,
confidence: result.confidence,
});
} catch (error) {
if (error instanceof SuppError) {
return NextResponse.json(
{ error: error.message },
{ status: error.status }
);
}
return NextResponse.json(
{ error: "Classification failed" },
{ status: 500 }
);
}
}Error Handling
The SDK throws typed errors you can catch and handle.
import {
Supp,
SuppError,
AuthenticationError,
InsufficientBalanceError,
RateLimitError,
} from "supp-ts";
try {
await supp.classify("...");
} catch (error) {
if (error instanceof InsufficientBalanceError) {
// 402 — add credits at supp.support/dashboard
} else if (error instanceof RateLimitError) {
// 429 — spend cap exceeded or too many requests
} else if (error instanceof AuthenticationError) {
// 401 — check your API key
} else if (error instanceof SuppError) {
console.log(error.status); // HTTP status code
console.log(error.code); // Error code string
}
}Analytics & Billing
Monitor your support performance and spending.
// Get summary stats
const stats = await supp.analytics.summary({ period: "30d" });
console.log(stats.totalConversations); // 1420
console.log(stats.resolved); // 1180
console.log(stats.avgConfidence); // 0.82
// Check balance
const { balance } = await supp.billing.balance();
console.log(balance); // 47.50
// Export as CSV
const { downloadUrl } = await supp.analytics.export({
period: "month",
format: "csv",
});Pricing
| Method | Cost |
|---|---|
| supp.classify() | $0.20 |
| supp.classifyWithPriority() | $0.23 |
| supp.priorityScore() | $0.03 |
| Batch classification | 50% off |
| Everything else | Free |
New accounts get $5.00 in free credits (~25 classifications).