SMS segment counter API

Count SMS segments (GSM-7 160/153 or UCS-2 70/67), list the characters that force Unicode, get an unaccented GSM-safe version and check a brandname.

GETPOSThttps://apibox.io.vn/v1/sms-count

An SMS holds 160 characters of the GSM 7-bit alphabet, or only 70 as soon as one character is outside it (UCS-2), and long messages are split into parts of 153 or 67 characters. Every Vietnamese accent, curly quote or emoji therefore doubles or triples the cost of a message. The API tells you the encoding, the units used (septets or UTF-16 code units, the GSM extension characters ^ { } [ ] ~ | € \ counting twice), the number of segments and what is left in the last one.

It lists each character that forces UCS-2 with its code point, position and suggested replacement, and returns a GSM-safe version of the text: Vietnamese accents removed, smart quotes, dashes and ellipses replaced, emoji dropped, with its own segment count and how many segments it saves. segments=true adds the text of each part, and brandname checks an alphanumeric sender ID (at most 11 characters).

Counting follows 3GPP TS 23.038 / 23.040; carriers may add their own limits on concatenated brandname messages.

Parameters

NameInTypeRequiredDefault
textquery|bodystringyesThe message (max 20,000 characters).
segmentsquery|bodybooleannofalsetrue: include the text of each segment.
brandnamequery|bodystringnoSender ID to check (≤ 11 characters).

Example

curl -X POST "https://apibox.io.vn/v1/sms-count" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"Mã OTP của bạn là 123456, hiệu lực 5 phút."}'

Response

{
  "encoding": "UCS-2",
  "characters": 42,
  "units": 42,
  "unit": "UTF-16 code units",
  "segments": 1,
  "per_segment": 70,
  "remaining_in_segment": 28,
  "ucs2_characters": [
    {
      "char": "ã",
      "codepoint": "U+00E3",
      "count": 1,
      "first_index": 1,
      "replacement": "a"
    },
    {
      "char": "ủ",
      "codepoint": "U+1EE7",
      "count": 1,
      "first_index": 8,
      "replacement": "u"
    },
    {
      "char": "ạ",
      "codepoint": "U+1EA1",
      "count": 1,
      "first_index": 12,
      "replacement": "a"
    },
    {
      "char": "ệ",
      "codepoint": "U+1EC7",
      "count": 1,
      "first_index": 28,
      "replacement": "e"
    },
    {
      "char": "ự",
      "codepoint": "U+1EF1",
      "count": 1,
      "first_index": 32,
      "replacement": "u"
    },
    {
      "char": "ú",
      "codepoint": "U+00FA",
      "count": 1,
      "first_index": 39,
      "replacement": "u"
    }
  ],
  "extension_characters": [],
  "gsm_version": {
    "encoding": "GSM-7",
    "characters": 42,
    "units": 42,
    "unit": "septets",
    "segments": 1,
    "per_segment": 160,
    "remaining_in_segment": 118,
    "text": "Ma OTP cua ban la 123456, hieu luc 5 phut.",
    "changed_characters": 7,
    "saves_segments": 0
  },
  "note": "Single SMS: 160 GSM-7 characters or 70 UCS-2 characters; concatenated parts carry a 7-byte header (153 / 67 per part). Characters of the GSM extension table (^ { } \\ [ ] ~ | €) count twice. Any Vietnamese accent forces UCS-2."
}

Use cases

  • Show a live character / segment counter in an SMS form
  • Cut OTP and marketing SMS costs by removing accents
  • Validate templates before registering them with carriers
  • Find the hidden character that turns a message into Unicode

FAQ

Why does one accent change everything?

Vietnamese letters with accents (ă, ơ, ệ…) are not in the GSM alphabet, so the whole message switches to UCS-2: 70 characters instead of 160.

Are é, è, à allowed in GSM?

Yes, a few accented Latin letters (é è ù ì ò à Ä Ö Ñ Ü…) are part of the GSM alphabet, so they do not force UCS-2; the GSM-safe version still removes every accent, as usual for Vietnamese SMS.

How are emoji counted?

As UCS-2, and most emoji take two UTF-16 code units, so 35 emoji fill a single SMS.

Related APIs

Start with 1,000 free requests every month. Get free API key →