Overview

The AllternitBus API provides the runtime surface agents use to send and receive messages, store encrypted secrets, resolve connector credentials, and manage identity channels such as email, phone, and wallet addresses. All authenticated routes are mounted under /api/v1 and require a valid bearer token via the platform auth middleware. The public inbound webhook is mounted at /webhooks/photon and is called server-to-server by Photon.codes.
This namespace is served by the Allternit API data-plane node (http://127.0.0.1:8013 on the same machine, or your paired or provisioned node). The hosted Cloud API at https://api.allternit.com does not route it; it relays only agent sessions, canvases, office and beta research/sessions. See Cloud API.

Base URL

Authenticated surface:
Public webhook surface:
For local development:

Authentication

All authenticated routes require a valid bearer token in the Authorization header. The inbound Photon webhook is authenticated server-to-server by Photon.codes and does not carry a Clerk session. See Authentication for details.

Endpoints

Message inbox

Send a message

Delivers a message to the agent’s inbox. The route path is kept for backward compatibility with the Photon.codes integration.

Request body

Example request

Example response

List inbox messages

Returns messages for the agent, newest first.

Query parameters

Example request

Example response

Inbound webhook

Receive an inbound message

Public webhook for Photon 2.0 (Beta) events, signed with Standard Webhooks. There is no bearer token; the signature is the authentication. Set PHOTON_WEBHOOK_SECRET to the destination’s whsec_... signing secret (Photon returns it once when the destination is created). Every request must carry webhook-id, webhook-timestamp (Unix seconds, within 5 minutes of the server clock) and webhook-signature (v1,<base64>; HMAC-SHA256 over id.timestamp.rawBody with the base64-decoded secret, compared in constant time). A missing, wrong or stale signature, or an unset PHOTON_WEBHOOK_SECRET, answers 401 unauthorized and nothing is stored. The body is Photon’s public event JSON. A message.received event is routed to the agent whose identity channel has phone_provider = 'photon' and phone_number equal to the event’s data.object.receivedBy.handle, and stored in its inbox keyed by the event id, so a retried delivery is stored once. Other event types are accepted and ignored. The answer is 204 No Content.

Example event (abridged)

Secrets

Set a secret

Stores an encrypted secret value for the agent. Values are sealed at rest via token_crypto. If a secret with the same key already exists, it is overwritten.

Request body

Example request

Example response

Resolve secrets

Decrypts and returns values for the requested secret references. Required secrets that are missing or cannot be decrypted are reported in missing and errors.

Request body

Each reference:

Example request

Example response

Connectors

Resolve connector credentials

Resolves live credentials for the requested connector bindings. The route first looks up a connected connector_connections row for the caller, then falls back to legacy allternit_vault_credentials that belong to the agent and user.

Request body

Each binding:

Example request

Example response

Identity channels

Get identity channels

Returns the agent’s bound identity channels: email, phone, and wallet. Channels that have not been provisioned are returned as null.

Example request

Example response

Provision email

Provisions an email address for the agent on ALLTERNIT_BOT_EMAIL_DOMAIN (default bots.allternit.com): through Allternit’s cloud on a signed-in computer, or directly when the runtime has Allternit Mail’s admin key. See Agent email rail. When the mailflare agent-email rail is configured (ALLTERNIT_MAILFLARE_URL + ALLTERNIT_MAILFLARE_ADMIN_KEY), this creates a real mailbox on the mailflare worker, mints a mailbox-scoped send/read API key, seals it server-side, and stores the channel with provider "mailflare". The agent can then genuinely receive and (subject to approval) send internet email. When mailflare is not configured, the endpoint falls back to minting an address record only (provider "commrails", a stored value) with no send/receive transport. Provisioning is idempotent: re-provisioning an agent returns its existing channel. A platform address (provider mailflare) is owned by the server: a PATCH /api/v1/agents/:id that sends a different identityChannels.email.address keeps the stored one. To change it, release it and provision again (below). Switching the bot to its own mail account (provider other than mailflare / commrails) still saves the new address. To put the bot on a verified company domain, send { "localPart": "support", "domain": "acme.com" } (see Company domains). A domain whose records haven’t all checked returns 409 domain_not_verified; a bot that already has an address elsewhere returns 409 email_address_exists (release it first). The part before the @ comes from the optional body { "localPart": "ledger-bot" }: 3-40 lowercase letters, numbers and single hyphens (invalid values return 400 invalid_local_part; role names such as postmaster return 400 reserved_local_part). A requested name that is already taken returns 409 email_local_part_taken. Without localPart, the address is a slug of the bot’s name (ledger-bot), with -2, -3 and so on added only when that address is taken. The mailbox’s display name, which becomes the From name on outbound mail, is the bot’s name.

Example request

Example response

Change an agent’s address

Removes the agent’s mailbox (on a cloud-provisioned runtime, cloud-api also removes its key, its webhook and the relay route), then clears the address and the mailbox credentials from the agent. Reply settings (replyMode, replyAllowlist) stay. Mail sent to the old address stops arriving. Follow it with POST …/identity/email {"localPart": "<new name>"}. If the mailbox can’t be removed, the call returns 502 mailbox_not_removed and the agent keeps its address. The app’s email wizard and the bot’s Identity settings do both steps; when the new name is taken they provision the default address again and say which address the bot is on.

Agent email rail

Real inbound/outbound email for agents, backed by a per-installation mailflare worker (see services/mailflare/). Inbound mail arrives as an HMAC-signed webhook and is bridged into the agent’s Factory mail threads; outbound mail is held for human approval before it is sent.

Two ways a runtime gets bot email

Inbound mail is verified with the receiving mailbox’s own secret (cloud-provisioned) or the runtime-wide one (admin), before anything in the body is trusted; the bot is found by the event’s mailboxId, then the delivered-to address, then to. A cloud-provisioned bot’s direct replies (auto, auto_known) are sent with its own key and approved by the runtime itself once its review and autonomy rules allow them. A mailbox’s mail is never delivered to another runtime: each webhook is scoped to one mailbox. ALLTERNIT_BOT_EMAIL_BROKERED=0 turns the cloud mode off. cloud-api answers 503 bot_email_not_configured until ALLTERNIT_MAILFLARE_URL and ALLTERNIT_MAILFLARE_ADMIN_KEY are set on it.

Company domains

Bots can use a customer’s own domain ([email protected]) instead of bots.allternit.com. The domain’s mail runs through Allternit’s mail host, mx.allternit.com (Postfix plus services/mail-relay), not through Cloudflare: the customer’s domain never needs to be in Allternit’s Cloudflare account. The records (each comes back with ok: true | false after a check): Pointing a domain’s MX at mx.allternit.com sends all of that domain’s mail to the bots, so use a domain or subdomain (bots.acme.com) that doesn’t already receive mail elsewhere. A domain belongs to one Allternit account (409 domain_taken for anyone else); allternit.com and its subdomains are refused. On a signed-in computer the runtime calls cloud-api (PUT/GET/DELETE /api/v1/runtime-devices/me/bot-email/domains[/:domain], device credential), which records ownership in bot_email_domains (migration 062, applied by hand to prod) and calls Allternit Mail’s /api/v1/relay/domains/:host with the admin key. A runtime with the admin key calls that route itself. Allternit Mail (D1 migration 0012_relay_domains.sql, column domains.transport = 'relay') asks the relay to make the domain’s DKIM key and check DNS, marks the domain active once it verifies, and from then on:
  • Inbound: Postfix on mx.allternit.com accepts mail only for verified domains and existing bot mailboxes (live socketmap lookups to the relay, which asks the worker’s GET /api/v1/relay/recipient), and the relay posts it to the worker’s POST /api/v1/relay/inbound. From there it is the same path as any bot mail.
  • Outbound: mail from a relay domain goes to the relay’s POST /relay/send, which signs it with the domain’s DKIM key and queues it in Postfix (retries for up to two days).
Worker env: MAIL_RELAY_URL (https://mx.allternit.com/relay) and MAIL_RELAY_SECRET (32+ characters, the same value as the relay’s RELAY_SECRET). Without them, adding a domain answers 503 custom_domains_unavailable. The relay’s install script is services/mail-relay/deploy/install.sh.

Send email (approval-gated)

The message is not sent immediately. It is recorded as pending_approval and a review is requested on a Factory mail thread (mail:email-out-<id>). A human approves or rejects via POST /api/factory/mail/decide with { "thread": "<thread_id>", "approve": true|false }; approving triggers the actual send and writes a receipt with the provider message id. The decide response includes an email object for email threads.

Email rail status

Reports whether the mailflare rail is configured, the agent email domain, and whether the worker is reachable. Use this to diagnose installations.

Inbound webhook (server-to-server)

Public route called by the mailflare worker, authenticated by an X-Email-Platform-Signature HMAC-SHA256 header against ALLTERNIT_MAILFLARE_WEBHOOK_SECRET. message.inbound events are stored and bridged into the receiving agent’s Factory mail thread (mail:email-in-<agent>). Unknown recipients return 202 and are logged. Each stored message is scanned for one-time codes and magic links (email_otp::extract over the subject, text and any HTML). The result is saved on the agent_email_inbound row as otp_codes and otp_links (JSON arrays) and is_verification. Codes are 4 to 8 digits, or 6 to 10 letters and digits next to a word like code, OTP, verification, passcode, PIN or 2FA. Years, phone numbers, prices, dates and digits inside links or addresses are skipped. Links are https links with verify, confirm, login, magic, token or auth in the path or query; unsubscribe links and images are skipped. A message with is_verification set is stored with guard_reason = 'verification' and reply_status = 'skipped': it starts no bot turn and no reply. It is stored even when the sender is outside the bot’s email sender policy (no rejection is recorded for it), since sign-up mail comes from the site, not a contact. The bot reads it with the allternit_mail.read_otp tool. The webhook copy has no HTML and is cut at 4000 characters. When a message isn’t marked as verification and its copy was cut short or had no text, the runtime fetches the full message from mailflare in the background (30-second limit) and extracts again, so a code or link that only appears in the HTML still reaches read_otp. That second pass never starts a turn.

Inbox tools (MCP)

The internal connectors MCP endpoint serves these allternit_mail.* tools in-process, next to allternit_mail.send and allternit_mail.status. Every tool takes agent_id, and ownership is checked against the calling user. list, read_otp and send give the bot a mailbox first when it has none, the same way POST /api/v1/agents does for every new bot (is_bot: true): the local mailflare admin key when set, otherwise the cloud-brokered POST /api/v1/runtime-devices/me/bot-email/mailboxes on the default bot domain. Hosted bots created through the Platform API agent upsert get one the same way. Provisioning is idempotent and best effort. If the cloud already has the bot’s mailbox but this runtime lost its key, the runtime asks again with reissue: true: the cloud keeps the address, makes a new relay route, key and webhook, removes the old ones, and answers 200 in the provisioning shape. Set ALLTERNIT_BOT_EMAIL_AUTO=0 to turn automatic mailboxes off.

Provision phone

Assigns a phone number to the agent from the comma-separated pool in ALLTERNIT_BOT_PHONE_POOL. The first number not already assigned to another agent is chosen.

Example request

Example response

Cross-surface bridge

Bridge a session

Requests a cross-surface bridge for a session. The route path is kept for backward compatibility. The payload is echoed back with a bridged status.

Request body

Example request

Example response

Error codes

Photon outbound texts (Photon 2.0 Beta)

An agent can text a person on a Photon iMessage line. Every outbound text is held for the owner and goes only to the owner’s own handles. 1. Hold. Post to the inbox route with surface: "photon":
The answer is 202 {"id":"pho_hold_...","status":"held"}. Nothing is sent yet. to must be listed in ALLTERNIT_PHOTON_OWNER_HANDLES (comma-separated E.164; empty means no one), otherwise the call is 403 forbidden. 2. Approve. POST /api/v1/photon/outbound/:id/approve sends the text once with Photon’s POST /v1/projects/{projectId}/messages (header Idempotency-Key = the hold id; body spaceId, senderId, content {type:"text", format:"plain", text}). The answer is {"state":"sent","vendorMessageId":"pho_msg_...","vendorStatus":"dispatched"}. Photon delivers asynchronously, so dispatched is not delivered; read the message from Photon’s GET /v1/projects/{projectId}/messages/{messageId} for the final status. A second approve returns 409. POST .../reject ends the hold without sending. A Photon refusal returns 502 photon_failed and the hold is marked failed. Credentials. The runtime reads the agent’s sealed vault entries photon (project API key) and photon_project (project id), then falls back to the environment variables PHOTON_API_KEY and PHOTON_PROJECT_ID. With neither it answers 503 photon_not_configured. PHOTON_API_BASE overrides https://api.photon.codes. The person texts first. A shared Photon iMessage line cannot start a conversation. Add the person’s number to the line (POST /v1/projects/{projectId}/platforms/imessage/assignments with {"handle":"+1..."}, or the dashboard), then have them text the line once. Their first message creates the space and the Photon user ids (pho_spc_..., pho_usr_...) that a send needs.