Quickstart
Send your first SMS through the API in about five minutes. You work in the sandbox the whole way: real API calls, simulated phones, nothing charged. Going live at the end is one key change.
You need a terminal with curl, or Node.js 20+, Python 3.8+ with requests, or PHP 7.4+ with the curl extension. Node examples are ES modules: save them as .mjs. Pick your language once on any example and every example on the site follows.
Create your account
Sign up at app.semalink.africa. It's free, and you don't need to wait for anything: sandbox keys work from the moment your account exists, while we verify your business in the background.
Get a test key
In the dashboard, open Developer, then API keys, then Create key.
- Choose Test mode. A test key starts with
sk_test_and only ever talks to the sandbox. (Until your business is verified, test keys are the only kind you can make.) - Give it a label you'll recognise later, such as "Laptop".
- Copy the key. It's shown once.
Keep the key out of your code. Put it in an environment variable:
export SEMALINK_API_KEY="sk_test_..."Check it works by asking who you are:
curl https://api.semalink.africa/v1/account \
-H "Authorization: Bearer $SEMALINK_API_KEY"2
const response = await fetch('https://api.semalink.africa/v1/account', {
headers: { Authorization: `Bearer ${process.env.SEMALINK_API_KEY}` },
});
console.log(await response.json());2
3
4
import os
import requests
response = requests.get(
"https://api.semalink.africa/v1/account",
headers={"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}"},
timeout=30,
)
print(response.json())2
3
4
5
6
7
8
9
<?php
$ch = curl_init('https://api.semalink.africa/v1/account');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('SEMALINK_API_KEY')],
]);
print_r(json_decode(curl_exec($ch), true));2
3
4
5
6
7
{
"object": "account",
"livemode": false,
"organisation": {
"id": "org_8c1f2a3b4d5e4f60a1b2c3d4e5f60718",
"name": "Greenhill Academy",
"country": "KE",
"status": "pending"
},
"key": {
"id": "key_2b7e151628ae4d2a9f1c3b5d7e9f0a1c",
"label": "Laptop",
"mode": "test",
"scopes": ["balance:read", "sender_ids:read", "pricing:read", "messages:send", "messages:read", "webhooks:manage"],
"prefix": "sk_test_4f9a1c2e",
"allowed_ips": [],
"expires_at": null
},
"readiness": {
"account_active": false,
"sender_id_approved": false,
"balance_ok": true,
"sending_enabled": true
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
livemode: false means you're in the sandbox. readiness is about live sending: when all four are true, live keys can send. None of it stops you in the sandbox.
Send your first message
Send to +254700000001. It's a sandbox magic number that is always delivered after 2 seconds. Use SANDBOX as the sender ID: every account has it in the sandbox.
curl https://api.semalink.africa/v1/messages \
-H "Authorization: Bearer $SEMALINK_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"to": "+254700000001",
"from": "SANDBOX",
"text": "Hello from the SemaLink sandbox!"
}'2
3
4
5
6
7
8
9
const response = await fetch('https://api.semalink.africa/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SEMALINK_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(),
},
body: JSON.stringify({
to: '+254700000001',
from: 'SANDBOX',
text: 'Hello from the SemaLink sandbox!',
}),
});
const message = await response.json();
console.log(response.status, message.id, message.status);2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import os
import uuid
import requests
response = requests.post(
"https://api.semalink.africa/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"to": "+254700000001",
"from": "SANDBOX",
"text": "Hello from the SemaLink sandbox!",
},
timeout=30,
)
message = response.json()
print(response.status_code, message["id"], message["status"])2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
$ch = curl_init('https://api.semalink.africa/v1/messages');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SEMALINK_API_KEY'),
'Content-Type: application/json',
'Idempotency-Key: ' . bin2hex(random_bytes(16)),
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '+254700000001',
'from' => 'SANDBOX',
'text' => 'Hello from the SemaLink sandbox!',
]),
]);
$message = json_decode(curl_exec($ch), true);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), ' ', $message['id'], ' ', $message['status'], PHP_EOL;2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
You get 202 Accepted and the message:
{
"id": "msg_9a4c2e7b1d3f4a5c8e6b0d2f4a6c8e1b",
"object": "message",
"livemode": false,
"to": "+254700000001",
"from": "SANDBOX",
"text": "Hello from the SemaLink sandbox!",
"type": "service",
"status": "queued",
"network": "safaricom",
"parts": 1,
"encoding": "gsm7",
"cost": { "amount": 80, "currency": "KES", "display": "KES 0.80" },
"reference": null,
"batch": null,
"send_at": null,
"created_at": "2026-12-02T07:15:22.000Z",
"sent_at": null,
"delivered_at": null,
"failure": null,
"refunded": false
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
202 means SemaLink accepted the message and it's on its way. The cost is shown as it would be live; in the sandbox it comes off a virtual balance, never your money.
Check its status
A couple of seconds later, fetch the message by its ID:
curl https://api.semalink.africa/v1/messages/msg_9a4c2e7b1d3f4a5c8e6b0d2f4a6c8e1b \
-H "Authorization: Bearer $SEMALINK_API_KEY"2
const id = 'msg_9a4c2e7b1d3f4a5c8e6b0d2f4a6c8e1b';
const response = await fetch(`https://api.semalink.africa/v1/messages/${id}`, {
headers: { Authorization: `Bearer ${process.env.SEMALINK_API_KEY}` },
});
const message = await response.json();
console.log(message.status, message.status_history);2
3
4
5
6
import os
import requests
message_id = "msg_9a4c2e7b1d3f4a5c8e6b0d2f4a6c8e1b"
response = requests.get(
f"https://api.semalink.africa/v1/messages/{message_id}",
headers={"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}"},
timeout=30,
)
message = response.json()
print(message["status"], message["status_history"])2
3
4
5
6
7
8
9
10
11
<?php
$id = 'msg_9a4c2e7b1d3f4a5c8e6b0d2f4a6c8e1b';
$ch = curl_init("https://api.semalink.africa/v1/messages/{$id}");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('SEMALINK_API_KEY')],
]);
$message = json_decode(curl_exec($ch), true);
echo $message['status'], PHP_EOL;2
3
4
5
6
7
8
9
{
"id": "msg_9a4c2e7b1d3f4a5c8e6b0d2f4a6c8e1b",
"object": "message",
"livemode": false,
"status": "delivered",
"sent_at": "2026-12-02T07:15:22.000Z",
"delivered_at": "2026-12-02T07:15:24.000Z",
"status_history": [
{ "status": "queued", "at": "2026-12-02T07:15:22.000Z" },
{ "status": "sent", "at": "2026-12-02T07:15:22.000Z" },
{ "status": "delivered", "at": "2026-12-02T07:15:24.000Z" }
]
}2
3
4
5
6
7
8
9
10
11
12
13
The response above is shortened; the full message comes back. Try +254700000002 next to see a failed message, and read Message statuses for what each status means.
Get updates by webhook
Asking for a status works, but your system shouldn't have to keep asking. Add a webhook and SemaLink tells you the moment a message is sent, delivered or failed.
- In the dashboard, open Developer, then Webhooks, then Add endpoint. Choose Test mode: test endpoints get the sandbox's events, and only those.
- Enter your HTTPS address and pick
message.deliveredandmessage.failed. - Copy the signing secret (
whsec_...).
For a first look without writing a server, use a public request inspector (an HTTPS address) as the endpoint. Send another message and the event arrives within seconds:
{
"id": "evt_9d8c7b6a5f4e4d3c2b1a0f9e8d7c6b5a",
"object": "event",
"type": "message.delivered",
"livemode": false,
"created_at": "2026-12-02T07:16:04.000Z",
"data": {
"object": {
"id": "msg_4c0a7d3b2e5f4a6b9c8d7e6f5a4b3c2d",
"object": "message",
"livemode": false,
"to": "+254700000001",
"status": "delivered"
}
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
The event above is shortened: data.object is the whole message.
Before you rely on webhooks, verify every signature. The webhooks guide has the code.
Go live
When your integration works in the sandbox, going live is a key change, not a code change:
- Your business is verified and your account is active. Live keys can only be made then.
- You have an approved sender ID, such as
GREENHILL. Approval usually takes 4 to 5 days. - You've topped up your balance with M-Pesa.
- You create a live key (
sk_live_...) and put it where the test key was.
GET /v1/account with the live key shows all four readiness checks as true when you're ready.
Then send from your own sender ID. Each SMS in Kenya costs KES 0.80 on Safaricom, Airtel and Telkom. Work through the going-live checklist first.