Developers
Bulk SMS API reference
The PortSMS SMS API is a REST API with JSON over HTTPS and Bearer keys: send bulk SMS, estimate the cost, check delivery status and receive signed delivery webhooks.
V1https://portsms.com/api/v1
Getting started
Sending through the API takes three steps.
- 1Create an account. The sign-in token you save is your account.
- 2Top up from $40 with crypto in the PortSMS checkout, on the top-up page.
- 3Create an API key on the API keys page. It is shown once, so copy it to your server right away.
The API is available after the first top-up
Once your first top-up is credited you can create an API key, and the key can send right away.
Base address and keys
All calls go to the address below. Send your key in the Authorization header. Anyone with the key can spend your balance, so keep it on your server only.
https://portsms.com/api/v1Authorization: Bearer psm_your_api_key Content-Type: application/json
Limits: 300 calls a minute per account, 1,000 recipients per request, 50,000 messages per account in 24 hours.
Send a message
Sends one text to one or more numbers. Numbers must be in international format (+ and the country code). The whole cost is taken from your balance when the request is accepted; numbers that cannot be sent are listed in rejected with the reason and are not charged.
POST/api/v1/messages
| Field | Type | Notes |
|---|---|---|
| tostring or array | Recipient numbers, up to 1,000. Each item can also be an object { "to": "+1415...", "vars": ["Alice"] } whose vars fill {{1}}, {{2}} in the text | |
| textstring | Message text, up to 10 parts per recipient | |
| namestring, optional | A name for the send, shown in your history (80 characters) | |
| schedule_atstring, optional | ISO 8601 time to start, from 5 minutes to 29 days ahead. Charged now; cancel before it starts for a full refund | |
| opt_outboolean, optional | true adds "Reply STOP to opt out" on a new line at the end | |
| refstring, optional | Your own reference, returned in webhooks (64 characters) |
curl https://portsms.com/api/v1/messages \
-H "Authorization: Bearer $PORTSMS_KEY" \
-H "Content-Type: application/json" \
-d '{"to": ["+14155550123", "+447700900123"],
"text": "Your code is 482913",
"name": "Login codes",
"ref": "order-1042"}'{"to": [{"to": "+14155550123", "vars": ["Alice", "A-1042"]},
{"to": "+447700900123", "vars": ["Ben", "A-1043"]}],
"text": "Hi {{1}}, your order {{2}} has shipped.",
"schedule_at": "2026-10-14T09:00:00Z",
"opt_out": true}{
"campaign": {
"id": "c_7kq2m9xd4tpa", "name": "Login codes", "source": "api",
"text": "Your code is 482913", "encoding": "gsm7", "parts": 1,
"recipients": 2, "cost": "0.0156", "refunded": "0.0000",
"status": "sending", "ref": "order-1042", "scheduled_at": null,
"created_at": "2026-10-13T09:30:00.000Z", "done_at": null
},
"messages": [
{ "id": "m_3hx8q2vkd7mrtc", "campaign_id": "c_7kq2m9xd4tpa", "to": "+14155550123",
"country": "US", "status": "queued", "error": null, "parts": 1, "price": "0.0061",
"created_at": "2026-10-13T09:30:00.000Z", "sent_at": null, "done_at": null }
],
"rejected": []
}const res = await fetch("https://portsms.com/api/v1/messages", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.PORTSMS_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ to: ["+14155550123"], text: "Your code is 482913" }),
});
const data = await res.json();import os, requests
r = requests.post("https://portsms.com/api/v1/messages",
headers={"Authorization": "Bearer " + os.environ["PORTSMS_KEY"]},
json={"to": ["+14155550123"], "text": "Your code is 482913"})
print(r.status_code, r.json())Estimate before sending
Same body as sending. Returns encoding, parts, cost and the numbers that would be refused, and sends nothing.
POST/api/v1/estimate
{ "encoding": "gsm7", "characters": 19, "parts": 1, "recipients": 2,
"cost": "0.0156", "balance": "120.00",
"rejected": [ { "to": "4155550123", "reason": "format" } ] }Check one message
Status of one recipient, by the id returned when sending.
GET/api/v1/messages/{id}
{ "message": { "id": "m_3hx8q2vkd7mrtc", "to": "+14155550123", "status": "delivered",
"error": null, "price": "0.0061", "done_at": "2026-10-13T09:30:06.000Z", ... } }Campaigns (one per send)
Every send request is a campaign with the status scheduled, sending, done or canceled. List your last 100, open one to see counts per status and every recipient (500 per page, ?page=2 for more), or cancel a scheduled one with POST /api/v1/campaigns/{id}/cancel for a full refund.
GET/api/v1/campaigns
GET/api/v1/campaigns/{id}?page=1
POST/api/v1/campaigns/{id}/cancel
{ "campaign": { "id": "c_7kq2m9xd4tpa", "status": "done", "recipients": 2,
"counts": { "queued": 0, "sent": 0, "delivered": 1, "failed": 1 }, ... },
"messages": [ ... ], "page": 1, "page_size": 500 }Balance and prices
Your balance in US dollars, and the price per part for every country on sale.
GET/api/v1/balance
GET/api/v1/prices
{ "balance": "120.00", "currency": "USD" }
{ "prices": [ { "country": "US", "name": "United States", "dial_code": "+1", "price_per_part": "0.0061" }, ... ] }Message statuses
| Status | Meaning |
|---|---|
| queued | Accepted and charged, waiting to be handed to the carrier route |
| sent | Handed to the carrier route, waiting for a delivery report |
| delivered | The carrier reported delivery to the phone |
| failed | Rejected or not deliverable. The price was refunded to your balance |
Delivery webhooks
Set an https address on the API key page. When a message becomes delivered or failed we POST it as JSON. Until your server answers with a 2xx status, we send up to 8 attempts including the first, over about 2 hours (at intervals of 0 s, 30 s, 1 min, 2 min, 5 min, 15 min, 30 min and 1 h).
POST https://your-server.example/portsms
X-PortSMS-Signature: t=1791883806,v1=5f2c...e91a
Content-Type: application/json
{ "event": "sms.status",
"data": { "id": "m_3hx8q2vkd7mrtc", "campaign_id": "c_7kq2m9xd4tpa", "to": "+14155550123",
"country": "US", "status": "delivered", "error": null, "parts": 1, "price": "0.0061",
"ref": "order-1042", "done_at": "2026-10-13T09:30:06.000Z", ... } }Verify the X-PortSMS-Signature header: t is a Unix time and v1 is the HMAC-SHA256 of "t.body" with your signing secret. Reject requests older than five minutes.
import crypto from "node:crypto";
function verify(raw, header, secret) {
const m = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(header || "");
if (!m || Math.abs(Date.now() / 1000 - Number(m[1])) > 300) return false;
const want = crypto.createHmac("sha256", secret).update(m[1] + "." + raw).digest("hex");
return crypto.timingSafeEqual(Buffer.from(want), Buffer.from(m[2]));
}Handle each event once
A webhook can arrive more than once when a retry overlaps a slow answer. Use the message id and the status together as a key and ignore an event you have already stored.
Errors
Errors come back as JSON with an error code and an HTTP status.
// 1,000 numbers in Germany, 1 part each
{ "error": "insufficient_balance", "cost": "17.5000" }| Code | HTTP | What to do |
|---|---|---|
| bad_keyHTTP 401 | The key is missing or wrong | |
| no_depositHTTP 403 | The API is available once your first top-up is credited | |
| insufficient_balanceHTTP 402 | Top up the cost of this send to send it (the cost is included) | |
| no_recipientsHTTP 400 | 0 numbers can be sent (rejected lists the reasons) | |
| too_many_recipientsHTTP 413 | Up to 1,000 numbers per request | |
| empty_textHTTP 400 | Write the message text | |
| text_too_longHTTP 400 | A text can have up to 10 parts | |
| bad_scheduleHTTP 400 | schedule_at must be a time from 5 minutes to 29 days ahead | |
| daily_limitHTTP 429 | The account's 24-hour sending limit is used up | |
| rate_limitedHTTP 429 | Up to 300 calls per minute | |
| not_foundHTTP 404 | No message, send or page matches the id or address | |
| not_scheduledHTTP 409 | Only a scheduled campaign that has not started can be canceled |
Why a number is rejected
| Reason | What to do |
|---|---|
| format | Write it again in international format (wrong format or length) |
| country | A calling code that is not on the price list |
| price | A country without a price right now |
| duplicate | The same number appears twice in one request |
| too_long | With its vars filled in, the text is over 10 parts |
Limits
- Calls
- 300 a minute per account
- Numbers per request
- 1,000
- Messages per account
- 50,000 in 24 hours
- Parts per message
- 10 (1,530 GSM-7 or 670 Unicode characters)
- Scheduling
- 5 minutes to 29 days ahead
- Webhook retries
- Up to 8 attempts including the first, over about 2 hours, until your server answers 2xx
Create a key right after your first top-up.
Top up from $40, create a key on the API keys page and send your first request.