For developers & AI agents

Build on Hanbai

A public REST API and a remote MCP server for sending email, managing domains and contacts, and running broadcasts — programmatically or from an AI agent.

REST API

Authenticate with a scoped API key from Settings → API Keys (hb_live_… / hb_test_…) as a Bearer token, or with an OAuth 2.1 access token (see below). Errors use one envelope: { statusCode, name, message }. The full machine-readable description is at /openapi.json (OpenAPI 3.1).

API and MCP live sending require a paid plan; the free plan includes test-mode keys. Live keys and OAuth tokens on the free plan receive 403 plan_upgrade_required.

EndpointScopeDoes
/api/v1/me · /api/v1/usageanyIntrospect the key (organization, mode, scopes, plan) and read plan usage: emails this month and contacts vs your plan limits.
/api/v1/emailsemails:send / emails:readSend one email (now or scheduled), list sent emails with cursor pagination, get status, cancel or reschedule a scheduled email.
/api/v1/emails/batchemails:sendSend up to 100 emails in a single request.
/api/v1/domainsdomains:read / domains:writeList sending domains, provision a new domain in a chosen region, verify DNS, and run a live SPF/DKIM/DMARC/MX audit.
/api/v1/contactscontacts:read / contacts:writeList, add, update and delete contacts (audience members), scoped to a brand.
/api/v1/suppressionscontacts:read / contacts:writeList, add and remove addresses on the suppression list. Suppressed addresses are skipped by every send path.
/api/v1/broadcasts · /api/v1/broadcasts/previewbroadcasts:sendPreview (dry run with a confirm_token) and send a one-off broadcast to a brand's active contacts. Respects suppression lists and plan limits.
/api/v1/webhooksdomains:read / domains:writeList, register and delete signed webhook endpoints for email events.

Available scopes

emails:sendemails:readdomains:readdomains:writeinbound:readcontacts:readcontacts:writebroadcasts:send

Keys are scoped to your organization and can be assigned any combination of the scopes above when you create them in Settings → API Keys.

Test-mode keys

Keys starting hb_test_ exercise the full API and MCP surface without sending anything: sends are simulated, logged with mode test, and don’t count against your quota. A recipient whose local part contains bounce or complain simulates that outcome, so you can test webhooks and error paths. Test-mode keys are available on every plan, including free.

MCP server

Hanbai runs a remote MCP (Model Context Protocol) server so AI agents — Claude, Claude Desktop, or any MCP-compatible client — can send email, manage domains, and run broadcasts directly. Each tool call is forwarded to the REST API above with your bearer token, so the same scopes, rate limits, and audit trail apply.

Connection

Transport
streamable-http (JSON-RPC over POST)
Endpoint
https://hanb.ai/api/mcp
Auth
OAuth 2.1 (discovered from the 401 challenge), or a Bearer Hanbai API key from Settings → API Keys

Every request except ping needs a Bearer token; without one the server answers 401 with a WWW-Authenticate header pointing at the protected-resource metadata. tools/list only shows tools your token’s scopes allow, and a call that needs a missing scope returns 403 insufficient_scope so the client can request it. A copy-paste client config is at GET /api/mcp/info.

Available tools

Every tool has a title and MCP annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) so clients can ask before sending or deleting. List tools accept response_format: "concise" | "detailed" and paginate.

ToolScopeHints
send_email
Send email
emails:senddestructive · open-world
send_batch_email
Send batch of emails
emails:senddestructive · open-world
list_emails
List sent emails
emails:readread-only
get_email_status
Get email status
emails:readread-only
cancel_email
Cancel scheduled email
emails:senddestructive · idempotent
reschedule_email
Reschedule email
emails:sendidempotent
add_domain
Add sending domain
domains:writeopen-world
verify_domain
Verify sending domain
domains:writeidempotent · open-world
list_domains
List sending domains
domains:readread-only
audit_domain
Audit domain DNS
domains:readread-only · open-world
add_contact
Add contact
contacts:writeidempotent
list_contacts
List contacts
contacts:readread-only
update_contact
Update contact
contacts:writeidempotent
delete_contact
Delete contact
contacts:writedestructive · idempotent
list_suppressions
List suppressed addresses
contacts:readread-only
add_suppression
Suppress address
contacts:writeidempotent
remove_suppression
Remove suppressed address
contacts:writedestructive · idempotent
send_broadcast
Send broadcast
broadcasts:senddestructive · open-world
get_usage
Get plan usage
anyread-only
list_webhooks
List webhooks
domains:readread-only
create_webhook
Create webhook
domains:writeopen-world
delete_webhook
Delete webhook
domains:writedestructive · idempotent

Two-step broadcasts

send_broadcast without a confirm_token sends nothing. It returns a preview: recipients after suppression, how many were suppressed, your remaining monthly quota, and a confirm_token valid for 10 minutes and bound to the brand, subject and content. Calling again with the same content and that token sends the broadcast; each token works once. Over REST the same flow is POST /api/v1/broadcasts/preview then POST /api/v1/broadcasts with confirm_token (optional for REST callers).

OAuth 2.1

MCP clients can connect with OAuth instead of a pasted API key. Hanbai runs an OAuth 2.1 authorization server for public clients: authorization code with PKCE (S256 only), consent per organization, and scoped access tokens.

  • Client registration: Dynamic Client Registration, or a Client ID Metadata Document (use an https URL as client_id; its JSON lists your redirect_uris). Redirect URIs must be https, or http on localhost / 127.0.0.1 for desktop apps.
  • Resource indicators (RFC 8707): send resource=https://hanb.ai/api/mcp.
  • Access tokens last 30 days; refresh tokens rotate on every use.
  • Revoke access or refresh tokens with RFC 7009 at /api/oauth/revoke.

Authorization endpoint

/oauth/authorize

Token endpoint

/api/oauth/token

Dynamic client registration

/api/oauth/register

Token revocation

/api/oauth/revoke

Authorization server metadata

/.well-known/oauth-authorization-server

Protected resource metadata

/.well-known/oauth-protected-resource

Discovery for agents

MCP server card

/.well-known/mcp.json

OpenAPI 3.1 (REST API)

/openapi.json

Agent skills index

/.well-known/agent-skills/index.json

hanbai-email skill

/.well-known/agent-skills/hanbai-email/SKILL.md

Webhooks

Register an https endpoint via /api/v1/webhooks (or the create_webhook tool) to receive signed email events instead of polling.

Ready to build?

Create an API key from your dashboard settings and start sending in minutes.

Start Free Trial