Developers
How to send an SMS from Node.js
You don't need an SDK to send a text from Node. Bremlio is a plain REST endpoint, so a built-in fetch is all it takes. Here's a real, working example you can drop into any Node 18+ project, plus the error handling most first integrations skip.
The minimum viable send
// Node 18+ has fetch built in — no dependencies needed const res = await fetch("https://api.bremlio.com/v1/messages", { method: "POST", headers: { "X-Api-Key": process.env.BREMLIO_API_KEY, "Content-Type": "application/json" }, body: JSON.stringify({ to: "+447700900123", message: "Your order is ready to collect." }) }); const data = await res.json(); console.log(data.message_id, data.status);
Handle the failure cases
A send can fail for reasons worth handling distinctly: an invalid number (400), no credits (402), or a provider error (502). Check res.ok and read the error rather than assuming success.
if (!res.ok) { // data.error explains what went wrong if (res.status === 402) throw new Error("Out of credits — top up."); if (res.status === 400) throw new Error("Bad number: " + data.error); throw new Error("Send failed: " + data.error); }
Before production
- Keep the key server-side. Your API key belongs in an environment variable, never in front-end code.
- Use +44 format. Bremlio normalises
07…to+44, but sending E.164 is cleanest. - Test without spending. Add
"test": trueto skip the carrier and the credit while you wire things up. - Watch delivery, not just acceptance. Poll
/v1/messages/historyor subscribe a webhook for delivery-status events.