Send an SMS message
POST/api/v1/sms
curl -X POST 'https://www.unitpost.com/api/v1/sms' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'User-Agent: my-app/1.0' \
-H 'Content-Type: application/json' \
-d '{
"to": "+15551234567",
"body": "Your code is 123456"
}'{
"object": "sms",
"id": "id_123",
"to": "customer@example.com",
"from": "you@yourdomain.com",
"direction": "outbound",
"status": "queued",
"type": "transactional",
"body": "string",
"segments": 0,
"in_reply_to": "string",
"received_at": "2026-01-01T00:00:00.000Z",
"looks_like_opt_out": false,
"country": "string",
"scheduled_at": "2026-01-01T00:00:00.000Z",
"last_error": "string",
"error": {
"code": "out_of_reach",
"message": "string"
},
"failure_code": "quota_exceeded",
"created_at": "2026-01-01T00:00:00.000Z",
"contact_id": "contact_123",
"participant_opted_out": false,
"tags": [
{
"name": "Example",
"value": "string"
}
]
}Send a single SMS — now, or at a future time by passing scheduled_at. The recipient must be a valid E.164 number. It doesn't have to be one of your contacts: a number you've never stored is sent to without creating a contact (pass create_contact to add one), and opt-outs and the suppression list still apply. Marketing sends additionally require the recipient's prior express consent on record and honor recipient-local quiet hours (they are deferred to the next allowed window, never dropped). The sender is chosen by the recipient's country — the active number or Sender ID whose reach covers it, exactly as campaigns route — unless you pin one with from (a snum_… id from List SMS numbers, or the number / Sender ID string). Pass an Idempotency-Key header to make retries safe: the same key with the same body replays the original message instead of sending (and billing) twice. Billing is per segment. Read delivery state back with Retrieve an SMS message. Requires the sms:send capability.
Parameters1 field
| Field | Type | Description |
|---|---|---|
Idempotency-Key | string · header | Any unique string (1–256 characters, e.g. a UUID). Retrying with the same key and the same body within 24 hours returns the first result instead of sending again; the same key with a different body is `409 invalid_idempotent_request`, and one still in flight is `409 concurrent_idempotent_requests`. |
Request body7 fields
| Field | Type | Description |
|---|---|---|
torequired | string | Recipient phone number in E.164 format, e.g. `+15551234567`. |
from | string | Optional sender to send from: a number id from `GET /sms/numbers` (`snum_…`), or the E.164 number / Sender ID string itself (e.g. `+18005550100`, `Acme`). Must belong to your workspace, be active, and be able to reach the recipient's country. Otherwise it answers `404 not_found`, `403 sender_not_approved`, or `422 sender_cannot_reach`. Omit to route automatically: a transactional text to someone who texted one of your numbers in the last 30 days goes out from that number, so a reply stays in the same thread on their phone; otherwise Unitpost picks the active sender whose reach covers the recipient's country (10DLC before toll-free for US recipients; the matching Sender ID elsewhere), exactly as campaigns do. |
bodyrequired | string | Message text. Billing is per segment (160 GSM-7 chars single-segment, 153 per segment concatenated; 70/67 for Unicode). |
type | enumtransactional | marketing | Defaults to `transactional`. Use `marketing` for anything promotional (offers, sales, newsletters): marketing sends require the recipient's prior express consent on record and honor recipient-local quiet hours. Sending promotional text as `transactional` skips both checks and breaks carrier rules. |
scheduled_at | string | Time to send at: ISO 8601 with `Z` or a `±hh:mm` offset (e.g. `2026-10-24T02:00:00Z` or `2026-10-24T09:00:00+07:00`), normalized to UTC. Omit to send immediately. A time in the past is not refused: the text goes out right away. A time in a later billing period is checked now (plan, price, country) but paid when it sends, from that period's allowance, so this period's balance does not refuse it. If the plan can't cover it then, the text ends `failed` with `failure_code` set (e.g. `quota_exceeded`), and `sms.failed` fires with the same code. |
create_contact | boolean | Create a contact for this recipient if one doesn't exist yet. Defaults to false. Sends don't modify your contact list. When the recipient is already a contact, the message is attached to them either way. A contact created this way records no consent, so it can't be used for marketing sends. |
tags | object[] | Labels to tell your texts apart later (which customer, feature or agent a text was for): up to 10 `{ name, value }` pairs, each half 1–256 ASCII letters, digits, `_` or `-`, the same rule as email tags. More than 10, or a character outside the rule, is `422 validation_error` and nothing is sent; keep anything more in your own records under the text's `id`. Returned as `tags` on the SMS object and in outbound `sms.*` webhooks; filter the list with `GET /sms?tag=name:value`. |
Response · 200 fields21 fields
| Field | Type | Description |
|---|---|---|
objectrequired | string | — |
idrequired | string | — |
torequired | string | — |
fromrequired | string | null | — |
directionrequired | enumoutbound | inbound | — |
statusrequired | enumqueued | scheduled | sending | sent | delivered | failed | suppressed | canceled | received | — |
typerequired | enumtransactional | marketing | — |
bodyrequired | string | null | — |
segmentsrequired | integer | Billed units. Outbound: segments. Inbound: the received text's segments when it was charged ($0.008 a segment in the US and $0.004 in Canada; a text charged before per-segment pricing was 1¢ flat and shows 1), else 0. |
in_reply_torequired | string | null | Inbound only: your text this reply answers (`sms_…`), when the carrier says which. Null otherwise. |
received_atrequired | string | null | Inbound only: when the reply reached Unitpost. Order a conversation by this; carriers don't guarantee order. Null on outbound. |
looks_like_opt_outrequired | boolean | Inbound only: the text reads like a request to stop texting ("please stop texting me") but was not an opt-out keyword, so no opt-out was recorded. Decide whether to record one (POST /v1/contacts/{id}/sms-consent, action opt_out). False for an exact keyword such as STOP (already recorded) and on outbound. |
countryrequired | string | null | The other party's country (ISO 3166-1 alpha-2): the recipient's on a send, the sender's on a received text. Null when the number's country isn't known. |
scheduled_atrequired | string | null | — |
last_errorrequired | string | null | The sentence for why the text failed or was skipped. Match on `failure_code` (failed) or `error.code` (suppressed), not on this text. |
errorrequired | object | null | Set on `suppressed` messages: the stable skip reason and its sentence. Null otherwise. |
failure_code | enum | null | Set on `failed` messages: why it failed, as a stable code (the sentence is `last_error`). Null otherwise. Only `carrier_undelivered` (the carrier accepted the text, then could not deliver it) is billed; every other failure is not charged. Billing when a scheduled text was due: `quota_exceeded`, `overage_cap_exceeded`, `subscription_inactive`, `sms_not_in_plan` (the paid plan ended and its grace is over, or it is 100% discounted); `unsupported_country`: SMS to the country was paused; workspace holds: `workspace_suspended`, `sms_brand_blocked`; the sender: `sender_not_active`, `sender_registration_incomplete`, `sender_action_required`, `sender_use_case_mismatch`; `quiet_hours_unsatisfiable`: marketing that could not go out inside the recipient's window; ours: `channel_unavailable`, `delivery_exhausted`; `provider_rejected`: refused before any carrier; `suspected_pumping`: stopped before the carrier as suspected SMS pumping. The same code is `failed.code` on the `sms.failed` webhook. |
created_atrequired | string | — |
contact_id | string | null | The contact this text is filed under (`con_…`), or null: an inbound text from a number that isn't a contact. Make one with POST /sms/{id}/contact. |
participant_opted_out | boolean | The other party (the sender of an inbound text, the recipient of an outbound one) can't be texted by this workspace now: they texted STOP or the number is suppressed. A reply to them is refused (`opted_out`) until they text START or UNSTOP. As of this read. |
tags | object[] | The tags the text was sent with (`tags` on `POST /sms`), in the order given. Empty for a text sent without tags and for received texts. |