Send SMS from Next.js with the SendiMessage API
Next.js keeps SendiMessage credentials safe by design when you send from a route handler or server action: the code runs on the server, the key pair lives in process.env, and your React components just call your own endpoint.
The example is an App Router route handler using the official sendimessage npm SDK. The same client works inside a server action if you prefer form-driven flows.
What this integration enables
Architecture
- Your application eventAn order ships, a booking nears, a ticket updates
- Next.js server codeBuilds the request with credentials from the environment
- SendiMessage APIPOST /send-message returns the queued message
- Managed messaging lineSMS, or iMessage on supported lines and destinations
- Webhook eventsDelivery status and incoming replies post back to your endpoint
Example request
// app/api/notify/route.ts — runs on the server; the key never reaches the browser.// npm install sendimessageimport { NextResponse } from "next/server";import SendImessage, { SendImessageError } from "sendimessage";const client = new SendImessage({apiKey: process.env.SENDIMESSAGE_KEY!,apiSecret: process.env.SENDIMESSAGE_SECRET!,});export async function POST(request: Request) {const { to, content } = await request.json();try {const msg = await client.sendMessage({ number: to, content });return NextResponse.json({ handle: msg.message_handle, status: msg.status }); // "QUEUED"} catch (err) {const status = err instanceof SendImessageError ? err.status : 502;return NextResponse.json({ error: "send failed" }, { status });}}
Authenticate and rate-limit this route — it can send real messages.
Delivery events and incoming replies
Point a Next.js route at your webhook URL to receive delivery status and incoming replies. Verify the signature header before processing.
// "outbound" event → your nextjs endpoint// Verify the SendiMessage-Signature header (t={timestamp},v1=HMAC-SHA256 of// "{timestamp}.{raw body}", keyed with your webhook secret), then use// GET /v2/messages/{message_handle} for authoritative state and match it to// your contact_id in nextjs.
Limitations and honest notes
- iMessage delivery is available on supported messaging lines and destinations. Recipients without iMessage receive SMS when fallback is configured — never assume universal iMessage availability.
- Messages are accepted asynchronously — the API returns status QUEUED and final status arrives via webhook or the message endpoints.
- Official SDKs are published for JavaScript/TypeScript (npm: sendimessage), Python (PyPI: sendimessage), PHP (Composer: sendimessage/sdk), and Go (github.com/sendimessage/sendimessage-go). Every SDK is dependency-free and covers the full public API surface.
Security considerations
- Keep the API key pair in server configuration or environment variables, never in the repository.
- Verify webhook signatures before trusting delivery or reply events.
Frequently asked questions
Is there an official Next.js package for SendiMessage?
Can Next.js receive message replies?
Related integrations
Ready to connect Next.js?
Request a messaging line and a SendiMessage integration specialist will review your Next.js workflow and guide the setup.