SuperSend TX with Next.js

Use SuperSend TX from a server context in Next.js: Route Handlers, Server Actions, background jobs, or any trusted backend code. Do not expose your stx_… API key in the browser.

1. Install the SDK

npm install supersendtx

2. Set your API key

export SUPERSENDTX_API_KEY=stx_your_key_here

In Vercel or Kubernetes, store the same value as an environment variable instead of committing it to the repo.

3. Send from an API route

Create app/api/send-welcome/route.ts:

import { NextResponse } from 'next/server'
import { SuperSendTX } from 'supersendtx'

const tx = new SuperSendTX(process.env.SUPERSENDTX_API_KEY!)

export async function POST() {
  const result = await tx.emails.send({
    from: 'onboarding@yourdomain.com',
    to: 'user@example.com',
    subject: 'Welcome to your app',
    html: '<p>Your account is ready.</p>',
  })

  return NextResponse.json(result)
}