{"openapi":"3.1.0","info":{"title":"SMS Gateway API","version":"1.0.0","summary":"Send SMS through your own SIM card, like SMTP for text messages.","description":"Submit a message to the API; it is queued, and the Android phone that owns the chosen SIM sends it. Poll `GET /v1/messages/{id}` for the outcome.\n\nEvery request needs your **Auth ID** and **Secret ID** (client portal → Account & Security) as the headers `X-Auth-Id` and `X-Secret-Id`. There is no Bearer or query-string alternative. Keep the Secret ID on your server. All paths are under `/v1/messages`; the base URL is the address of this server (shown on the docs page).\n\n**Phone numbers.** Send international format such as `+923001234567`. Spaces, dashes, dots and brackets are removed and the rest must be an optional + and 7 to 15 digits. Nothing is converted: a local `03001234567` is accepted and handed to the SIM as written, and the response `to` is the cleaned input, not a rewritten number.\n\n**Lifecycle.** `queued` → `dispatched` (the phone has it) → `sent` (every part left the phone) → `delivered` (the network confirmed every part). `delivered`, `failed`, `expired` and `cancelled` are final. `sent` is not guaranteed to become `delivered`: some carriers send no delivery receipt, and the status is never changed automatically after `sent`. A `queued` message past `expiresAt` becomes `expired` (checked about every 30 seconds). A `dispatched` message the phone never reports on becomes `failed` with `NO_DEVICE_REPORT` after 5 minutes (server default) and is never re-sent. `error` and `failedAt` are set for `failed`, `expired` and `cancelled`.\n\n**Retries.** Always send a `reference`. A repeated `reference` returns the original message with HTTP 200 and sends nothing, so a retry after a timeout is safe, and it doubles as a lookup by reference. Without a `reference`, retrying after a timeout can send the SMS twice. After `failed`, `expired` or `cancelled` the old reference still returns that dead message, so use a new reference to try again.\n\n**Rate limits.** Requests per minute and per day come from your plan; every authenticated response carries `X-RateLimit-Limit` and `X-RateLimit-Remaining`. A separate limit caps messages per second, and every message in a batch counts toward it, so a batch bigger than that limit is rejected as a whole. Quotas count SMS parts, not messages. There are no webhooks yet: poll `GET /v1/messages/{id}` every 2 to 5 seconds, backing off, until the status is final, and give up at `expiresAt` plus 6 minutes: a queued message expires at `expiresAt`, and one the phone took fails within 5 minutes if the phone never reports. Treat a message still `sent` after that as left the phone with no delivery receipt."},"servers":[{"url":"/","description":"This server"}],"tags":[{"name":"Messages","description":"Queue messages and follow them from queued to delivered."},{"name":"Senders","description":"Which SIMs can send right now."}],"security":[{"AuthId":[],"SecretId":[]}],"paths":{"/v1/messages":{"post":{"tags":["Messages"],"operationId":"sendMessage","summary":"Send a message","description":"Queues one message and returns immediately with status `queued` (HTTP 202). The phone sends it within a second or two when it is online.\n\nRe-sending the same `reference` never sends a second SMS: it returns the original message with HTTP 200, so your own retries are safe.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendMessageRequest"},"examples":{"basic":{"summary":"A one-time code","value":{"to":"+923001234567","text":"Your code is 4821"}},"full":{"summary":"With a reference and a SIM","value":{"to":"+923001234567","text":"Your order has shipped.","reference":"order-1001","from":"+923368216697","ttlSeconds":300}}}}}},"responses":{"200":{"description":"This `reference` was already used; the original message is returned and nothing new is sent.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Message"}}}},"202":{"description":"Accepted and queued.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Message"},"examples":{"queued":{"value":{"id":"3f6c1e1a-7b0e-4a53-9d5e-5f1d7a3c9b21","to":"+923001234567","text":"Your code is 4821","status":"queued","parts":1,"reference":"order-1001","from":{"simId":"b1c0a6f2-0d0a-4a7c-8f5b-2c9a1e4d7e10","phoneNumber":"+923368216697"},"error":null,"source":"api","createdAt":"2026-11-18T09:30:00.000Z","expiresAt":"2026-11-18T09:40:00.000Z","sentAt":null,"deliveredAt":null,"failedAt":null}}}}}},"400":{"description":"The request was rejected. See `error.code`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or wrong credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"`ACCOUNT_SUSPENDED` or `MESSAGE_BLOCKED`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"`NO_SENDER_AVAILABLE`: no phone has sending turned on.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"423":{"description":"`ACCOUNT_LOCKED`: a registered SIM was removed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit or quota reached.","headers":{"Retry-After":{"description":"Seconds to wait before retrying. Sent for the per-minute and per-day request limits. The per-second message limit puts the same number in `error.retryAfter` (always 1) instead, and `QUOTA_EXCEEDED` has neither, so switch on `error.code`, not on the status.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"`SMS_DISABLED`: sending is switched off by the administrator.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"get":{"tags":["Messages"],"operationId":"listMessages","summary":"List messages","description":"Newest first. Pass the returned `next` back as `before` to read the next page; `next` is `null` on the last page.","parameters":[{"name":"status","in":"query","description":"Only messages in this status.","schema":{"enum":["queued","dispatched","sent","delivered","failed","expired","cancelled"]},"example":"delivered"},{"name":"limit","in":"query","description":"Page size.","schema":{"type":"integer","minimum":1,"maximum":100,"default":25},"example":10},{"name":"before","in":"query","description":"The `next` value from the previous page.","schema":{"type":"integer","minimum":1}}],"responses":{"200":{"description":"A page of messages.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageList"}}}},"400":{"description":"The request was rejected. See `error.code`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or wrong credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit or quota reached.","headers":{"Retry-After":{"description":"Seconds to wait before retrying. Sent for the per-minute and per-day request limits. The per-second message limit puts the same number in `error.retryAfter` (always 1) instead, and `QUOTA_EXCEEDED` has neither, so switch on `error.code`, not on the status.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/messages/batch":{"post":{"tags":["Messages"],"operationId":"sendBatch","summary":"Send up to 100 messages","description":"All or nothing: if any message is invalid, or the batch goes over a limit, the whole batch is rejected and nothing is queued. The error `message` names the failing item with a zero-based index, e.g. `messages.3.to: …` is the fourth message. The answer is always 202 with the messages in the order you sent them. A `reference` that was already used (earlier, or earlier in the same batch) returns that existing message in its place instead of a new one, and the response does not mark which entries are new. Each message counts toward the per-second message limit, so keep a batch within it.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BatchRequest"},"examples":{"two":{"summary":"Two messages","value":{"messages":[{"to":"+923001234567","text":"Your code is 4821","reference":"login-8812"},{"to":"+923007654321","text":"Your order has shipped.","reference":"order-1001"}]}}}}}},"responses":{"202":{"description":"All messages queued, in the order you sent them.","content":{"application/json":{"schema":{"type":"object","required":["messages"],"properties":{"messages":{"type":"array","items":{"$ref":"#/components/schemas/Message"}}}}}}},"400":{"description":"The request was rejected. See `error.code`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or wrong credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"`ACCOUNT_SUSPENDED` or `MESSAGE_BLOCKED`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"`NO_SENDER_AVAILABLE`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"423":{"description":"`ACCOUNT_LOCKED`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit or quota reached.","headers":{"Retry-After":{"description":"Seconds to wait before retrying. Sent for the per-minute and per-day request limits. The per-second message limit puts the same number in `error.retryAfter` (always 1) instead, and `QUOTA_EXCEEDED` has neither, so switch on `error.code`, not on the status.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"`SMS_DISABLED`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/messages/senders":{"get":{"tags":["Senders"],"operationId":"listSenders","summary":"List SIMs that can send","description":"Use a SIM `id` or `phoneNumber` as `from` when sending. `online` is true while the phone has checked in within the last 90 seconds.","responses":{"200":{"description":"The SIMs ready to send.","content":{"application/json":{"schema":{"type":"object","required":["senders"],"properties":{"senders":{"type":"array","items":{"$ref":"#/components/schemas/Sender"}}}}}}},"400":{"description":"The request was rejected. See `error.code`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or wrong credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit or quota reached.","headers":{"Retry-After":{"description":"Seconds to wait before retrying. Sent for the per-minute and per-day request limits. The per-second message limit puts the same number in `error.retryAfter` (always 1) instead, and `QUOTA_EXCEEDED` has neither, so switch on `error.code`, not on the status.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/messages/{id}":{"get":{"tags":["Messages"],"operationId":"getMessage","summary":"Get a message","description":"Poll this to follow a message: `queued` → `dispatched` → `sent` → `delivered`, or `failed` / `expired` / `cancelled`. Poll every 2 to 5 seconds with backoff until the status is final, and give up at `expiresAt` plus 6 minutes (a message still `sent` then left the phone but got no delivery receipt). This endpoint is rate-limited like the others. You cannot look a message up by `reference` here; send it again with the same `reference` to get it back, or keep the `id`.","parameters":[{"$ref":"#/components/parameters/MessageId"}],"responses":{"200":{"description":"The message.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Message"}}}},"400":{"description":"The request was rejected. See `error.code`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or wrong credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"`NOT_FOUND`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit or quota reached.","headers":{"Retry-After":{"description":"Seconds to wait before retrying. Sent for the per-minute and per-day request limits. The per-second message limit puts the same number in `error.retryAfter` (always 1) instead, and `QUOTA_EXCEEDED` has neither, so switch on `error.code`, not on the status.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/messages/{id}/cancel":{"post":{"tags":["Messages"],"operationId":"cancelMessage","summary":"Cancel a message","description":"Only works while the status is still `queued`. Once the phone has the message it cannot be recalled.","parameters":[{"$ref":"#/components/parameters/MessageId"}],"responses":{"200":{"description":"The cancelled message.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Message"}}}},"400":{"description":"The request was rejected. See `error.code`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or wrong credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"`NOT_FOUND`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"`NOT_CANCELLABLE`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit or quota reached.","headers":{"Retry-After":{"description":"Seconds to wait before retrying. Sent for the per-minute and per-day request limits. The per-second message limit puts the same number in `error.retryAfter` (always 1) instead, and `QUOTA_EXCEEDED` has neither, so switch on `error.code`, not on the status.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"components":{"securitySchemes":{"AuthId":{"type":"apiKey","in":"header","name":"X-Auth-Id","description":"Your account Auth ID (starts with `ak_`)."},"SecretId":{"type":"apiKey","in":"header","name":"X-Secret-Id","description":"Your account Secret ID (starts with `sk_`). Never put it in a website or app that visitors can read."}},"parameters":{"MessageId":{"name":"id","in":"path","required":true,"description":"The message id returned when it was queued.","schema":{"type":"string"}}},"schemas":{"SendMessageRequest":{"type":"object","properties":{"to":{"type":"string","minLength":1,"maxLength":30,"description":"Recipient phone number: an optional leading + and 7 to 15 digits. Spaces, dashes, dots and brackets are removed. The number is not converted, so use international format such as +923001234567; a local number such as 03001234567 is handed to the SIM exactly as written."},"text":{"type":"string","minLength":1,"maxLength":5000,"description":"The message. The alias `message` is also accepted. Length is counted in characters the way a JavaScript string counts them (an emoji counts as 2). The limit comes from your plan and never exceeds the server cap (1,600 characters by default); a longer text is rejected with `MESSAGE_TOO_LONG`, and the error message states the limit. Plain GSM text is 1 part up to 160 characters and 153 per part after that. One character outside GSM (Urdu, Arabic, emoji) makes the whole text UCS-2: 70, then 67 per part. A few GSM characters ({ } [ ] ~ ^ | \\ and the euro sign) count as 2."},"from":{"description":"Optional. The id or phone number of the SIM to send from. By default the load is spread over your online SIMs.","type":"string","minLength":1,"maxLength":64},"reference":{"description":"Optional. Your own id, up to 100 characters, unique per account. Sending the same reference again never sends a second SMS: it returns the first message as it is now (any status) with HTTP 200 and ignores the content of the new body (it must still be a valid request). A reference stays used even if its message failed, expired or was cancelled, so use a new one to try again. Without a reference, a retry after a timeout can send twice, so always set one.","type":"string","minLength":1,"maxLength":100},"ttlSeconds":{"description":"Optional. How long to keep trying while the phone is offline. Default 600, at most 86400.","type":"integer","minimum":30,"maximum":86400}},"required":["to","text"]},"BatchRequest":{"type":"object","required":["messages"],"properties":{"messages":{"type":"array","minItems":1,"maxItems":100,"items":{"$ref":"#/components/schemas/SendMessageRequest"}}}},"Message":{"type":"object","required":["id","to","text","status","parts","createdAt"],"properties":{"id":{"type":"string","format":"uuid"},"to":{"type":"string","description":"The recipient as stored: your input with spaces, dashes, dots and brackets removed. It is not converted to international format."},"text":{"type":"string"},"status":{"enum":["queued","dispatched","sent","delivered","failed","expired","cancelled"],"description":"`dispatched` means the phone has it; `sent` means every part left the phone; `delivered` means the recipient network confirmed every part. Final states: `delivered`, `failed`, `expired`, `cancelled`. `sent` can stay as it is when the carrier gives no delivery receipt."},"parts":{"type":"integer","description":"How many SMS the text is split into. Plans count parts, not messages."},"reference":{"type":["string","null"],"description":"Your own id, if you sent one."},"from":{"type":["object","null"],"properties":{"simId":{"type":"string"},"phoneNumber":{"type":["string","null"]}}},"error":{"type":["string","null"],"description":"Why it ended as `failed`, `expired` or `cancelled`; null otherwise. The codes are listed under Failure reasons on the docs page and in `x-failure-codes` in this document. Treat it as an open string."},"source":{"type":"string","description":"`api` or `portal`."},"createdAt":{"type":"string","format":"date-time"},"expiresAt":{"type":["string","null"],"format":"date-time"},"sentAt":{"type":["string","null"],"format":"date-time"},"deliveredAt":{"type":["string","null"],"format":"date-time"},"failedAt":{"type":["string","null"],"format":"date-time"}},"example":{"id":"3f6c1e1a-7b0e-4a53-9d5e-5f1d7a3c9b21","to":"+923001234567","text":"Your code is 4821","status":"queued","parts":1,"reference":"order-1001","from":{"simId":"b1c0a6f2-0d0a-4a7c-8f5b-2c9a1e4d7e10","phoneNumber":"+923368216697"},"error":null,"source":"api","createdAt":"2026-11-18T09:30:00.000Z","expiresAt":"2026-11-18T09:40:00.000Z","sentAt":null,"deliveredAt":null,"failedAt":null}},"MessageList":{"type":"object","required":["messages","next"],"properties":{"messages":{"type":"array","items":{"$ref":"#/components/schemas/Message"}},"next":{"type":["integer","null"],"description":"Pass as `before` for the next page; null on the last page."}}},"Sender":{"type":"object","properties":{"id":{"type":"string"},"phoneNumber":{"type":["string","null"]},"carrier":{"type":["string","null"]},"slotIndex":{"type":"integer"},"device":{"type":["string","null"]},"online":{"type":"boolean"}}},"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"object","required":["code","message"],"properties":{"code":{"type":"string"},"message":{"type":"string"},"retryAfter":{"type":"integer"}}}},"example":{"error":{"code":"NO_SENDER_AVAILABLE","message":"No SIM is ready to send. On the phone, open the app and turn on 'Send SMS from this phone'."}}}}},"x-errors":[{"status":400,"code":"VALIDATION_ERROR","meaning":"The body or a parameter is malformed. The message names the field."},{"status":400,"code":"INVALID_PHONE","meaning":"`to` is not a valid phone number: an optional leading + and 7 to 15 digits (spaces, dashes, dots and brackets are ignored). Use international format, e.g. +923001234567."},{"status":400,"code":"MESSAGE_TOO_LONG","meaning":"The text is longer than your plan's maximum (never more than the server cap, 1,600 characters by default). The error message states the limit."},{"status":400,"code":"UNKNOWN_SENDER","meaning":"`from` is not the id or number of a SIM on your account that has sending turned on."},{"status":401,"code":"API_AUTH_REQUIRED","meaning":"The X-Auth-Id or X-Secret-Id header is missing."},{"status":401,"code":"API_AUTH_FAILED","meaning":"The Auth ID / Secret ID pair is wrong."},{"status":403,"code":"ACCOUNT_SUSPENDED","meaning":"The account is suspended. Contact support."},{"status":403,"code":"MESSAGE_BLOCKED","meaning":"The text matches a template the administrator blocked."},{"status":404,"code":"NOT_FOUND","meaning":"No such message, or it belongs to another account."},{"status":409,"code":"NO_SENDER_AVAILABLE","meaning":"No SIM is ready to send. On the phone, open the app and turn on 'Send SMS from this phone'."},{"status":409,"code":"NOT_CANCELLABLE","meaning":"The message already reached the phone, so it can no longer be cancelled."},{"status":423,"code":"ACCOUNT_LOCKED","meaning":"A registered SIM was removed from its phone. Put it back and verify it again."},{"status":429,"code":"RATE_LIMITED","meaning":"Too many requests per minute or day, or too many messages per second. Wait `Retry-After` seconds when the header is present, otherwise `error.retryAfter`."},{"status":429,"code":"QUOTA_EXCEEDED","meaning":"Your plan's daily, monthly or lifetime SMS allowance is used up. There is no `Retry-After`: daily and monthly allowances roll over at 00:00 UTC (the 1st for monthly), or raise your plan. Retrying sooner will not help."},{"status":429,"code":"TOO_MANY_FAILED_ATTEMPTS","meaning":"Too many wrong credentials from this address. Try again in a few minutes (no `Retry-After` header)."},{"status":503,"code":"SMS_DISABLED","meaning":"The administrator has temporarily switched sending off."}],"x-failure-codes":[{"code":"NO_SERVICE","meaning":"The phone has no mobile signal."},{"code":"LIMIT_EXCEEDED","meaning":"Android asked the person holding the phone to confirm a burst of messages (about 30 in 30 minutes) and they did not."},{"code":"RADIO_OFF","meaning":"The phone is in airplane mode or its radio is off."},{"code":"SIM_NOT_PRESENT","meaning":"The SIM is no longer in the phone."},{"code":"NO_SEND_SMS_PERMISSION","meaning":"The app lost the SMS permission."},{"code":"GENERIC_FAILURE","meaning":"Android reported an unspecified failure."},{"code":"SHORT_CODE_NOT_ALLOWED","meaning":"Android blocked sending to this short code."},{"code":"DELIVERY_FAILED","meaning":"The message left the phone but the recipient network reported it undelivered."},{"code":"NO_DEVICE_REPORT","meaning":"The phone took the message but never reported back. It is not re-sent, so nobody gets a duplicate."},{"code":"EXPIRED","meaning":"The phone stayed offline past the message's `ttlSeconds`."},{"code":"CANCELLED","meaning":"You cancelled it."}]}