Building an agent startup? Apply now →
Back to Blog

Multi-tenant email for AI agents: keep each customer apart

December 2, 2026

AI AgentsMulti-tenantGuide+1

To keep each customer's agents and email apart, give every customer their own pod in OpenMail. A pod holds that customer's inboxes and, if you like, their own domain, and a pod-scoped API key can only reach that one pod. Your account-wide key stays on your server and is the only thing that sees every customer.

The usual shortcut is one shared mailbox or one API key for everyone, with tenant IDs in your own code. It works until a bug, a leaked key or a prompt-injected agent crosses the line, and then nothing on the email side stops it. With pods, the API enforces the boundary. If you're still choosing a provider, what 1,000 agent inboxes cost compares the options. This guide is about keeping tenants apart.

Account, pod, inbox

Your OpenMail account is your business: one bill and one account-wide key. Inside it, each pod is one tenant: a customer, an end user or an environment. Every inbox belongs to exactly one pod, and it can't move to another pod later, so pick the pod when you create the inbox.

When you create a pod, pass your own tenant ID as clientId. From then on you can address the pod by that ID anywhere the API takes a pod, so you don't need a table that maps your tenants to OpenMail IDs.

Three keys, three reaches

The pod draws the line. The key decides who stays behind it.

OpenMail API key scopes: what each key reaches and who should hold it.
KeyWhat it reachesWho holds it
Account-wideEvery pod, inbox and domain. Mints and revokes scoped keys.Your backend only
Pod-scopedOne pod: read and send from its inboxes, create inboxes in it, add a domain scoped to it. No pod management.A tenant's integration or worker
Inbox-scopedOne inbox: read and send. Can't create, change or delete inboxes.A single agent

A scoped key can never widen its own reach, and neither kind can read or change sender rules, so a tricked agent can't loosen the rules on who it may email. A revoked key gets 401 on its next request.

Onboarding a customer

This is the flow from the multi-tenancy guide, run with your account-wide key when a customer signs up: create the pod, create an inbox in it, then mint the pod key you hand to that customer's integration.

onboard.py
import os, requests

OPENMAIL_API_KEY = os.environ["OPENMAIL_API_KEY"]  # account-wide key

def create_tenant_pod(tenant_id: str, company_name: str) -> dict:
    res = requests.post(
        "https://api.openmail.sh/v1/pods",
        headers={"Authorization": f"Bearer {OPENMAIL_API_KEY}"},
        json={"clientId": tenant_id, "name": company_name},
    )
    res.raise_for_status()
    return res.json()

def create_tenant_inbox(tenant_id: str, mailbox_name: str) -> dict:
    res = requests.post(
        "https://api.openmail.sh/v1/inboxes",
        headers={"Authorization": f"Bearer {OPENMAIL_API_KEY}"},
        json={"podId": tenant_id, "mailboxName": mailbox_name},
    )
    res.raise_for_status()
    return res.json()  # { "id", "address", "podId", ... }

def mint_tenant_key(tenant_id: str) -> str:
    res = requests.post(
        f"https://api.openmail.sh/v1/pods/{tenant_id}/api-keys",
        headers={"Authorization": f"Bearer {OPENMAIL_API_KEY}"},
        json={"name": f"{tenant_id}-integration"},
    )
    res.raise_for_status()
    return res.json()["token"]

def onboard_tenant(tenant_id: str, company_name: str) -> dict:
    create_tenant_pod(tenant_id, company_name)
    inbox = create_tenant_inbox(tenant_id, "support")
    scoped_key = mint_tenant_key(tenant_id)

    # Store scoped_key as this tenant's OPENMAIL_API_KEY (shown only once)
    return {"pod_id": tenant_id, "address": inbox["address"], "scoped_key": scoped_key}

The customer's worker or agent then sends with its scoped key. Point the same key at an inbox in someone else's pod and the API refuses:

send.sh
# Send with the tenant's scoped key
curl -X POST https://api.openmail.sh/v1/inboxes/INBOX_ID/send \
  -H "Authorization: Bearer $TENANT_SCOPED_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"to": "customer@example.com", "subject": "Hello", "body": "..."}'

# The same request against an inbox in another pod returns 403

A domain per customer

