DevelopersSend your first iMessage

Send your first iMessage from code.

Find your line, send one message with an idempotency key, and follow it from 202 to delivered. In TypeScript, curl or Python, all copied from the docs.

Recipe 018 min readDevelopers

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_KEY the moment you see it. It starts with isnap_live_ or isnap_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 active status 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.

list-lines.ts
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)
}
From docs.isnap.ai/quickstart#make-a-first-call

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/sdk
From docs.isnap.ai/sdk/overview

With 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.

send-message.ts
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
}
From docs.isnap.ai/quickstart#send-a-message
  • to is 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.
  • body holds up to 5,000 UTF-16 code units. A message can also carry attachments (the device sends the first one) and up to 20 metadata keys, 8,192 bytes in all, which come back on the message’s events. Put your own record id there.
  • channel accepts only auto. 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:

202-accepted.json
{
  "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"
}
The response to the send above. From docs.isnap.ai/quickstart#send-a-message
  • status is queued when the message waits for the line’s device, or scheduled when iSnap is holding it.
  • scheduled_for and schedule_reason say when a held message will go, and why.
  • service stays null until the device sends. Then it reads what the device used, usually iMessage or SMS.
  • trace_id and request_id come 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.

LimitDefault per line
New contacts50 per 24 hours
Known contacts200 per 24 hours
All messages600 per 24 hours
Per hour / per minute60 / 5
First messages to new contactsAbout 5 minutes apart: at most 12 an hour
Quiet hoursSends 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:

get-message.ts
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)
From docs.isnap.ai/quickstart#read-its-status
StatusWhat it means
queuedAccepted, waiting for the line’s device.
scheduledHeld by iSnap: a limit, the spacing or quiet hours.
sentThe device sent it.
deliveredApple reported it delivered. iMessage only.
readRead, when the contact shares read receipts. iMessage only.
failedIt did not go. error_code says why.
cancelledYou 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:

  1. Retry a 429 after the Retry-After seconds.
  2. Retry a 500 or a 503 up to two times, with backoff.
  3. Never retry another 4xx. Fix the request instead.
  4. 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.

Put a real iPhone
to work.

Start free with no credit card. Rent a line, or bring your own iPhone.