Developers

How to send an SMS from Node.js

September 2026 · 5 min read

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

Send your first message

Grab an API key and 25 free credits — no card required.

Create free account →