For white-label setups, add the customer's domain with their pod's ID, for example {"domain": "meridian.io", "podId": "meridian"} on POST /v1/domains. Only inboxes in that pod can use it. Publish the DNS records OpenMail returns and the domain verifies on its own.

A domain is either scoped to one pod or shared by every pod. If several tenants send from your own domain, keep it account-wide. You can narrow a domain to one pod later only while all its inboxes already live in that pod.

Routing inbound mail

Every inbound event carries the inbox_id it arrived on, so routing is a lookup from inbox to tenant. An account-wide subscription gets events from every pod. A subscription made with a pod key only sees that pod's events. One catch: a pod-key subscription covers the inboxes that existed when it started, so re-subscribe after creating an inbox. How agents receive and reply covers the webhook and WebSocket handlers.

What a pod doesn't separate

Pods are organizational isolation, not a network boundary:

  • Email isn't walled off. Inboxes in different pods are ordinary addresses and can email each other.
  • The account-wide key reaches everything. If it leaks, every tenant is exposed.
  • Billing and your plan's inbox limit are shared across the account.
  • Send limits apply per inbox, not per pod, and sender rules you set on a pod limit who its agents may email.

Inbound mail is still written by strangers. Scoped keys limit what a tricked agent can reach, but treat every email and attachment text as untrusted input.

Offboarding

Revoke the customer's key first; it stops working on its next request. Then delete the pod's inboxes, which removes their messages and threads, reassign or delete any pod-scoped domain, and delete the empty pod. The pods docs list the exact order and errors.

Frequently asked questions

How do I keep each customer's email separate in a multi-tenant AI product?

With OpenMail, create one pod per customer and put that customer's inboxes in it. Give their agents a pod-scoped or inbox-scoped API key, not your account key. The scoped key can only reach its own pod or inbox; requests to anything else return 403.

Can one customer's agent read another customer's inbox?

Not with a scoped key. A pod-scoped key reaches only its pod, and an inbox-scoped key only its one inbox. Your account-wide key reaches every pod, so keep it on your server and never give it to a tenant or an agent.

Can each customer send from their own domain?

Yes. Add the customer's domain with their pod's ID and it becomes a pod-scoped domain: only inboxes in that pod can use it. A domain is scoped to one pod or shared by all pods, never a chosen few.

Does a pod keep one tenant's sending from affecting another?

Mostly, if each tenant sends from its own domain. OpenMail tracks sending reputation per inbox and per domain, so give each tenant a pod-scoped custom domain (Pro and above) and a reputation hit stays with that tenant. Mail sent from the shared omail.sh domain shares its reputation, and the account-wide send cap still applies to everyone.

Should I give a tenant a pod key or an inbox key?

Use a pod key when the tenant owns several inboxes and needs to create more. Use an inbox key when one agent owns exactly one inbox. The inbox key is narrower: it can't create or delete inboxes.

Every AI agent deserves its own inbox.

Install the CLI, run setup, and you're sending email from your agent in minutes.

From the blog

Latest posts

All posts →
Developer4 min read

Create an email inbox for every user or agent with one API call

One POST to /v1/inboxes gives a user or AI agent its own working email address. The call, a signup-handler example with a per-inbox key, routing, and the limits at scale.

Nov 30, 2026Read →
Developer4 min read

How to keep prompt injection out of an AI agent's inbox

How to protect an AI agent that reads email from prompt injection and malicious attachments: what can go wrong, what to build in your agent, and what OpenMail handles for you.

Nov 30, 2026Read →
Analysis5 min read

Email for AI agents that keeps data in the EU

Which email API for AI agents keeps data in the EU? What runs where on OpenMail, how eight providers compare, and where agent email can still leave the EU.

Nov 10, 2026Read →
Analysis8 min read

Email for AI agent platforms: what 1,000 inboxes really cost

Twelve ways to run 1,000 agent inboxes, from a few dollars to $14,000 a month, and what each leaves you to build.

Nov 5, 2026Read →
Developer5 min read

Inbound email with attachment text, ready for an LLM

An inbound email API that puts the text of PDFs, scans, Office files and CSVs into the webhook, ready for a model. What gets extracted, the limits, and the code to pass it to an LLM.

Nov 2, 2026Read →