This recipe sends one message from one of your lines to one phone number, then reads what happened to it. It is the call every other recipe builds on. An AI agent’s reply, a CRM’s follow-up and a sales sequence’s next touch are all the same request: POST /v1/messages.
Every sample below is copied from docs.isnap.ai and names the page it came from. Pick your language once and every code block on these pages follows: the TypeScript SDK, curl, or Python with the requests library.
What you need
- An API key. You create keys in the dashboard at platform.isnap.ai. A key is shown once, so store it as
ISNAP_API_KEYthe moment you see it. It starts withisnap_live_orisnap_test_, never expires, and stops working on the next request after you revoke it. - An active line. A line is what sends and receives messages: a real iPhone line you rent from the Line Marketplace, or an iPhone you own and connect yourself (recipe 05). Only a line in the
activestatus sends. - A server. The API answers no cross-origin requests from other sites, and a key in a browser is a key anyone can read. Call iSnap from your backend.
- Your own phone number, to receive the test. The next paragraph explains why.
A test key is not a sandbox. iSnap has no test environment. An isnap_test_ key works on the same account, the same lines and the same billing as a live key, and its messages reach real phones. Use the two prefixes to tell your environments apart, not to send for free. While you build, text yourself.
1. Find your line
Every send names the line it goes out from, by its id: line_ followed by 25 characters. GET /v1/lines/my lists your active and reserved lines.
import { ISnapClient } from '@isnap/sdk'
const client = new ISnapClient({ apiKey: process.env.ISNAP_API_KEY ?? '', maxRetries: 2 })
const { lines } = await client.lines.listMine()
for (const line of lines) {
console.log(line.id, line.billing_tier, line.status, line.inbound_only)
}curl -sS https://api.isnap.ai/v1/lines/my \
-H "Authorization: Bearer $ISNAP_API_KEY"import os
import requests
response = requests.get(
"https://api.isnap.ai/v1/lines/my",
headers={"Authorization": f"Bearer {os.environ['ISNAP_API_KEY']}"},
timeout=30,
)
body = response.json()
if response.status_code != 200:
raise SystemExit(f"{body['error']['status']} {body['error']['code']}: {body['error']['message']}")
for line in body["data"]["lines"]:
print(line["id"], line["billing_tier"], line["status"], line["inbound_only"])Each line comes back with a billing_tier (rental_iphone for a rented iPhone line), a status and an inbound_only flag. An inbound-only line can message a contact only after that contact wrote to it first, so pick a two-way line for this recipe and copy its id.
2. Install the SDK, or don’t
The TypeScript SDK, @isnap/sdk, runs on Node.js 20 or later and on Bun 1.2 or later. It is ESM only, runs on servers only, has no runtime dependencies and is MIT licensed.
npm install @isnap/sdkWith Bun, pnpm or Yarn it is bun add @isnap/sdk, pnpm add @isnap/sdk or yarn add @isnap/sdk. The SDK gives you typed methods, typed errors, automatic retries on a connection failure, a timeout, a 500, a 503 and some 429s, an Idempotency-Key on every write, and iterators over paged lists. It is the only SDK: from any other language you call the same REST API over HTTPS, and the docs show Python with requests (pip install requests).
3. Send the message
A send takes three fields: line_id, to and body. Replace the line id with yours and the number with your own.
import { randomUUID } from 'node:crypto'
import { APIError, ISnapClient } from '@isnap/sdk'
const client = new ISnapClient({ apiKey: process.env.ISNAP_API_KEY ?? '', maxRetries: 2 })
const idempotencyKey = randomUUID() // Store it with your record of the message: reuse it to retry.
try {
const message = await client.messages.send(
{
line_id: 'line_8Xk2mQ4vTn7Bw9Rz3Lc6Yp1Hd',
to: '+14155550123',
body: 'Hello from iSnap'
},
{ idempotencyKey }
)
console.log(message.id, message.status, message.scheduled_for, message.schedule_reason)
} catch (err) {
if (!(err instanceof APIError)) throw err
console.error(err.status, err.code, err.message, `trace_id=${err.traceId}`, `request_id=${err.requestId}`)
process.exitCode = 1
}IDEMPOTENCY_KEY=$(uuidgen) # Store it with your record of the message: reuse it to retry.
curl -sS https://api.isnap.ai/v1/messages \
-H "Authorization: Bearer $ISNAP_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-d '{
"line_id": "line_8Xk2mQ4vTn7Bw9Rz3Lc6Yp1Hd",
"to": "+14155550123",
"body": "Hello from iSnap"
}'import os
import time
import uuid
import requests
idempotency_key = str(uuid.uuid4()) # Store it with your record of the message: reuse it to retry.
for attempt in range(3):
try:
response = requests.post(
"https://api.isnap.ai/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['ISNAP_API_KEY']}",
"Idempotency-Key": idempotency_key,
},
json={
"line_id": "line_8Xk2mQ4vTn7Bw9Rz3Lc6Yp1Hd",
"to": "+14155550123",
"body": "Hello from iSnap",
},
timeout=30,
)
break
except (requests.ConnectionError, requests.Timeout):
# No response: iSnap may have accepted the message. Retry with the same key, up to 2 times.
if attempt == 2:
raise
time.sleep(2**attempt)
body = response.json()
if response.status_code != 202:
error = body["error"]
raise SystemExit(
f"{error['status']} {error['code']}: {error['message']} "
f"(trace_id={body['trace_id']}, request_id={body['request_id']})"
)
message = body["data"]
print(message["id"], message["status"], message["scheduled_for"], message["schedule_reason"])tois one phone number in E.164 format, such as+14155550123. A number without a country code is read as a US number. iSnap sends to phone numbers only: not to email addresses, and not to groups.bodyholds up to 5,000 UTF-16 code units. A message can also carry attachments (the device sends the first one) and up to 20metadatakeys, 8,192 bytes in all, which come back on the message’s events. Put your own record id there.channelaccepts onlyauto. The line’s device picks iMessage or SMS when it sends; recipe 04 shows how to know in advance.
Why the idempotency key matters
A network error can hide a success: the request reached iSnap and the response never reached you. Retry without a key and your contact gets the message twice. The sample makes a key, sends it in the Idempotency-Key header, and tells you to store it with your own record of the message. A repeat send with the same key returns the same message for at least 72 hours instead of sending a second one. The SDK adds a key to every write on its own; passing yours lets you retry safely from your own job queue too.
4. Read the 202
A successful send answers 202 Accepted. It means iSnap has the message. It never means the message was sent. The body is the message inside the usual envelope:
{
"success": true,
"data": {
"id": "msg_3Lc6Yp1Hd8Xk2mQ4vTn7Bw9Rz",
"line_id": "line_8Xk2mQ4vTn7Bw9Rz3Lc6Yp1Hd",
"direction": "outbound",
"to": "+14155550123",
"from": "+14155550124",
"body": "Hello from iSnap",
"status": "queued",
"service": null,
"queued_at": "2026-10-08T14:22:57.392Z",
"scheduled_for": "2026-10-08T14:22:57.392Z",
"schedule_reason": null
},
"trace_id": "0af7651916cd43dd8448eb211c80319c",
"request_id": "req_4Tn7Bw9Rz3Lc6Yp1Hd8Xk2mQv"
}statusisqueuedwhen the message waits for the line’s device, orscheduledwhen iSnap is holding it.scheduled_forandschedule_reasonsay when a held message will go, and why.servicestaysnulluntil the device sends. Then it reads what the device used, usuallyiMessageorSMS.trace_idandrequest_idcome with every response. Log them: they are what support asks for when something looks wrong.
Why a message waits
Each line paces itself, to protect the line and the people it texts. These are the defaults on an iMessage line. A contact is known when they wrote to the line in the last 30 days; everyone else is new, and sending to someone does not make them known.
| Limit | Default per line |
|---|---|
| New contacts | 50 per 24 hours |
| Known contacts | 200 per 24 hours |
| All messages | 600 per 24 hours |
| Per hour / per minute | 60 / 5 |
| First messages to new contacts | About 5 minutes apart: at most 12 an hour |
| Quiet hours | Sends 08:00 to 20:59 in the recipient’s local time |
The windows roll; nothing resets at midnight. A message over a limit or outside those hours is held, not refused, and goes out when it can. A held message that still cannot go after 48 hours fails. A reply to someone who wrote to the line in the last 24 hours takes the reply lane, which skips the hourly and daily caps and quiet hours. The defaults are iSnap settings and can change, so read the ones in force on your line with GET /v1/lines/{id}/quota. The sending limits guide has every rule.
5. Follow its status
Read the message back by its id:
import { ISnapClient } from '@isnap/sdk'
const client = new ISnapClient({ apiKey: process.env.ISNAP_API_KEY ?? '', maxRetries: 2 })
const message = await client.messages.get('msg_3Lc6Yp1Hd8Xk2mQ4vTn7Bw9Rz')
console.log(message.status, message.service, message.sent_at, message.delivered_at, message.error_code)curl -sS https://api.isnap.ai/v1/messages/msg_3Lc6Yp1Hd8Xk2mQ4vTn7Bw9Rz \
-H "Authorization: Bearer $ISNAP_API_KEY"| Status | What it means |
|---|---|
queued | Accepted, waiting for the line’s device. |
scheduled | Held by iSnap: a limit, the spacing or quiet hours. |
sent | The device sent it. |
delivered | Apple reported it delivered. iMessage only. |
read | Read, when the contact shares read receipts. iMessage only. |
failed | It did not go. error_code says why. |
cancelled | You cancelled it before the device took it. |
Two honest limits. Over SMS, iSnap reports no delivery and no read, so an SMS message stops at sent. And read appears only when the contact has read receipts turned on. Polling is fine for a first test; in production, subscribe to the message.* events and let iSnap tell you. That is recipe 02.
Changed your mind? DELETE /v1/messages/{id} cancels a queued or held message the device has not taken yet. After that point the API answers 409 too_late_to_cancel.
When a call fails
Errors share one envelope: success: false, and an error object with status, code and message, plus retry_after when a limit is the cause. The docs’ retry rule fits in four lines:
- Retry a
429after theRetry-Afterseconds. - Retry a
500or a503up to two times, with backoff. - Never retry another 4xx. Fix the request instead.
- Retry a write only with its idempotency key.
The API also limits requests: 100 per rolling 60 seconds per network address and, on top of that, 60 calls per 60 seconds that send or list messages. That second limit bounds how many messages one server sends per minute across all your lines. Every response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. In TypeScript the SDK throws typed errors: APIError, and kinds such as AuthenticationError, RateLimitError, QuotaExceededError and ConflictError. The sample catches APIError and prints its trace and request ids. The errors and rate limits page lists every code.
What you have now
One message, sent from a real iPhone line, with a key you can retry on and a status you can read. The same request carries your agent’s answers, your CRM’s follow-ups and your team’s replies. Next, stop polling: let iSnap call you when the message is delivered and when your contact writes back.
Next recipe: Receive replies with webhooks. Or go back to all recipes and the API at a glance.