To send an SMS from C++, use libcurl to POST a small JSON body to https://api.tryready.com/v1/messages with your key in an X-API-Key header. The body carries to, body and consent_attested. Add an Idempotency-Key header so a retried request never sends twice.
C++ shows up in texting work more than people expect: device firmware, game servers, trading systems and desktop tools that need to tell someone a job finished. There's no official C++ SDK to learn. A text is one HTTPS request, and libcurl already does that well. We make Ready, so the example sticks to the one request shape we document.
Before you start
- An API key from Ready, read from an environment variable rather than compiled into the binary.
- A card on file and a number of your own. Both are needed to send. A number is $2 a month.
- Consent you can show.
consent_attested: trueis your promise that the person agreed to texts. Only send it when you hold that record. - libcurl with HTTPS support, and a JSON library if you build bodies from user data (nlohmann/json is common).
A text costs $0.0075 per segment plus a $0.0045 carrier fee. See the pricing page for the full list.
The request
#include <curl/curl.h>
#include <cstdlib>
#include <string>
#include <iostream>
static size_t sink(char* p, size_t s, size_t n, void* out) {
static_cast<std::string*>(out)->append(p, s * n);
return s * n;
}
int send_text(const std::string& to, const std::string& body, const std::string& idem) {
const char* key = std::getenv("READY_API_KEY");
if (!key) return -1;
std::string json = "{\"to\":\"" + to + "\",\"body\":\"" + body +
"\",\"consent_attested\":true}";
std::string reply;
CURL* curl = curl_easy_init();
curl_slist* h = nullptr;
h = curl_slist_append(h, "Content-Type: application/json");
h = curl_slist_append(h, (std::string("X-API-Key: ") + key).c_str());
h = curl_slist_append(h, ("Idempotency-Key: " + idem).c_str());
curl_easy_setopt(curl, CURLOPT_URL, "https://api.tryready.com/v1/messages");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, h);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, sink);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &reply);
CURLcode rc = curl_easy_perform(curl);
long status = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
curl_slist_free_all(h);
curl_easy_cleanup(curl);
if (rc != CURLE_OK) return -2; // network problem: safe to retry with the same key
return static_cast<int>(status); // 2xx accepted; anything else, read the reply
} The to value is E.164, like +12125550199. A 10-digit US number is treated as +1. Build the JSON with a real library in production. The string concatenation above breaks the moment a message contains a quote or a newline.
Idempotency keys in a C++ program
Generate one UUID per message and reuse it on every retry of that message. If the process dies after the request leaves but before you read the reply, the retry carries the same key and nobody gets two texts. Don't derive the key from the clock. Derive it from something you already store, such as the order ID plus the message type. Our post on idempotency keys for SMS goes deeper.
What to do with each status
| Result | Meaning | What your code does |
|---|---|---|
| 2xx | Accepted | Record it and move on |
409 QUIET_HOURS_BLOCK | The recipient is in quiet hours and the window is more than 6 hours away | Send again after the window opens, or set hold_until_allowed |
403 api_consent_attested_required | The send had no consent attestation | Fix the body; do not retry as is |
| Opted-out or Ban list number | Refused up front, not charged | Treat as final |
| 5xx or a curl error | Transient | Retry with backoff and the same key |
The quiet hours 409 guide explains the first row in detail, and the error codes docs list the rest.
Practical notes
Call curl_global_init once at startup, not per request. Reuse one easy handle per thread if you send often, since it keeps the TLS connection open. Set a timeout so a stalled network never freezes your main loop. For bursts, put sends on a worker queue instead of the thread that does your real work.
Frequently asked questions
Is there a C++ SDK for Ready? No, and you don't need one. The API is plain HTTPS and JSON, so libcurl or any HTTP client covers it.
Can I send from an embedded device? Yes, if it can make a TLS request. For very small devices, have them call a small service you run, and keep the API key on that service.
How do I send to many numbers? Use POST /v1/messages/bulk with to as an array of at most 100 numbers per call, and split bigger lists. The bulk messages docs have the details.
Next step
Send one text to your own phone, then run the same call twice with the same idempotency key and confirm only one arrives. The API quickstart shows how to create your key. If you'd rather start from a shell, see sending SMS with curl.
Accounts opened before November 12, 2026 keep their signup prices, shown under Billing.