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.
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
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
text | query|body | string | yes | The message (max 20,000 characters). | |
segments | query|body | boolean | no | false | true: include the text of each segment. |
brandname | query|body | string | no | Sender 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."}'const res = await fetch('https://apibox.io.vn/v1/sms-count', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"text": "Mã OTP của bạn là 123456, hiệu lực 5 phút."
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/sms-count",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"text": "Mã OTP của bạn là 123456, hiệu lực 5 phút."},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/sms-count');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"text":"Mã OTP của bạn là 123456, hiệu lực 5 phút."}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));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
Text Diff
Compare two texts by lines, words, characters, sentences or JSON and get the changes, a similarity score and a unified diff patch.
a-bSlugify
Turn titles into clean URL slugs: accents removed (Vietnamese đ included), custom separator, optional case keeping and maximum length.
123Text Statistics
Count words, characters, sentences, paragraphs and lines, estimate reading and speaking time, and list the most frequent words of a text.