To send an SMS from Deno or Bun, POST JSON to your provider's REST endpoint with the built-in fetch, pass the API key in a header, and check the status before you assume it worked. Neither runtime needs an SDK, a package install or a polyfill, and the same function runs on both with one line changed.

We make Ready, so the example uses the Ready REST API and only the request shape we document. If you're on classic Node, our Node.js guide is the sibling to this one.

The only difference: reading the key

Both runtimes have web-standard fetch, Request, Response, AbortSignal.timeout and crypto.randomUUID. Where they differ is environment variables:

DenoBun
Read a variableDeno.env.get("READY_API_KEY")Bun.env.READY_API_KEY
Load from .envThe env-file flag on deno runAutomatic
PermissionsNetwork and env permission flagsNone

Deno's permission model is a real advantage for a script that holds a credential. Run it with network access limited to the API host and env access limited to the one variable, and a compromised dependency can't read anything else. Write a small helper that hides the difference:

const apiKey = (globalThis as any).Deno
  ? Deno.env.get("READY_API_KEY")
  : Bun.env.READY_API_KEY;

A typed send helper

type SendResult = { status: number; body: unknown };

export async function sendSms(
  to: string,
  body: string,
  idempotencyKey: string = crypto.randomUUID(),
): Promise<SendResult> {
  const res = await fetch("https://api.tryready.com/v1/messages", {
    method: "POST",
    headers: {
      "X-API-Key": apiKey!,
      "Content-Type": "application/json",
      "Idempotency-Key": idempotencyKey,
    },
    body: JSON.stringify({ to, body, consent_attested: true }),
    signal: AbortSignal.timeout(15000),
  });
  const text = await res.text();
  let parsed: unknown = text;
  try { parsed = JSON.parse(text); } catch { /* keep raw text */ }
  return { status: res.status, body: parsed };
}

const out = await sendSms("+12125550199", "Your order #1042 has shipped.");
console.log(out.status, out.body);

Top-level await works in both runtimes. Reading the body as text first and then trying to parse it means a gateway error page doesn't throw a JSON error and hide the real status. For the response fields, use the messages API reference instead of guessing.

Retries that stay safe

Generate the idempotency key once per logical message and reuse it on each attempt:

export async function sendWithRetry(to: string, body: string) {
  const key = crypto.randomUUID();
  let delay = 500;
  for (let attempt = 1; attempt <= 4; attempt++) {
    try {
      const r = await sendSms(to, body, key);
      const inProgress = r.status === 409 && (await r.clone().json().catch(() => ({}))).code === "idempotency_in_progress";
      if (r.status !== 429 && r.status < 500 && !inProgress) return r;
    } catch { /* network error, retry */ }
    await new Promise((r) => setTimeout(r, delay));
    delay *= 2;
  }
  throw new Error("send failed after retries");
}

A repeated key means a repeated request isn't sent twice. That's the whole point of idempotency for SMS, and the retries guide goes through which statuses are worth retrying. A 409 idempotency_in_progress means the first attempt is still running, so the loop retries it with the same key. A 503 was not sent, but the same key replays that stored error, so resend it under a new key; after a 504, or a code ending in OUTCOME_UNKNOWN, check GET /v1/messages first.

A tiny webhook server

Replies need somewhere to land. In Bun:

Bun.serve({
  port: 3000,
  async fetch(req) {
    if (new URL(req.url).pathname !== "/sms-webhook") return new Response("not found", { status: 404 });
    const raw = await req.text(); // raw bytes first, for signature checks
    // verify the signature per the docs, then enqueue `raw`
    return new Response("ok");
  },
});

The Deno version swaps Bun.serve for Deno.serve, with the same handler body. Read the raw text before parsing, verify the signature, acknowledge fast and process later. Event names and signature headers live in the docs quickstart, and the inbound webhook guide explains the pattern.

Cost and registration

A segment on the Standard rate is $0.0075 plus a $0.0045 carrier fee, passed through at cost, excluding optional screening. An account can send up to 500 texts a month before it registers for 10DLC, and most approvals take 2 to 7 days. See pricing.

FAQ

Do I need an SMS SDK on Deno or Bun?

No. The API is plain HTTPS and JSON. A helper like sendSms above is all most apps need, and it has no dependencies to audit.

Does Bun's fetch behave differently from Node's?

For this use they're the same. Both implement the standard fetch, so a request written for one runs on the other. Differences show up in less common features like proxies and streaming.

How do I test without sending real texts?

Ready has one: a test key (Settings, Developers, Environment: Test) simulates every send with no card, number or charge. Our sandbox and test numbers guide covers the options.

The short version

Built-in fetch, one runtime-specific line for the key, a stable idempotency key and a retry loop. Same request, any runtime.