Supp/Examples

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.

View on GitHub
git clone https://github.com/supp-support/supp-ts-starter
cd supp-ts-starter && npm install

Install

Terminalbash
npm install supp-ts
1

Classify a Message

$0.20

Classify a customer message into one of 315 intents with a confidence score.

classify.tstypescript
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.20
2

Classify with Priority

$0.23

Get intent classification and urgency scoring in a single call.

classify-priority.tstypescript
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"
3

Set Up Routing Rules

Map intents to actions — create GitHub issues, post to Slack, send template responses, or escalate to humans.

routing.tstypescript
// 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" },
});
4

Manage Conversations

List, view, and reply to support conversations.

conversations.tstypescript
// 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,
});
5

Embed the Widget

Add the Supp chat widget to any website with a single script tag.

HTMLhtml
<!-- 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>
Next.js (app/layout.tsx)tsx
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>
  );
}
6

Next.js API Route

Use the SDK in a server-side API route to classify messages from your frontend.

app/api/classify/route.tstypescript
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 }
    );
  }
}
7

Error Handling

The SDK throws typed errors you can catch and handle.

errors.tstypescript
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
  }
}
8

Analytics & Billing

Monitor your support performance and spending.

analytics.tstypescript
// 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

MethodCost
supp.classify()$0.20
supp.classifyWithPriority()$0.23
supp.priorityScore()$0.03
Batch classification50% off
Everything elseFree

New accounts get $5.00 in free credits (~25 classifications).