You don't send SMS from a React Native app. You send it from your backend, and the app asks your backend to do it. The Ready API key lives in a server environment variable, the app proves who the user is with its own session token, and your server decides whether a text goes out at all.
We make Ready, so the server code below uses only the request shape we document. Our mobile app backend guide covers the general pattern; this post is the React Native version, with an OTP flow and a notification flow.
Why the key can't be in the app
Anything in a React Native bundle can be pulled out of it. Environment variables inlined at build time, a value in app.json, a key fetched at launch and kept in memory: a determined person can read all of them. A leaked key lets someone send texts on your account, at your cost, to anyone. So the key never leaves the server.
The same rule gives you control. If the app could call the texting API directly, a user could change the recipient or the message. If it calls your backend, your backend picks the recipient from your own records and writes the message itself.
The shape of the system
| Piece | Holds | Does |
|---|---|---|
| React Native app | The user's session token | Asks your backend to start a verification or trigger a notification |
| Your backend | READY_API_KEY, session checks, rate limits | Authenticates the caller, builds the text, calls Ready |
| Ready | The sending side | Sends the text and applies opt-out and quiet-hours rules |
Device to backend authentication is whatever you already use for the app's other calls: a short-lived access token in the Authorization header, stored in the platform keychain through something like expo-secure-store or react-native-keychain. Don't invent a second scheme just for texting.
The app side
The app sends the token and almost nothing else.
const API = "https://api.example.com";
export async function requestCode(accessToken: string, phone: string) {
const res = await fetch(`${API}/auth/sms/start`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({ phone }),
});
if (res.status === 429) throw new Error("Too many attempts, try again later");
if (!res.ok) throw new Error("Could not send the code");
} api.example.com stands in for your backend. Notice what's missing: no Ready URL, no key, no message text.
The backend: an OTP endpoint
This Express route generates the code on the server, stores only a hash, and sends the text. The app never sees the code until it arrives by SMS.
import crypto from "node:crypto";
import express from "express";
const router = express.Router();
router.post("/auth/sms/start", requireSession, rateLimit, async (req, res) => {
const phone = normalizeE164(req.body.phone);
if (!phone) return res.status(400).json({ error: "bad_phone" });
const code = String(crypto.randomInt(0, 1_000_000)).padStart(6, "0");
const sendId = crypto.randomUUID();
await saveChallenge({
userId: req.user.id,
phone,
codeHash: sha256(code),
expiresAt: Date.now() + 10 * 60 * 1000,
sendId,
});
const result = await sendText(phone, `Your Acme code is ${code}`, sendId);
if (!result.ok) return res.status(502).json({ error: "send_failed" });
res.sendStatus(204);
});
async function sendText(to, body, key) {
const res = await fetch("https://api.tryready.com/v1/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.READY_API_KEY,
"Idempotency-Key": key,
},
body: JSON.stringify({ to, body, consent_attested: true }),
signal: AbortSignal.timeout(15000),
});
return { ok: res.ok, status: res.status };
}
export default router; requireSession, rateLimit, normalizeE164, saveChallenge and sha256 are yours. "Acme" is a made-up product name. Set consent_attested to true only when the person agreed to receive texts, for instance through the terms they accepted when they entered their number to verify.
A few details carry weight here. crypto.randomInt is a proper random source, unlike Math.random. The idempotency key is created once per challenge, so an internal retry of the same send reuses it. The rate limit should count per user and per phone number, because a verification endpoint is a favorite target for people who want to run up your bill. And the code expires.
For the verify step, compare hashes, count attempts, and invalidate the challenge after a few wrong guesses. Our OTP message format guide covers wording that autofill reads correctly, and the OTP and verification API post goes deeper on the server side.
The backend: notifications
A notification text is different: the app doesn't ask for a particular message, it reports an event. Your server turns the event into a text.
router.post("/orders/:id/ready-for-pickup", requireSession, async (req, res) => {
const order = await loadOrderForUser(req.params.id, req.user.id);
if (!order || !order.smsOptIn) return res.sendStatus(404);
await queue.add("sms", {
to: order.phone,
body: `Order ${order.number} is ready for pickup.`,
key: `order-ready-${order.id}`,
});
res.sendStatus(202);
}); The recipient comes from your order record, not the request body, and smsOptIn is your own consent flag. Putting the send on a queue means a slow response never holds up the app, and a retry reuses the same key. Handle 429 and 5xx as retries and other 4xx as final. A 409 QUIET_HOURS_BLOCK is a time rule: an API text is held only if the recipient's window opens within a few hours, otherwise nothing is sent and you send it again once the window opens. See handling the quiet hours 409.
If the texts are login or verification codes, add a login and verification campaign to your registration (use case TWO_FACTOR_AUTH over the API). The registration docs walk through it.
FAQ
Can I use a push notification instead of a text?
For users who allowed push and have the app installed, yes. SMS is for reaching people when push isn't an option or for codes that must arrive out of band.
Should the app send the phone number or should the backend look it up?
Look it up when you can. For notifications, load the number from your own records. For first-time verification the app has to send what the user typed, so validate and rate-limit it.
Is it safe to hide the key with an obfuscation library?
No. Obfuscation slows reading, it doesn't stop it. The only safe place for the key is a server you control.
The short version
The app holds a session token, your backend holds the key, and Ready only ever hears from your server. Start with the messages API docs, and create an account at tryready.com/signup when you're set to send.