AIThreads Documentation

AIThreads provides email infrastructure for AI agents. Create managed inboxes, receive emails via webhooks, and send replies through our API.

Base URL: https://api.aithreads.io/v1

Quickstart

Get started in 5 minutes:

1. Create an account

Sign up at aithreads.io/sign-up and create an organization.

2. Generate an API key

Go to your dashboard → Settings → API Keys → Create New Key

3. Create your first inbox

cURL
curl -X POST https://api.aithreads.io/v1/agent/inboxes \
  -H "Authorization: Bearer ait_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "username": "support",
    "name": "Support Team"
  }'

4. Set up your webhook

Configure a webhook URL in your inbox settings to receive incoming emails.

5. Send a reply

cURL
curl -X POST https://api.aithreads.io/v1/agent/inboxes/{inbox_id}/messages \
  -H "Authorization: Bearer ait_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "to": [{"email": "customer@example.com"}],
    "subject": "Re: Your inquiry",
    "text_body": "Thank you for reaching out..."
  }'

Core Concepts

Organizations

Organizations are the top-level container for all resources. Each organization has its own inboxes, domains, and settings.

Inboxes

Inboxes are email addresses that can send and receive emails. Each inbox gets an address like support@yourorg.aithreads.io.

Threads

Emails are automatically grouped into threads based on subject and message headers. Threads maintain conversation history.

Labels

Labels help organize threads within an inbox. Create custom labels like "urgent", "resolved", or "needs-follow-up".

Knowledge Base

Upload documents to give your AI agent context. We generate embeddings for semantic search.

API Keys

API keys are the recommended way to authenticate for agent/programmatic access.

Request Header
Authorization: Bearer ait_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Key Format

API keys start with ait_ followed by a UUID. Keys are scoped to a single organization.

Permissions

ScopeDescription
inbox:readRead inbox details and list inboxes
inbox:writeCreate, update, delete inboxes
email:readRead emails and threads
email:sendSend emails

JWT Tokens

JWT tokens are used for dashboard/user authentication. Obtain a token by logging in:

Login
curl -X POST https://api.aithreads.io/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "you@example.com",
    "password": "your_password"
  }'

Response:

Response
{
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "user": {
    "id": "usr_abc123",
    "email": "you@example.com",
    "name": "Your Name"
  }
}

Create Inbox

Create a new email inbox for your organization.

POST /v1/agent/inboxes

Request Body

ParameterTypeRequiredDescription
usernamestringYesLocal part of the email address
namestringNoDisplay name for From header
webhook_urlstringNoURL to receive email notifications

Example

Request
curl -X POST https://api.aithreads.io/v1/agent/inboxes \
  -H "Authorization: Bearer ait_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "username": "support",
    "name": "Support Team"
  }'
Response
{
  "id": "inb_abc123",
  "address": "support@acme.aithreads.io",
  "local_part": "support",
  "domain": "acme.aithreads.io",
  "display_name": "Support Team",
  "is_active": true,
  "created_at": "2024-01-15T10:30:00Z"
}

List Inboxes

Retrieve all inboxes for your organization.

GET /v1/agent/inboxes

Response

Response
{
  "data": [
    {
      "id": "inb_abc123",
      "address": "support@acme.aithreads.io",
      "display_name": "Support Team",
      "thread_count": 142,
      "unread_thread_count": 5,
      "is_active": true
    }
  ],
  "pagination": {
    "total": 1,
    "limit": 20,
    "offset": 0
  }
}

Update Inbox

Update inbox settings including display name, webhook URL, and agent prompt.

PATCH /v1/agent/inboxes/:inbox_id

Request Body

ParameterTypeDescription
display_namestringDisplay name for From header
agent_promptstringSystem prompt for AI agent
webhook_urlstringWebhook URL for notifications
is_activebooleanEnable/disable the inbox

Delete Inbox

Permanently delete an inbox and all associated data.

DELETE /v1/agent/inboxes/:inbox_id
Warning: This action is irreversible. All threads, emails, and documents will be permanently deleted.

Send Email

Send an email from your inbox.

POST /v1/agent/inboxes/:inbox_id/messages

Request Body

ParameterTypeRequiredDescription
toarrayYesRecipients (email, name)
ccarrayNoCC recipients
subjectstringYesEmail subject
text_bodystringNo*Plain text body
html_bodystringNo*HTML body
thread_idstringNoReply to existing thread

* At least one of text_body or html_body is required.

Example

