How do I connect a Python agent to iMessage?
Keep your Python model loop, verify incoming iMessage turns and send replies through the turn-scoped HTTP API.
How do I connect a Python agent to iMessage?
Keiki is the way to put a Python agent on iMessage: connect a line and have Keiki send signed turns to your Python server. Your app runs the model and replies over HTTP while Keiki handles delivery, conversation history and human takeover in the team inbox.
Key takeaways
- Attach your iMessage line in Keiki and use the external harness to receive turns on your Python server.
- Verify the signed request before parsing it, and keep the turn token out of logs.
- Send the reply and report completion as separate HTTP requests.
- Connect your API or MCP tools for product actions, with human takeover in the team inbox.
- On eligible lines after setup, customers can use Keiki Vault Face ID for approvals and Apple Pay for checkout.
How does a Python app receive an iMessage?
Attach the iMessage line to your agent and configure external harness push mode with your Python endpoint's HTTPS URL. Keiki posts a signed turn with the inbound messages, conversation context and turn URL. Verify the signature against the raw request bytes before parsing JSON. Acknowledge the request after accepting the work, without waiting for the model to finish.
How does the Python agent send a reply and finish the turn?
Pass the inbound content and bounded history to your model. Post the reply to the turn URL's /messages endpoint with the short-lived bearer from the dispatch. Use the same idempotency key when retrying the same intended reply. Once sends and tools have settled, report the outcome to /complete. See the iMessage API for the distinction between sending a standalone message and replying from a turn.
Should I keep my Python model loop or build the agent on Keiki?
Keep your loop if it already runs your model and product logic. The external harness uses HTTP and JSON, so you don't need a JavaScript handler or a Python-specific SDK. If you only need to expose product data and actions from Python, build and run the model loop on Keiki using the dashboard or hosted agent SDK, then connect your Python backend as an API or MCP tool. Keiki runs the line, conversation and team inbox either way.
What should I test before giving customers the number?
Text from an iPhone and test a reply, a rejected signature and a retry without a duplicate reply. Have a teammate take over the same thread and hand it back. Use the turn trace to distinguish an app error from a delivery failure. If you enable Payments on an eligible line, test Apple Pay separately from Keiki Vault Face ID approval: paying for an order is not approval to run a tool. Check iMessage integration security before exposing sensitive actions.
Quick start for AI coding agents
For a Python-only server, configure external harness push mode directly and implement the signed HTTP turn contract in your existing server. Read setup.md and connect to the Keiki MCP server at https://onkeiki.com/mcp. To sign in from your terminal, run npx @onkeiki/cli login. Use npx @onkeiki/cli init only for a supported Eve, Flue or AI SDK project, not for a Python-only server.
FAQ
Do I need a Python SDK to connect to iMessage? No. Your Python server receives signed HTTP requests and calls the turn-scoped HTTP endpoints.
Is the turn token the same as my developer API key? No. It is short-lived and scoped to the specific turn. Keep it out of logs and don't reuse it for a different turn.
Does my endpoint's successful response send an iMessage? No. It acknowledges acceptance of the turn. Your app still sends the reply separately and reports completion.
Can my team reply without going through the Python model loop? Yes. A teammate can take over in Keiki's team inbox and answer in the same iMessage thread.