Connect your AI agent to iMessage.
Receive a message, run your agent, and reply in the same iMessage conversation. Your application supplies the model and tools; YapBlue connects the messages.
Base URL · https://yapblue.com/v1AI agent quickstart
Give people a way to text your assistant from iMessage. YapBlue provides assigned messaging numbers, an HTTP API, media, and signed events. Your backend supplies the model, conversation memory, tool access, and scheduling.
- Connect an assigned number. Apply for access, complete the approved account setup, and create a number-scoped API key after billing and number activation. Check line readiness before sending.
- Receive a message. Subscribe to
message.receivedat your HTTPS endpoint. Verify the signature, durably save the event using its uniqueid, and acknowledge it before running the model. - Run your agent. A background job loads the conversation and calls your own model and tools. For a one-to-one phone-number conversation, the event's
lineidentifies your assigned number anddata.from_numberidentifies the person texting it. Keep memory scoped to the workspace, assigned line, and conversation. Group conversations need their own conversation routing. - Send and track the reply. Save the chosen reply and intended outbound payload before sending. Call
POST /v1/messageswith a stable idempotency key for that reply. Subscribe tomessage.statusto track delivery separately from acceptance.
curl 'https://yapblue.com/v1/messages' \
-H "Authorization: Bearer $YAPBLUE_API_KEY" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: agent-reply-EVENT_ID-001' \
-d '{
"from_number": "+15555550100",
"to": "+15555550101",
"text": "I found the answer in your project notes. Here is the summary."
}'Replace the fictional numbers with your assigned line and an authorized participant. Replace EVENT_ID with the verified incoming event ID and persist a distinct key for each intended reply. Use the API schema for complete message and group-conversation fields.
Make the conversation reliable
- Trigger agent work only for the incoming event types you handle. Delivery updates and webhook tests must not create reply loops.
- Deduplicate incoming events before model or tool execution. If processing retries, load the saved outgoing reply instead of generating different text under the same idempotency key.
- On a send timeout, retain the exact payload and key. Inspect the request and retry consistently; an accepted request is not proof of delivery.
- Keep credentials and tool authorization on your server. Incoming messages are user input; apply your own permissions and approval rules before the agent performs actions.
- Opted-in reminders and follow-ups use your scheduler and saved conversation state. Sending still requires an online, ready messaging line.
Use the API quickstart below for your first send, then connect your existing agent backend through the signed webhook flow.
Quickstart
You need an assigned, verified number and a number-scoped API key. Apply for access first. After approval, complete your account invitation and monthly payment setup. Number readiness and commercial terms are confirmed before activation.
1. Check your available lines
Keep your API key in a server-side environment variable named YAPBLUE_API_KEY. Never expose it in browser code.
curl 'https://yapblue.com/v1/lines' \
-H "Authorization: Bearer $YAPBLUE_API_KEY"The response contains data with each permitted line's from_number, api_reachable, bridge_connected, and sending_enabled fields. A reachable API alone does not prove sending readiness.
2. Send a text message
curl 'https://yapblue.com/v1/messages' \
-H "Authorization: Bearer $YAPBLUE_API_KEY" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: welcome-message-001' \
-d '{
"from_number": "+15555550100",
"to": "+15555550101",
"text": "Hello from our team!"
}'Use a new idempotency key for each new intended message. Retain that key, the payload, and the returned message ID. Reuse the original key only for an identical retry.
3. Follow the message
curl 'https://yapblue.com/v1/messages/MESSAGE_ID' \
-H "Authorization: Bearer $YAPBLUE_API_KEY"A 202 response is acceptance, not delivery. Poll this endpoint or subscribe to message.status events. See the interactive API reference for complete request and response schemas.
Authentication & API keys
Every /v1 endpoint requires Authorization: Bearer YOUR_API_KEY. Keys belong to a customer account and grant access only to selected assigned numbers. Dashboard sessions are separate from API authentication.
- Create and revoke keys in the API keys dashboard. Save the secret when it is displayed.
- Email verification and assigned capacity are required before new customer API access. Follow the setup status shown in your workspace.
- Store keys in server-side secret storage. Do not include credentials in URLs, source control, screenshots, or public logs.
- Revoking a key also disables webhooks created with that key. Plan credential replacement accordingly.
Public documentation and /healthz do not need a key. Process health does not establish the health of an individual messaging line.
Numbers & readiness
A line becomes usable after carrier activation, Apple registration, worker setup, and sender verification. An inventory record or requested number does not activate those services.
Use GET /v1/lines to inspect permitted lines and GET /v1/capabilities for actual feature availability. To query a specific line, URL-encode its number:
curl --get 'https://yapblue.com/v1/capabilities' \
-H "Authorization: Bearer $YAPBLUE_API_KEY" \
--data-urlencode 'from_number=+15555550100'from_number selects an authorized configured line; it cannot force Apple to send from an arbitrary identity. Rich messaging depends on the capabilities of that worker. Unsupported features do not automatically fall back to ordinary messages or SMS.
Delivery, idempotency & uncertain outcomes
| Observation | Meaning |
|---|---|
202 Accepted | The request was accepted. It is not a delivery receipt. |
| Delivered event/status | The underlying messaging system reported delivery. |
| Read event/status | A read receipt was observed. Recipient settings affect availability. |
| Timeout or unavailable worker | The result may be uncertain. Preserve the request payload and idempotency key. |
On a timeout or retryable 503, repeat the identical request with the same Idempotency-Key. A changed payload with an already-used key returns 409. Creating a new key after an uncertain send can create another intended operation.
When an error provides a request ID, inspect GET /v1/requests/{request_id}. Offline client mutations are not promised automatic replay after a long outage. The service does not guarantee end-to-end exactly-once delivery.
Receive messages & consume events
Use GET /v1/inbox for received messages or GET /v1/events for the broader event feed. Both are scoped to your API key and support after, limit (1–100), and optional from_number.
curl --get 'https://yapblue.com/v1/events' \
-H "Authorization: Bearer $YAPBLUE_API_KEY" \
--data-urlencode 'from_number=+15555550100' \
--data-urlencode 'after=0' \
--data-urlencode 'limit=50'Each response contains data and next_cursor. Process and persist the page before saving its cursor. Use that cursor as the next request's after value. Deduplicate by event ID, and keep separate progress for streams with different filters.
Inspect GET /v1/events/status for per-line collection checkpoints and errors. An empty page does not prove the worker is online. Incoming typing has additional isolation requirements; rely on reported capabilities.
Subscribe to signed webhooks
Webhooks send events to your public HTTPS endpoint. Select the event types and permitted numbers explicitly. The create response includes a signing_secret; store it securely for signature verification.
curl 'https://yapblue.com/v1/webhooks' \
-H "Authorization: Bearer $YAPBLUE_API_KEY" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: primary-webhook-001' \
-d '{
"url": "https://example.com/webhooks/imessage",
"events": ["message.received", "message.status"],
"numbers": ["+15555550100"]
}'Supported subscription types are message.received, reaction.received, message.status, operation.status, typing.changed, and webhook.test. Feature availability still depends on the line.
- Verify signatures on the raw body before parsing or processing the event.
- Persist the event with a unique event-ID constraint before returning a
2xxacknowledgment. Do slower work asynchronously. - Duplicate delivery is possible. Use the event ID for deduplication; do not rely on the delivery attempt being unique.
- Inspect
GET /v1/webhooks/{id}/deliveriesfor callback delivery results. These are separate from message delivery status. POST /v1/webhooks/{id}/testrequires an idempotency key and creates a synthetic event. Replay usesPOST /v1/webhooks/{id}/replaywith{"event_id":"EVENT_ID"}.
Connections, 408/429 responses, and server errors may be retried, up to eight attempts. An independent cloud scheduler processes queued retries every minute even when Mac agents are offline. Scheduling is best effort; it does not make an offline messaging line able to send or provide an uptime guarantee.
Verify webhook signatures
Read X-iMessage-Timestamp and X-iMessage-Signature. The signature is v1= followed by a hex HMAC-SHA256 digest of timestamp + "." + raw_body, using the subscription's signing secret. Compare in constant time and reject timestamps outside your tolerance.
import hashlib
import hmac
import time
def verify_signature(raw, timestamp, received_signature, secret):
if not secret or not timestamp or not received_signature:
return False
try:
when = int(timestamp)
except (TypeError, ValueError):
return False
if abs(time.time() - when) > 300:
return False
signed = timestamp.encode() + b'.' + raw
expected = 'v1=' + hmac.new(
secret.encode(), signed, hashlib.sha256
).hexdigest()
return hmac.compare_digest(received_signature, expected)Pass the original request bytes as raw; re-serializing JSON changes the signed input. After verification, confirm the payload's id matches X-iMessage-Event-ID, then store it with a uniqueness constraint. Keep your server clock synchronized.
This function verifies the signature only. Your receiver still needs HTTPS, body limits, durable event storage, deduplication, and a background processor. See the API reference for subscription and delivery endpoints.
Send media
Media uploads belong to the selected sending number. Use the returned media record's ID as media_id in a message from that same line.
Raw files up to 4 MiB
curl 'https://yapblue.com/v1/media?from_number=%2B15555550100' \
-H "Authorization: Bearer $YAPBLUE_API_KEY" \
-H 'Content-Type: image/png' \
-H 'X-Filename: preview.png' \
-H 'Idempotency-Key: preview-upload-001' \
--data-binary @preview.pngChunked files up to 25 MiB
POST /v1/uploadswith an idempotency key and{"from_number":"+15555550100","filename":"clip.mp4","content_type":"video/mp4"}. Save the returned uploadid.- Split the file into chunks of at most 1,048,576 bytes. Send raw bytes to
PUT /v1/uploads/{id}/chunks/{index}, starting at index 0. Identical chunk retries are safe; changed bytes return a conflict. - Finish with
POST /v1/uploads/{id}/completeand{"parts":5}for five chunks. All indices from 0 to 4 must be present. Repeat completion safely after a timeout. - Use the completed media ID in
POST /v1/messageswith the same sender and a new message idempotency key.
Every step needs your bearer key. Upload sessions are subject to 24-hour cleanup; do not rely on retaining incomplete uploads beyond that window. The complete upload is limited to 25 MiB.
Download owned media through GET /v1/media/{id}/content and received attachments through GET /v1/attachments/{id}/content. Files reside on the Mac worker, so content access requires it to be online. Native voice messages are distinct from ordinary audio attachments.
Handle errors deliberately
| Status | Next step |
|---|---|
| 401 | Check the bearer key. It may be missing, invalid, or revoked. |
| 403 | Check account and number permissions. Do not retry with another customer's credential. |
| 404 | The resource may not exist or may not be accessible to this key. |
| 409 | Inspect the error detail. Common causes include changed idempotent payloads or conflicting upload chunks. Do not blindly issue a new send. |
| 413 | Reduce the request size or use chunked upload within the overall limit. |
| 422 | Correct validation errors or check whether the requested feature is supported. |
| 429 | Respect any returned retry guidance and back off. Review subscription or operation limits. |
| 503 / timeout | Check line readiness. For uncertain writes, retry the identical request with its original idempotency key. |
Preserve the error response and any request ID for investigation, without logging authorization headers, signing secrets, or private message content unnecessarily.