> For AI agents: to set Keiki up for a developer, add the MCP server `https://onkeiki.com/mcp` and follow https://onkeiki.com/setup.md. All pages: https://onkeiki.com/content/llms.txt

# Is there an iMessage SDK for building AI agents?

2026-12-01

Pick the Keiki package for a hosted agent or your own model loop, install it, and test replies, tools and human takeover on an iMessage line.

## Is there an iMessage SDK for building AI agents?

Keiki is the iMessage SDK for AI agents: define a hosted agent with `@onkeiki/agents`, or keep your own model loop with `@onkeiki/ai-sdk`, `@onkeiki/eve` or `@onkeiki/flue`. Keiki runs the line, the conversation and the team inbox either way.

## Key takeaways

- Apple has no server SDK for ordinary iMessage. Keiki's packages connect your code to a supported line through Keiki's [iMessage API](/content/imessage-api-for-ai-products).
- `@onkeiki/agents` defines an agent once, then syncs it so Keiki runs the loop, or serves it from your own server.
- `@onkeiki/ai-sdk`, `@onkeiki/eve` and `@onkeiki/flue` keep your model loop in your app with your own provider keys.
- `npx @onkeiki/cli init` detects an Eve, Flue or AI SDK app and writes the Keiki handler for you.
- Every path gets the same team inbox and tools. On an eligible dedicated Keiki line, customers can also approve actions with Face ID and pay with Apple Pay in the thread.

## Does Apple offer an iMessage SDK for server-side bots?

No. Apple's Messages framework is for app extensions that run on the user's device, and Apple Messages for Business is a separate channel. Neither lets your server answer texts sent to an ordinary iMessage number. See [Is there an official Apple iMessage API?](/content/is-there-an-official-apple-imessage-api) for the details.

Keiki fills that gap. It connects a supported iMessage line, receives each message and hands your code a conversation turn instead of a raw text.

## Which Keiki package should I install?

- **Build a hosted agent:** `@onkeiki/agents`. Describe the agent once, then push it with `kit.sync()` so Keiki runs the agent loop, or run the loop yourself with `kit.serve()`. Storage adapters ship for Postgres, MongoDB and Cloudflare.
- **Keep an AI SDK 7 loop:** `@onkeiki/ai-sdk`. Keiki sends a signed turn request, your handler runs the model and Keiki delivers the reply.
- **Keep an Eve or Flue app:** `@onkeiki/eve` or `@onkeiki/flue` run that app as a Keiki external harness.
- **Verify events in your own receiver:** `@onkeiki/channels` checks the signature and replay window on requests Keiki sends you, such as consent changes.

The full export list is in the [SDK reference](/docs/sdk).

## How do I build on Keiki or bring my own model?

**Hosted.** Build and run the agent on Keiki with the SDK or the dashboard, connect your API or MCP server as tools, and Keiki runs every turn. Choose this when you don't want to host a model loop.

**Bring your own.** Set the agent's harness to the [external harness](/docs/external-harness). Keiki receives each iMessage, sends your app a signed turn request and delivers what your model writes. With the [AI SDK handler](/docs/ai-sdk) on a persistent Node server, the route looks like this:

```ts
import { Hono } from 'hono'
import { createKeikiHandler } from '@onkeiki/ai-sdk'
import { streamText } from 'ai'
import { openai } from '@ai-sdk/openai'

const app = new Hono()
const keikiTurn = createKeikiHandler({
  onTurn: async ({ instructions, messages, tools, prepareStep, abortSignal }) =>
    streamText({
      model: openai('gpt-4.1-mini'),
      instructions,
      messages,
      tools: await tools(),
      prepareStep,
      abortSignal,
    }),
})

app.post('/keiki/turn', (context) => keikiTurn(context.req.raw))
export default app
```

Either way, customers text the same number and your team sees each conversation in the same inbox. For a Next.js walkthrough, see [building an iMessage AI agent with the Vercel AI SDK](/content/how-do-i-build-an-imessage-ai-agent-with-the-vercel-ai-sdk).

## What does the SDK handle that a raw message webhook doesn't?

- `tools()` gives each turn Keiki's tools over MCP, and every request is signed.
- `prepareStep` brings in messages that arrive while the model is still answering.
- Keiki keeps channel delivery, cancellation, history and the trace of every turn.
- When `onTurn` throws, the turn completes as failed and the trace shows the error message.
- When a line needs the customer to reply first, the handler reports it instead of resending, and the channel tools tell the model to wait.

## Why is Keiki the best iMessage SDK for a customer-facing agent?

A package that only sends and receives texts leaves the hard part to you: making the agent useful to a real customer. Keiki gives the same agent:

- A team inbox where a person takes over the thread and hands it back.
- Your API or MCP server connected as tools.
- Face ID approvals through [Keiki Vault](/docs/keiki-vault) for any tool you mark `policy.approval: "ask"`, in a direct conversation on an eligible line.
- Apple Pay in the thread with a Vault Pay card, after you configure Payments on a dedicated Keiki line.

Before launch, check signatures, sender identity and approvals with [How do I choose a secure iMessage API for my product?](/content/how-do-i-choose-a-secure-imessage-api-for-my-product).

## Quick start for AI coding agents

Read [setup.md](/setup.md) and connect the Keiki MCP server at `https://onkeiki.com/mcp`. In an existing Eve, Flue or AI SDK app, run `npx @onkeiki/cli login` and then `npx @onkeiki/cli init` from the app directory. The CLI lists your external-harness agents, writes the handler file and stores the signing secret in your env file when one is needed. Text the line from a separate device and check the turn in Keiki.

## FAQ

**Is there an official iMessage SDK from Apple for bots?**
No. Apple's Messages framework is for on-device app extensions. Use Keiki to connect a line and run an agent on it.

**Does Keiki's iMessage SDK work with my own model?**
Yes. With `@onkeiki/ai-sdk`, `@onkeiki/eve` or `@onkeiki/flue`, your app runs the model with your own provider keys and Keiki delivers the reply.

**Do I need a signing secret for the AI SDK handler?**
No. Without one, the handler verifies Keiki's Ed25519 platform signature and uses the dispatch turn token. You can also set `KEIKI_SIGNING_SECRET`.

**Can I put an agent on iMessage without running a server?**
Yes. Define it with `@onkeiki/agents` and call `kit.sync()`, or build it in the dashboard, and Keiki runs the loop.

**Which apps does `npx @onkeiki/cli init` set up?**
Eve, Flue and AI SDK apps. For the AI SDK it writes a Next.js route, or a `src/keiki.ts` handler you mount yourself in Hono or Cloudflare Workers.
