Wiring up an iMessage API takes an afternoon. The part that actually eats your week is the backend for an iMessage AI agent: the database, hosting, file storage, scheduled jobs, and email inbox sitting behind the webhook.
If you want the short version of the architecture: an iMessage AI agent needs Postgres for user state and message history, public web hosting for generated pages and link previews, object storage for attachments, a cron runner for proactive texts, an email inbox for forwarded confirmations, and optionally Redis for debouncing rapid-fire texts. You can stitch that together yourself with Neon or Supabase, Vercel or Fly, S3 or R2, a cron service, and an email API—or let your coding agent provision the whole stack through Cohesivity.
In practice, every iMessage agent ends up with the same five layers:
Most tutorials stop at layer 3. Layers 4 and 5 are where the real backend work lives.
Because Apple doesn't expose an official iMessage API, you route through a third-party bridge. The main options right now:
| Provider | What it gives you | Worth knowing |
|---|---|---|
| Linq | iMessage, RCS, and SMS in one API | Automatically falls back from iMessage to RCS to SMS |
| Photon | Open-source SDK for iMessage, WhatsApp, Telegram, and more | Works self-hosted or via their cloud |
| Sendblue | iMessage API supporting links, images, and contact cards | Commonly used for high-volume outbound |
| Blooio | iMessage API with transparent public pricing | Ships with a hosted MCP server |
| BlueBubbles | Self-hosted iMessage bridge | Requires running your own Mac |
From a backend perspective, they all behave the same way: your server gets an HTTP webhook containing the sender and message body, and you call their API to reply.
Once you have a messaging provider, you need Postgres, public hosting, object storage, scheduled jobs, an inbox, and maybe Redis. There are two realistic ways to set that up.
Stitching together separate services. The standard DIY stack is Postgres on Neon or Supabase, hosting on Vercel or Fly, attachments on S3 or R2, plus a separate cron service and an email API. Each piece is solid on its own, though you do end up juggling five accounts, five sets of API keys, and five dashboards before you've shipped much.
Provisioning it from your coding agent. Cohesivity is built around this workflow. It exposes Postgres, hosting, object storage, Redis, cron, and an email inbox through a single HTTP API and an MCP server, so Claude Code, Cursor, or Codex can spin up the entire backend directly. You don't need an account to test it-the first tenant is free for 72 hours, and you only claim it if you decide to keep it.
A typical prompt looks like this:
Build the backend for my iMessage agent: a webhook endpoint for Linq,
a Postgres schema for users, messages, reminders and pages, a public
route that serves pages by slug, and a job that sends due reminders
every minute. Build and host it using cohesivity.ai.
The coding agent provisions the database and hosting, deploys the webhook server, and hands back the URL to drop into Linq or whichever provider you picked.
The one hard rule for an iMessage webhook server is to respond fast and process asynchronously. Messaging providers retry slow webhooks, and the first thing that broke when I built one was a slow LLM call triggering retries and double-texting the user.
app.post("/webhooks/imessage", async (req, res) => {
const { message_id, from, text } = req.body;
// 1. Acknowledge immediately so the provider does not retry.
res.sendStatus(200);
// 2. Deduplicate messages we have already seen.
const fresh = await db.query(
"insert into inbound (message_id) values ($1) on conflict do nothing returning 1",
[message_id]
);
if (fresh.rowCount === 0) return;
// 3. Push the actual LLM work to a background job.
await jobs.enqueue("handle_message", { from, text });
});
That inbound deduplication table is usually the first thing that forces you to add a real database.
An SMS or iMessage thread gives your backend no state on its own. Postgres handles user profiles, full message logs, scheduled reminders, and generated pages in one place:
create table users (
phone text primary key,
name text,
timezone text,
created_at timestamptz default now()
);
create table messages (
id bigserial primary key,
phone text references users(phone),
role text, -- 'user' or 'agent'
body text,
created_at timestamptz default now()
);
create table reminders (
id bigserial primary key,
phone text references users(phone),
due_at timestamptz,
body text,
sent boolean default false
);
create table pages (
slug text primary key, -- long and unguessable
phone text references users(phone),
title text,
html text,
created_at timestamptz default now()
);
I always store every inbound and outbound message in Postgres even when I only pass the last 20 messages to the LLM, because you'll want the full log the first time a user asks why the agent contradicted itself last week. Keying tables on the phone number is fine to start, as long as you keep it isolated in one column so migrating to an internal user ID later doesn't hurt.
If users tend to send five short texts in a row instead of one paragraph, add Redis to debounce incoming messages for a few seconds and handle rate limiting.
Long structured output—like a weekend itinerary, an apartment comparison, or a weekly digest—is painful to read inside a narrow chat bubble. Having the backend host small HTML pages solves this cleanly: the agent generates the HTML, saves it to the pages table under a long random slug, and texts the URL by itself.
An iMessage link preview is built from the page's Open Graph tags, so include og:title, og:description, and og:image in the HTML. According to Apple's rich link reference, iMessage falls back to the page title and largest image if those tags are missing.
Keep three practical details in mind when hosting agent-generated pages:
When a user texts back "push dinner to 8pm," the agent just updates the HTML row in Postgres. The same link immediately reflects the change without cluttering the thread with a new URL.
To let an iMessage agent text first—like sending a 7am reminder or a flight update—run a cron job every minute that checks the reminders table:
select id, phone, body from reminders
where sent = false and due_at <= now()
order by due_at limit 50;
Update sent = true in the same database transaction as the outbound send (or claim the row with FOR UPDATE SKIP LOCKED), otherwise a crash mid-batch will double-text users.
Users will eventually text photos, PDFs, and voice notes, and expect images or tickets back. Attachment URLs from messaging providers usually expire quickly, so download inbound files into your own object storage bucket right away and store the object key alongside the row in messages.
An agent-owned email address is worth adding once users start forwarding booking confirmations, receipts, or sign-in links. Treat inbound emails the same way you treat inbound texts: persist them to Postgres, then hand them to the agent loop.
If you're building an iMessage AI agent from scratch, this order avoids over-engineering early:
200 fast.users and messages tables.reminders table and a one-minute cron job.
Getting step 3 working is usually the turning point—once the agent can reply to "plan my weekend" with a clean hosted page instead of a wall of text, the whole experience clicks.
If you're building an iMessage agent right now, what does your backend stack look like and which piece has been the most annoying?