Request
curl -X POST https://api.aithreads.io/v1/agent/inboxes/inb_abc123/messages \
  -H "Authorization: Bearer ait_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "to": [{"email": "customer@example.com", "name": "John Doe"}],
    "subject": "Re: Your inquiry",
    "text_body": "Thank you for reaching out. Here is the information you requested...",
    "thread_id": "thr_xyz789"
  }'

Receive Webhooks

When an email is received, we'll POST to your configured webhook URL.

Webhook Payload

Payload
{
  "event": "email.received",
  "timestamp": "2024-01-15T10:30:00Z",
  "data": {
    "email_id": "eml_abc123",
    "thread_id": "thr_xyz789",
    "inbox_id": "inb_def456",
    "from": {
      "email": "customer@example.com",
      "name": "John Doe"
    },
    "to": [{"email": "support@acme.aithreads.io"}],
    "subject": "Need help with my order",
    "text_body": "Hi, I placed an order yesterday...",
    "received_at": "2024-01-15T10:30:00Z"
  }
}

Verifying Webhooks

We sign all webhook requests with HMAC-SHA256. Verify using your webhook secret:

Header
X-AIThreads-Signature: sha256=abc123...

List Messages

Get all messages in a thread.

GET /v1/agent/inboxes/:inbox_id/threads/:thread_id/messages

List Threads

Get all threads in an inbox.

GET /v1/agent/inboxes/:inbox_id/threads

Query Parameters

ParameterTypeDescription
limitintegerMax results (default: 20, max: 100)
offsetintegerPagination offset
is_readbooleanFilter by read status
is_archivedbooleanFilter by archived status

Get Thread

Get thread details with all messages.

GET /v1/agent/inboxes/:inbox_id/threads/:thread_id

Thread Labels

Labels help organize threads. Create labels per inbox, then apply them to threads.

Create Label

POST /v1/agent/inboxes/:inbox_id/labels
Request
{
  "name": "urgent",
  "color": "#EF4444",
  "description": "Needs immediate attention"
}

Upload Document

Upload a document to the knowledge base. Supported formats: PDF, TXT, MD, DOC, DOCX.

POST /v1/agent/inboxes/:inbox_id/documents

Request

Use multipart/form-data:

cURL
curl -X POST https://api.aithreads.io/v1/agent/inboxes/inb_abc123/documents \
  -H "Authorization: Bearer ait_your_api_key" \
  -F "file=@product-manual.pdf" \
  -F "name=Product Manual"

Documents are automatically processed for semantic search using AI embeddings.

Search Documents

Semantic search across your knowledge base.

GET /v1/agent/inboxes/:inbox_id/documents/search?q=query

Get Context for RAG

Use the context endpoint to get relevant document snippets for your AI agent:

GET /v1/agent/inboxes/:inbox_id/documents/context?q=query
Response
{
  "query": "refund policy",
  "context": "--- Document: Returns Policy (relevance: 0.89) ---\nCustomers may request a refund within 30 days...",
  "count": 3
}

Delete Document

Remove a document from the knowledge base.

DELETE /v1/agent/inboxes/:inbox_id/documents/:doc_id

Add Domain

Add a custom domain to send emails from your own domain.

POST /v1/organizations/:org_id/domains
Request
{
  "domain": "mail.example.com"
}

After adding, you'll receive DNS records to configure.

Verify Domain

Check if DNS records are properly configured.

POST /v1/organizations/:org_id/domains/:domain_id/verify

DNS Records

Required DNS records for custom domains:

TypePurposeDescription
CNAMEDKIM (x3)Email authentication signatures
MXMail routingRoute incoming mail to AIThreads
TXTSPFAuthorize sending servers
TXTDMARCEmail policy and reporting

Webhook Events

Events that trigger webhook notifications:

EventDescription
email.receivedNew email received in inbox
email.sentEmail successfully sent
email.bouncedEmail delivery failed
thread.createdNew conversation thread created

Webhook Security

All webhooks are signed using HMAC-SHA256 with your webhook secret.

Verification Example (Node.js)

Node.js
const crypto = require('crypto');

function verifyWebhook(payload, signature, secret) {
  const expected = 'sha256=' + crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');
  
  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expected)
  );
}

Retry Policy

Failed webhook deliveries are retried with exponential backoff:

  • Attempt 1: Immediate
  • Attempt 2: After 1 minute
  • Attempt 3: After 5 minutes
  • Attempt 4: After 30 minutes
  • Attempt 5: After 2 hours

A delivery is considered successful if your endpoint returns a 2xx status code within 30 seconds.