To send an SMS from Azure Functions, call POST /v1/messages with fetch (or HttpClient in .NET) from an HTTP-triggered or queue-triggered function, read the API key from an application setting, and send an Idempotency-Key header created once per message. Use an HTTP trigger when a caller needs the answer now, and a queue trigger when the text can happen a moment later and must survive failures.
The examples below use the Node.js programming model, but the request is identical in C# or Python. If you're on .NET, our post on sending SMS from C# has the HttpClient version.
The request
Base URL https://api.tryready.com, header X-API-Key, JSON body with to in E.164 (a 10-digit US number is treated as +1), body and consent_attested. Set consent_attested to true only when the recipient agreed to texts. Leave from out and Ready picks the number: the one this contact already texts with, otherwise your number closest to their area code.
Keep one small helper that every trigger calls, so retries, timeouts and headers live in one place:
async function sendText(message, idempotencyKey) {
const res = await fetch("https://api.tryready.com/v1/messages", {
method: "POST",
headers: {
"X-API-Key": process.env.READY_API_KEY,
"Content-Type": "application/json",
"Idempotency-Key": idempotencyKey,
},
body: JSON.stringify({ ...message, consent_attested: true }),
signal: AbortSignal.timeout(8000),
});
return res;
} Keep the key in an application setting
In the Azure portal, open the function app, go to Environment variables, and add READY_API_KEY. For local work, put it in local.settings.json, which the Functions tooling keeps out of source control by default, and use a different key from production. At runtime it's process.env.READY_API_KEY.
For tighter control, store the key in Azure Key Vault and make the app setting a Key Vault reference, with the function app's managed identity allowed to read that one secret. The code doesn't change, but the key never sits in the app's configuration as plain text. Whichever you choose, never log headers. API key security and rotation covers rotating a key without downtime.
Option 1: an HTTP trigger
Use this when another service calls your function, for example a form handler or a webhook from your own app.
const { app } = require("@azure/functions");
app.http("sendText", {
methods: ["POST"],
authLevel: "function",
handler: async (request, context) => {
const { messageId, phone, orderId } = await request.json();
const res = await sendText(
{ to: phone, body: `Your order #${orderId} has shipped.` },
messageId
);
if (res.ok) return { status: 202, body: "sent" };
if (res.status === 429 || res.status >= 500) {
return { status: 503, body: "try again" };
}
context.error("send refused", res.status, messageId, await res.text());
return { status: 422, body: "refused" };
},
}); The caller passes messageId, a UUID it created once when the event happened. If the caller retries on a 503, it reuses that same UUID, and Ready doesn't send a second text. If your function generated the key itself, every caller retry would mint a new one and the protection would disappear.
Option 2: a queue trigger
When the text can wait a second or two, put a message on an Azure Storage queue and let a queue-triggered function send it. The platform then handles retries for you.
app.storageQueue("textFromQueue", {
queueName: "outbound-texts",
connection: "AzureWebJobsStorage",
handler: async (item, context) => {
const { messageId, phone, body } = item;
const res = await sendText({ to: phone, body }, messageId);
if (res.ok) return;
if (res.status === 429 || res.status >= 500) {
throw new Error(`Ready returned ${res.status}`);
}
context.error("send refused", res.status, messageId, await res.text());
},
}); Throwing makes the message reappear after the visibility timeout and run again, up to the queue's maximum dequeue count, after which it lands in the poison queue (outbound-texts-poison). Returning normally deletes the message. That's why the function returns on a 4xx: a refused request will be refused again, and looping on it only fills the poison queue.
HTTP or queue, at a glance
| HTTP trigger | Queue trigger | |
|---|---|---|
| Caller waits for result | Yes | No |
| Retries handled by | The caller | The queue (dequeue count) |
| Failed messages end up | In the caller's logs | In the poison queue, inspectable |
| Good for | Codes, one-off confirmations | Reminders, receipts, anything that must not be lost |
| Spike protection | None | The queue absorbs it |
Most production setups use both: an HTTP function that validates input and enqueues, and a queue function that sends. Our guide to queue design for platforms covers throttling and dead letters.
Idempotency across redeliveries
Storage queues deliver at least once, so the same message can reach your function twice even when nothing failed. Create the UUID when the work item is first created, put it in the queue message, and send it as Idempotency-Key every time. Don't derive a new key from the dequeue time or the invocation ID, because those change on every run.
If a message sits in the poison queue for a long time, check GET /v1/messages before you resubmit it. This avoids a second text if the first one went out and only the acknowledgment was lost (the messages reference has the details). Read idempotency and duplicate texts for the longer version.
Concurrency, quiet hours and opt-outs
Queue triggers can scale out to many parallel instances. Texting has a per-second ceiling per registered campaign (a fresh standard campaign is roughly 1 to 4 segments per second, and higher tiers allow tens), so cap concurrency in the function's host settings or batch size and don't let a big enqueue fan out unchecked.
Ready also does some of the work for you:
- Opted-out numbers and Ban-list numbers are refused up front and not charged.
- An API text in the recipient's quiet hours is held only if the window opens within 6 hours. Otherwise it isn't sent and the API answers
409 QUIET_HOURS_BLOCK; send it again once the window opens. - These rules reduce risk. Consent and message content remain your responsibility.
Cost and registration
A segment costs $0.0075 plus a $0.0045 carrier fee. A card on file and a number of your own ($2 a month) are required to send. An account can send up to 500 texts a month before it registers; after that it has to, and most approvals take 2 to 7 days. Accounts opened before November 12, 2026 keep their signup prices, shown under Billing. The pricing page has the full list.
Frequently asked questions
Does the Azure Functions consumption plan work for this?
Yes. The call is an ordinary outbound HTTPS request, so any plan that can reach the internet works. Set the function timeout above your request timeout.
Where should the idempotency key come from?
From the event that created the work: a UUID stored on the order, or one the caller creates and passes in. Never generate it inside the retry path.
Should I use a Service Bus queue instead of a Storage queue?
Either works. Service Bus adds features such as dead-letter handling and sessions; the send code and the idempotency approach are the same.
The short version
Keep the key in an app setting or Key Vault, send with fetch, create one UUID per message and reuse it on every attempt, and use a queue trigger for anything that must not be lost. The API quickstart gets you to a first send, and sending SMS from AWS Lambda shows the same pattern on another cloud. When you want to try it, sign up and send from your own number.