REST API
The same index, tools and coverage semantics as the MCP server, over plain HTTPS with a bearer key you can scope to specific mailboxes and to read-only.
curl -H "Authorization: Bearer aik_..." \
"https://emailgents.com/api/public/v1/messages?q=invoice&unread=true&limit=10"- Created under Agents in the app; shown once; prefixed aik_.
- Scope a key to chosen mailboxes and read-only, flags, calendar, mail_write or send. Existing defaults are unchanged; mail_write and send are opt-in.
- Write scopes also require the matching per-mailbox agent permission. An explicit empty mailbox scope grants no access.
- Read permits operation status and metadata reconciliation; it never submits mail.
- Revoke instantly; the next call fails with 401.
- Every call appears on your Activity page with sanitized metadata.
Endpoints
Base URL: https://emailgents.com/api/public/v1. All responses are JSON except attachment downloads.
Connected mailboxes with status, sync window and coverage.
No parameters.
Folders per account with counts and sync state.
- account_id
- optional uuid
Unread counts and newest mail per mailbox.
- fresh
- true | false, default true
Search and list messages across mailboxes.
- q
- free-text query; quotes for phrases, - to exclude. Also matches words inside PDFs and text files, and images or scans when AI reading is on; such results list attachmentMatches with a short quote
- account_id
- repeatable
- folder
- repeatable role: inbox, sent, drafts, archive, trash, junk, all, starred, important, other
- folder_id
- uuid
- provider_label
- Exact provider label/category display name, separate from AI labels
- from, to
- substring match
- after, before
- ISO-8601
- unread, starred, has_attachments
- true | false
- calendar
- true: only invitations, updates, cancellations, replies and events; false: none of them
- limit
- 1–100, default 25
- offset
- integer, default 0
- order
- date | relevance
- fresh
- true | false, default true
One message with headers, body, attachment metadata and, for invitations, the full event structure (calendarData: events, attendees, join details, reminders, the owner's answer).
- format
- text | html | both
- max_chars
- 500–400000
- body
- false to skip the body
The conversation containing a message, oldest first.
- bodies
- true to include bodies
- max_chars
- per-message cap, default 12000
Download one attachment (up to 25 MB) with its original content type, or with as=text its extracted text as JSON (state, method, pages, text and paging in textInfo).
- as
- file (default) | text
- offset
- with as=text: continue from textInfo.nextOffset
- max_chars
- with as=text: 500–200000, default 60000
Every calendar per mailbox (synced provider calendars and the From-email calendar) with sync status and effective capabilities.
No parameters.
Unified calendar range: provider calendars merged with invitations and bookings found in mail, repeating events expanded, one entry per event per account. Index-only.
- from, to
- ISO-8601; default now to +30 days, at most 120 days
- account_id, calendar_id
- repeatable
- q
- match on title or location
- include_cancelled, include_hidden
- true | false
- time_zone
- IANA zone
- limit
- 1–500, default 100
One event or occurrence with attendees, join details, notes, reminders, mail history, actions and what the key can do with it.
- time_zone
- IANA zone
People by name or address: the address books of Google / Microsoft mailboxes that granted contacts, merged with everyone in the indexed mail. The sources list says which address books answered.
- q
- at least two characters, required
- account_ids
- repeatable or comma-separated
- limit
- 1–100, default 20
Open slots inside working hours across all connected calendars.
- from, to
- ISO-8601, required
- duration
- minutes, default 30
- time_zone
- IANA zone
- work_start, work_end
- HH:MM, default 09:00–18:00
- days
- 0–6, comma-separated, default Mon–Fri
- account_id
- repeatable
- max
- default 20
Set flags on up to 500 unique messages (flags scope and mailbox flags permission).
- message_ids OR anchor_message_ids OR filter
- Shared bounded selection; filters use the MCP snake_case action fields.
- read, starred
- Desired booleans; starred is the action value rather than a selection filter here.
- dry_run, max, cursor
- Preview; max 1–500, filter default 200; retain captured scope and finish remainingMessageIds before selection.nextCursor.
Archive Inbox mail and mark it read.
- message_ids OR anchor_message_ids OR filter
- Up to 500 unique messages. mail_write scope plus the corresponding mailbox permission.
- dry_run, max, cursor
- Preview; filter default 200. Continue remaining IDs before the returned cursor with the original scope.
Restore Archive mail to Inbox, preserving flags.
- message_ids OR anchor_message_ids OR filter
- Up to 500 unique messages. mail_write scope plus the corresponding mailbox permission.
- dry_run, max, cursor
- Preview; filter default 200. Continue remaining IDs before the returned cursor with the original scope.
Move mail to recoverable Trash; permanent removal remains opt-in housekeeping.
- message_ids OR anchor_message_ids OR filter
- Up to 500 unique messages. mail_write scope plus the corresponding mailbox permission.
- dry_run, max, cursor
- Preview; filter default 200. Continue remaining IDs before the returned cursor with the original scope.
Undo confirmed restorable moves to their recorded original folder; preserve later flags/labels (mail_write scope).
- receipt_ids
- 1–500 authorized receipt UUIDs. Requires original action permission and current destination identity.
Provider labels/categories/keywords, separate from AI labels (read scope).
- account_id, folder_id
- Mailbox UUID; IMAP requires folder UUID and may return an incomplete keyword catalogue.
Add/remove existing provider label references within one mailbox (mail_write scope and labels permission).
- account_id, add, remove
- Mailbox UUID and writable references from GET /labels.
- message_ids OR anchor_message_ids OR filter
- Shared bounded selection with dry_run/max/cursor. Does not create labels or edit AI/system labels.
Submit plain text via native Google/Microsoft OAuth only (send scope and mailbox Send permission).
- request_id, account_id, text
- One UUID per immutable submission, mailbox UUID and body ≤ 200 KiB UTF-8.
- to, cc, bcc, subject
- Address arrays, 50 recipients combined; subject ≤ 998 characters.
- retry_refused
- Explicit unchanged-payload retry of proven retryable refusal after its delay. Accepted/uncertain submissions never resend.
Reply or reply-all through native Google/Microsoft OAuth (send scope and Send permission).
- request_id, account_id, text, reply_all
- Immutable request UUID, source mailbox, plain text and optional reply_all.
- to, cc, bcc, subject
- Optional overrides; server derives visible recipients otherwise and never infers received Bcc.
- retry_refused
- Same frozen-refusal rules as sending.
Read authorized operation status (read scope); no provider dispatch.
- receipt_id OR request_id + account_id
- Receipt UUID or immutable submission UUID and mailbox UUID.
Observe metadata and repair the index from strong evidence (read scope); never send or resume IMAP source deletion.
- receipt_id OR request_id + account_id
- Same lookup in a JSON body.
Answer an invitation (calendar scope). Sent through the provider when the mailbox has a connected calendar, otherwise noted in Emailgents only; the response says which.
- answer
- accepted | tentative | declined
- scope
- this | series
- comment
- optional
Create an event in a writable calendar (calendar scope). Attendees are invited by the provider.
- calendar_id, title, start, end, time_zone
- required; wall-clock times or dates
- all_day, location, description, attendees[], reminder_minutes, rrule, conference_url, transparent
- optional
Force a bounded sync of one mailbox now.
No parameters.
Responses
- Search responses carry total, hasMore, coverage, refresh, freshness and messages; read coverage.status before concluding that something does not exist.
- Message responses carry bodyInfo (source and nextOffset) and attachments with size and downloadable flags.
- Thread responses carry coverage so a partial thread is never presented as complete.
- Mail actions return per-message operationStatus, providerState, indexState and retry guidance, plus separate remaining IDs and snapshot continuation. Applied, accepted and uncertain are distinct.
- All-failed responses retain outcomes alongside structured errors. Mixed batches retain each result; do not replay a whole batch to repair one item.
- Provider acceptance is not delivery. A submission request_id belongs to one frozen payload; check status before repeating an interrupted send.
Errors
- HTTP status plus a JSON body: { error: { code, message, retryable, retry_after, target, next_step, correlation_id } }.
- 401 unauthenticated, 403 forbidden/permission_missing, 404 not_found, 400 invalid_input, 409 uncertain/receipt_conflict/reauth_required, 429 rate_limited, 422 unsupported, 413 too_large, 502 provider_error, 504 provider_timeout, 503 server_unavailable.
- Follow per-item retry evidence and Retry-After. Uncertain or accepted sends never replay; metadata reconciliation never dispatches.
- Messages never include credentials or raw provider payloads; quote the correlation_id when reporting a problem.
Limits
- Search page size 1–100; mail actions at most 500 unique IDs, filter default 200.
- Ordinary sending: native Google/Microsoft OAuth, plain text ≤ 200 KiB UTF-8, at most 50 recipients, no attachments. App-password and legacy sending are unsupported.
- Bodies capped by max_chars (default 60 000, maximum 400 000) with continuation offsets.
- Attachments up to 25 MB per download.
- Provider fetches are bounded per call; use fresh=false for the fastest indexed answer.
API questions
Can a key be limited to one mailbox?
Yes. Choose the mailboxes when creating the key; requests for any other account return 403 forbidden.
Can a key send mail?
Yes, when it has the opt-in send scope, the mailbox has Send permission and native Google/Microsoft consent is sufficient. App-password and legacy ordinary sending are unsupported. Archive, recoverable Trash and provider labels use mail_write; flags and calendar retain their separate scopes. Provider acceptance is not delivery.
Is there an SDK?
Not yet; the API is small enough to call with fetch or curl, and MCP covers agent frameworks directly.
Prefer MCP? MCP server reference.