Sandbox
The sandbox is SemaLink's test mode. It runs inside the real API, with the same checks, so code that works in the sandbox works live. Nothing reaches a phone and nothing costs money.
You're in the sandbox whenever you use a test key (sk_test_...). Every object you get back says "livemode": false.
How it differs from live
| Sandbox (test key) | Live (live key) | |
|---|---|---|
| Phones | Simulated. Nothing is sent. | Real phones on Safaricom, Airtel and Telkom |
| Money | A virtual balance of KES 10,000, reset every day | Your balance, topped up with M-Pesa |
| Sender IDs | Any sender ID your organisation has, in any status, or SANDBOX | Approved sender IDs only |
| Delivery reports | Simulated, on the timings below | From the networks |
| Webhooks | Sent to test endpoints only, with livemode: false | Sent to live endpoints only |
| Rate limit | 5 requests a second per key, 10 per organisation | 20 a second per key (bursts to 40), 40 per organisation (bursts to 80) |
| Daily limit | 500 sandbox messages a day per organisation | Your account's daily limit |
| Data kept | 30 days (messages, batches, events) | Your full history |
| Account | Works from sign-up, before verification | Needs an active, verified account |
Sandbox messages are kept apart from live ones. They never appear in your live message lists, analytics, invoices or balance, and a test key only ever sees sandbox messages.
The same checks as live
The sandbox checks a send with the same code as live: message length and characters, phone numbers and opt-outs, sending hours, the daily limit, scopes, idempotency keys and required fields. Only three things differ: the money (a virtual balance), the sender ID (any of yours, or SANDBOX) and your account's verification (not needed). If a request fails in the sandbox it will fail live, and if it passes, it will pass live too, given an approved sender ID and enough balance.
Magic numbers
Send to these numbers to get a set outcome. Use them in tests to check how your code handles each case.
| Number | What happens | Events | Charged? |
|---|---|---|---|
+254700000001 | sent at once, delivered 2 seconds later | message.sent, message.delivered | Yes |
+254700000002 | sent, then failed 2 seconds later with absent_subscriber (the phone was off) | message.sent, message.failed | Yes, no refund, as live |
+254700000003 | failed at once with rejected_by_network: refused at hand-over, never sent | message.failed | No: refunded: true |
+254700000004 | sent, then expired after 1 hour with no_delivery_report | message.sent | Yes |
+254700000005 | sent at once, delivered 60 seconds later | message.sent, message.delivered | Yes |
+254700000006 | held for review, released after 30 seconds, then sent and delivered 2 seconds later | message.held, message.released, message.sent, message.delivered | Yes |
+254700000009 | The request answers 402 insufficient_balance | None | No |
+254700000010 | Opted out: refused at the request with opted_out and never stored | None | No |
| Any other valid number | sent at once, delivered 2 to 10 seconds later | message.sent, message.delivered | Yes |
"Charged" here means the virtual balance. Local forms work too: 0700000001 is the same number as +254700000001. A message scheduled with send_at waits as scheduled first, then plays out the same way.
Try every outcome at once
Send one batch to several magic numbers, then watch the webhooks arrive or list the messages.
curl https://api.semalink.africa/v1/batches \
-H "Authorization: Bearer $SEMALINK_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"from": "SANDBOX",
"text": "Sandbox test: which outcome am I?",
"to": ["+254700000001", "+254700000002", "+254700000003", "+254700000006", "+254700000010"],
"reference": "sandbox-outcomes"
}'2
3
4
5
6
7
8
9
10
const response = await fetch('https://api.semalink.africa/v1/batches', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SEMALINK_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(),
},
body: JSON.stringify({
from: 'SANDBOX',
text: 'Sandbox test: which outcome am I?',
to: ['+254700000001', '+254700000002', '+254700000003', '+254700000006', '+254700000010'],
reference: 'sandbox-outcomes',
}),
});
const batch = await response.json();
for (const recipient of batch.recipients) {
console.log(recipient.input, recipient.status, recipient.message ?? recipient.rejection.code);
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os
import uuid
import requests
response = requests.post(
"https://api.semalink.africa/v1/batches",
headers={
"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"from": "SANDBOX",
"text": "Sandbox test: which outcome am I?",
"to": ["+254700000001", "+254700000002", "+254700000003", "+254700000006", "+254700000010"],
"reference": "sandbox-outcomes",
},
timeout=30,
)
batch = response.json()
for recipient in batch["recipients"]:
print(recipient["input"], recipient["status"], recipient["message"] or recipient["rejection"]["code"])2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$ch = curl_init('https://api.semalink.africa/v1/batches');
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([
'from' => 'SANDBOX',
'text' => 'Sandbox test: which outcome am I?',
'to' => ['+254700000001', '+254700000002', '+254700000003', '+254700000006', '+254700000010'],
'reference' => 'sandbox-outcomes',
]),
]);
$batch = json_decode(curl_exec($ch), true);
foreach ($batch['recipients'] as $recipient) {
echo $recipient['input'], ' ', $recipient['status'], ' ', $recipient['message'] ?? $recipient['rejection']['code'], PHP_EOL;
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"id": "bat_2f6d9a1c3e5b4d7f8a0c2e4b6d8f1a3c",
"object": "batch",
"livemode": false,
"status": "sending",
"from": "SANDBOX",
"type": "service",
"text": "Sandbox test: which outcome am I?",
"reference": "sandbox-outcomes",
"send_at": null,
"created_at": "2026-12-02T07:30:00.000Z",
"completed_at": null,
"totals": {
"recipients": 5, "accepted": 4, "rejected": 1,
"scheduled": 0, "queued": 3, "held": 1, "sent": 0, "delivered": 0, "failed": 0, "expired": 0, "cancelled": 0
},
"cost": { "amount": 320, "currency": "KES", "display": "KES 3.20" },
"refunded": { "amount": 0, "currency": "KES", "display": "KES 0.00" },
"recipients": [
{ "index": 0, "input": "+254700000001", "to": "+254700000001", "status": "accepted", "message": "msg_1a2b3c4d5e6f4a7b8c9d0e1f2a3b4c5d", "rejection": null },
{ "index": 1, "input": "+254700000002", "to": "+254700000002", "status": "accepted", "message": "msg_2b3c4d5e6f7a4b8c9d0e1f2a3b4c5d6e", "rejection": null },
{ "index": 2, "input": "+254700000003", "to": "+254700000003", "status": "accepted", "message": "msg_3c4d5e6f7a8b4c9d0e1f2a3b4c5d6e7f", "rejection": null },
{ "index": 3, "input": "+254700000006", "to": "+254700000006", "status": "accepted", "message": "msg_4d5e6f7a8b9c4d0e1f2a3b4c5d6e7f8a", "rejection": null },
{
"index": 4, "input": "+254700000010", "to": "+254700000010", "status": "rejected", "message": null,
"rejection": { "code": "opted_out", "message": "This number opted out of your messages." }
}
]
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
The opted-out number was refused at the request, so it has no message. A few seconds later, GET /v1/messages/msg_2b3c... shows the absent subscriber (shortened here):
{
"id": "msg_2b3c4d5e6f7a4b8c9d0e1f2a3b4c5d6e",
"object": "message",
"livemode": false,
"to": "+254700000002",
"status": "failed",
"failure": {
"code": "absent_subscriber",
"message": "Phone off or unreachable",
"refunded": false
},
"refunded": false,
"status_history": [
{ "status": "queued", "at": "2026-12-02T07:30:00.000Z" },
{ "status": "sent", "at": "2026-12-02T07:30:00.000Z" },
{ "status": "failed", "at": "2026-12-02T07:30:02.000Z" }
]
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
The virtual balance
Each organisation's sandbox has KES 10,000 a day to spend: the day's charged sandbox messages count against it, and it is full again the next day. Sandbox messages are priced like live ones (KES 0.80 each in Kenya), so GET /v1/balance with a test key shows what is left today. To see what happens when money runs out without sending thousands of messages, send to +254700000009.
Sandbox webhooks
Webhook endpoints are either test or live. Sandbox events only go to test endpoints, and every payload says "livemode": false. Add a test endpoint in Developer, Webhooks, or with a test key through POST /v1/webhooks. Sandbox events arrive within seconds of each step. See Webhooks.
Limits
- 5 requests a second per test key, and 10 a second across all of an organisation's test keys. Over that you get
429rate_limited; see Rate limits. - 500 sandbox messages a day per organisation. After that, sends answer
daily_limit_reacheduntil the next day. - The virtual balance: KES 10,000 a day.
- Sandbox messages, batches and events are kept for 30 days.