openapi: 3.1.0 info: title: API Reference agent threads API version: 1.0.0 servers: - url: https://api.agentmail.to description: prod - url: https://x402.api.agentmail.to description: prod-x402 - url: https://mpp.api.agentmail.to description: prod-mpp - url: https://api.agentmail.eu description: eu-prod tags: - name: threads paths: /v0/threads: get: operationId: list summary: List Threads description: 'Lists threads, most recent first. Pass `senders`, `recipients`, or `subject` to filter by substring. Filtered requests are served by search, which caps `limit` at 100. For relevance-ranked full-text search across senders, recipients, subject, and message body, use `Search Threads`. **CLI:** ```bash agentmail threads list ```' tags: - threads parameters: - name: limit in: query required: false schema: $ref: '#/components/schemas/type_:Limit' - name: page_token in: query required: false schema: $ref: '#/components/schemas/type_:PageToken' - name: labels in: query required: false schema: $ref: '#/components/schemas/type_:Labels' - name: before in: query required: false schema: $ref: '#/components/schemas/type_:Before' - name: after in: query required: false schema: $ref: '#/components/schemas/type_:After' - name: ascending in: query required: false schema: $ref: '#/components/schemas/type_:Ascending' - name: include_spam in: query required: false schema: $ref: '#/components/schemas/type_:IncludeSpam' - name: include_blocked in: query required: false schema: $ref: '#/components/schemas/type_:IncludeBlocked' - name: include_unauthenticated in: query required: false schema: $ref: '#/components/schemas/type_:IncludeUnauthenticated' - name: include_trash in: query required: false schema: $ref: '#/components/schemas/type_:IncludeTrash' - name: senders in: query description: Filter to threads whose senders contain this value (substring match). Repeatable; all values must match. required: false schema: type: array items: type: string - name: recipients in: query description: Filter to threads whose recipients contain this value (substring match). Repeatable; all values must match. required: false schema: type: array items: type: string - name: subject in: query description: Filter to threads whose subject contains this value (substring match). Repeatable; all values must match. required: false schema: type: array items: type: string - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: Response with status 200 content: application/json: schema: $ref: '#/components/schemas/type_threads:ListThreadsResponse' '404': description: Error response with status 404 content: application/json: schema: $ref: '#/components/schemas/type_:ErrorResponse' /v0/threads/search: get: operationId: search summary: Search Threads description: 'Full-text search across threads in the organization, ranked by relevance. The query is matched against senders, recipients, and subject (substring) and the message body (tokenized full text). Spam, trash, blocked, and unauthenticated threads are always excluded. `limit` cannot exceed 100.' tags: - threads parameters: - name: q in: query required: true schema: $ref: '#/components/schemas/type_:Query' - name: limit in: query required: false schema: $ref: '#/components/schemas/type_:Limit' - name: page_token in: query required: false schema: $ref: '#/components/schemas/type_:PageToken' - name: before in: query required: false schema: $ref: '#/components/schemas/type_:Before' - name: after in: query required: false schema: $ref: '#/components/schemas/type_:After' - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: Response with status 200 content: application/json: schema: $ref: '#/components/schemas/type_threads:SearchThreadsResponse' '400': description: Error response with status 400 content: application/json: schema: $ref: '#/components/schemas/type_:ValidationErrorResponse' '404': description: Error response with status 404 content: application/json: schema: $ref: '#/components/schemas/type_:ErrorResponse' /v0/threads/{thread_id}: get: operationId: get summary: Get Thread description: '**CLI:** ```bash agentmail threads get --thread-id ```' tags: - threads parameters: - name: thread_id in: path required: true schema: $ref: '#/components/schemas/type_threads:ThreadId' - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: Response with status 200 content: application/json: schema: $ref: '#/components/schemas/type_threads:Thread' '404': description: Error response with status 404 content: application/json: schema: $ref: '#/components/schemas/type_:ErrorResponse' patch: operationId: update summary: Update Thread description: Updates thread labels. Cannot add or remove system labels (sent, received, bounced, etc.). Rejects requests with a `422` for threads with 100 or more messages. tags: - threads parameters: - name: thread_id in: path required: true schema: $ref: '#/components/schemas/type_threads:ThreadId' - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: Response with status 200 content: application/json: schema: $ref: '#/components/schemas/type_threads:UpdateThreadResponse' '400': description: Error response with status 400 content: application/json: schema: $ref: '#/components/schemas/type_:ValidationErrorResponse' '404': description: Error response with status 404 content: application/json: schema: $ref: '#/components/schemas/type_:ErrorResponse' '422': description: Error response with status 422 content: application/json: schema: $ref: '#/components/schemas/type_:ErrorResponse' requestBody: content: application/json: schema: $ref: '#/components/schemas/type_threads:UpdateThreadRequest' delete: operationId: delete summary: Delete Thread description: 'Permanently deletes a thread and all of its messages. **CLI:** ```bash agentmail threads delete --thread-id ```' tags: - threads parameters: - name: thread_id in: path required: true schema: $ref: '#/components/schemas/type_threads:ThreadId' - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: Successful response '404': description: Error response with status 404 content: application/json: schema: $ref: '#/components/schemas/type_:ErrorResponse' /v0/threads/{thread_id}/attachments/{attachment_id}: get: operationId: get-attachment summary: Get Attachment description: '**CLI:** ```bash agentmail threads get-attachment --thread-id --attachment-id ```' tags: - threads parameters: - name: thread_id in: path required: true schema: $ref: '#/components/schemas/type_threads:ThreadId' - name: attachment_id in: path required: true schema: $ref: '#/components/schemas/type_attachments:AttachmentId' - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: Response with status 200 content: application/json: schema: $ref: '#/components/schemas/type_attachments:AttachmentResponse' '404': description: Error response with status 404 content: application/json: schema: $ref: '#/components/schemas/type_:ErrorResponse' components: schemas: type_:IncludeUnauthenticated: type: boolean description: Include unauthenticated in results. title: IncludeUnauthenticated type_messages:MessageLabels: type: array items: type: string description: Labels of message. title: MessageLabels type_:After: type: string format: date-time description: Timestamp after which to filter by. title: After type_threads:SearchThreadItem: type: object properties: inbox_id: $ref: '#/components/schemas/type_inboxes:InboxId' thread_id: $ref: '#/components/schemas/type_threads:ThreadId' labels: $ref: '#/components/schemas/type_threads:ThreadLabels' timestamp: $ref: '#/components/schemas/type_threads:ThreadTimestamp' received_timestamp: $ref: '#/components/schemas/type_threads:ThreadReceivedTimestamp' sent_timestamp: $ref: '#/components/schemas/type_threads:ThreadSentTimestamp' senders: $ref: '#/components/schemas/type_threads:ThreadSenders' recipients: $ref: '#/components/schemas/type_threads:ThreadRecipients' subject: $ref: '#/components/schemas/type_threads:ThreadSubject' preview: $ref: '#/components/schemas/type_threads:ThreadPreview' attachments: $ref: '#/components/schemas/type_threads:ThreadAttachments' last_message_id: $ref: '#/components/schemas/type_threads:ThreadLastMessageId' message_count: $ref: '#/components/schemas/type_threads:ThreadMessageCount' size: $ref: '#/components/schemas/type_threads:ThreadSize' updated_at: $ref: '#/components/schemas/type_threads:ThreadUpdatedAt' created_at: $ref: '#/components/schemas/type_threads:ThreadCreatedAt' highlights: $ref: '#/components/schemas/type_threads:SearchThreadHighlights' description: Matched fragments per field. Present only when the query matched an indexed field. required: - inbox_id - thread_id - labels - timestamp - senders - recipients - last_message_id - message_count - size - updated_at - created_at title: SearchThreadItem type_attachments:Attachment: type: object properties: attachment_id: $ref: '#/components/schemas/type_attachments:AttachmentId' filename: $ref: '#/components/schemas/type_attachments:AttachmentFilename' size: $ref: '#/components/schemas/type_attachments:AttachmentSize' content_type: $ref: '#/components/schemas/type_attachments:AttachmentContentType' content_disposition: $ref: '#/components/schemas/type_attachments:AttachmentContentDisposition' content_id: $ref: '#/components/schemas/type_attachments:AttachmentContentId' required: - attachment_id - size title: Attachment type_messages:MessageCreatedAt: type: string format: date-time description: Time at which message was created. title: MessageCreatedAt type_threads:ThreadSenders: type: array items: type: string description: Senders in thread. In format `username@domain.com` or `Display Name `. title: ThreadSenders type_attachments:AttachmentResponse: type: object properties: attachment_id: $ref: '#/components/schemas/type_attachments:AttachmentId' filename: $ref: '#/components/schemas/type_attachments:AttachmentFilename' size: $ref: '#/components/schemas/type_attachments:AttachmentSize' content_type: $ref: '#/components/schemas/type_attachments:AttachmentContentType' content_disposition: $ref: '#/components/schemas/type_attachments:AttachmentContentDisposition' content_id: $ref: '#/components/schemas/type_attachments:AttachmentContentId' download_url: type: string description: URL to download the attachment. expires_at: type: string format: date-time description: Time at which the download URL expires. required: - attachment_id - size - download_url - expires_at title: AttachmentResponse type_threads:ListThreadsResponse: type: object properties: count: $ref: '#/components/schemas/type_:Count' limit: $ref: '#/components/schemas/type_:Limit' next_page_token: $ref: '#/components/schemas/type_:PageToken' threads: type: array items: $ref: '#/components/schemas/type_threads:ThreadItem' description: Ordered by `timestamp` descending. required: - count - threads title: ListThreadsResponse type_threads:ThreadAttachments: type: array items: $ref: '#/components/schemas/type_attachments:Attachment' description: Attachments in thread. title: ThreadAttachments type_:Before: type: string format: date-time description: Timestamp before which to filter by. title: Before type_messages:MessageReferences: type: array items: type: string description: IDs of previous messages in thread. title: MessageReferences type_:IncludeSpam: type: boolean description: Include spam in results. title: IncludeSpam type_attachments:AttachmentSize: type: integer description: Size of attachment in bytes. title: AttachmentSize type_:Count: type: integer description: Number of items returned. title: Count type_threads:ThreadSize: type: integer description: Size of thread in bytes. title: ThreadSize type_messages:MessageSubject: type: string description: Subject of message. title: MessageSubject type_attachments:AttachmentContentId: type: string description: Content ID of attachment. title: AttachmentContentId type_messages:MessageHeaders: type: object additionalProperties: type: string description: Headers in message. title: MessageHeaders type_:IncludeBlocked: type: boolean description: Include blocked in results. title: IncludeBlocked type_messages:MessagePreview: type: string description: Text preview of message. title: MessagePreview type_messages:MessageUpdatedAt: type: string format: date-time description: Time at which message was last updated. title: MessageUpdatedAt type_:Query: type: string description: 'Full-text search query. Matched against the sender, recipients, and subject (substring) and the message body (tokenized full text).' title: Query type_:ErrorCode: type: string description: Stable, machine-readable error code in snake_case (for example, not_found or missing_permission). Branch on this rather than the message text. title: ErrorCode type_attachments:AttachmentId: type: string description: ID of attachment. title: AttachmentId type_attachments:AttachmentFilename: type: string description: Filename of attachment. title: AttachmentFilename type_attachments:AttachmentContentDisposition: type: string enum: - inline - attachment description: Content disposition of attachment. title: AttachmentContentDisposition type_threads:UpdateThreadRequest: type: object properties: add_labels: type: array items: type: string description: Labels to add to thread. Cannot be system labels. remove_labels: type: array items: type: string description: Labels to remove from thread. Cannot be system labels. Takes priority over `add_labels` (in the event of duplicate labels passed in). title: UpdateThreadRequest type_threads:ThreadItem: type: object properties: inbox_id: $ref: '#/components/schemas/type_inboxes:InboxId' thread_id: $ref: '#/components/schemas/type_threads:ThreadId' labels: $ref: '#/components/schemas/type_threads:ThreadLabels' timestamp: $ref: '#/components/schemas/type_threads:ThreadTimestamp' received_timestamp: $ref: '#/components/schemas/type_threads:ThreadReceivedTimestamp' sent_timestamp: $ref: '#/components/schemas/type_threads:ThreadSentTimestamp' senders: $ref: '#/components/schemas/type_threads:ThreadSenders' recipients: $ref: '#/components/schemas/type_threads:ThreadRecipients' subject: $ref: '#/components/schemas/type_threads:ThreadSubject' preview: $ref: '#/components/schemas/type_threads:ThreadPreview' attachments: $ref: '#/components/schemas/type_threads:ThreadAttachments' last_message_id: $ref: '#/components/schemas/type_threads:ThreadLastMessageId' message_count: $ref: '#/components/schemas/type_threads:ThreadMessageCount' size: $ref: '#/components/schemas/type_threads:ThreadSize' updated_at: $ref: '#/components/schemas/type_threads:ThreadUpdatedAt' created_at: $ref: '#/components/schemas/type_threads:ThreadCreatedAt' required: - inbox_id - thread_id - labels - timestamp - senders - recipients - last_message_id - message_count - size - updated_at - created_at title: ThreadItem type_threads:ThreadId: type: string description: ID of thread. title: ThreadId type_messages:MessageHtml: type: string description: HTML body of message. title: MessageHtml type_:IncludeTrash: type: boolean description: Include trash in results. title: IncludeTrash type_inboxes:InboxId: type: string description: The ID of the inbox. title: InboxId type_messages:MessageTo: type: array items: type: string description: Addresses of recipients. In format `username@domain.com` or `Display Name `. title: MessageTo type_messages:MessageInReplyTo: type: string description: ID of message being replied to. title: MessageInReplyTo type_:ValidationErrorResponse: type: object properties: name: $ref: '#/components/schemas/type_:ErrorName' code: $ref: '#/components/schemas/type_:ErrorCode' message: $ref: '#/components/schemas/type_:ErrorMessage' errors: description: Validation errors. Each entry has a path and a message identifying the invalid field. fix: $ref: '#/components/schemas/type_:ErrorFix' docs: $ref: '#/components/schemas/type_:ErrorDocs' required: - name - errors title: ValidationErrorResponse type_messages:MessageText: type: string description: Plain text body of message. title: MessageText type_threads:SearchThreadsResponse: type: object properties: count: $ref: '#/components/schemas/type_:Count' limit: $ref: '#/components/schemas/type_:Limit' next_page_token: $ref: '#/components/schemas/type_:PageToken' threads: type: array items: $ref: '#/components/schemas/type_threads:SearchThreadItem' description: Ordered by relevance, best match first. required: - count - threads title: SearchThreadsResponse type_threads:ThreadLastMessageId: type: string description: ID of last message in thread. title: ThreadLastMessageId type_:ErrorFix: type: string description: The concrete next action that resolves the error. title: ErrorFix type_:ErrorMessage: type: string description: Error message. title: ErrorMessage type_messages:MessageAttachments: type: array items: $ref: '#/components/schemas/type_attachments:Attachment' description: Attachments in message. title: MessageAttachments type_threads:Thread: type: object properties: inbox_id: $ref: '#/components/schemas/type_inboxes:InboxId' thread_id: $ref: '#/components/schemas/type_threads:ThreadId' labels: $ref: '#/components/schemas/type_threads:ThreadLabels' timestamp: $ref: '#/components/schemas/type_threads:ThreadTimestamp' received_timestamp: $ref: '#/components/schemas/type_threads:ThreadReceivedTimestamp' sent_timestamp: $ref: '#/components/schemas/type_threads:ThreadSentTimestamp' senders: $ref: '#/components/schemas/type_threads:ThreadSenders' recipients: $ref: '#/components/schemas/type_threads:ThreadRecipients' subject: $ref: '#/components/schemas/type_threads:ThreadSubject' preview: $ref: '#/components/schemas/type_threads:ThreadPreview' attachments: $ref: '#/components/schemas/type_threads:ThreadAttachments' last_message_id: $ref: '#/components/schemas/type_threads:ThreadLastMessageId' message_count: $ref: '#/components/schemas/type_threads:ThreadMessageCount' size: $ref: '#/components/schemas/type_threads:ThreadSize' updated_at: $ref: '#/components/schemas/type_threads:ThreadUpdatedAt' created_at: $ref: '#/components/schemas/type_threads:ThreadCreatedAt' messages: type: array items: $ref: '#/components/schemas/type_messages:Message' description: Messages in thread. Ordered by `timestamp` ascending. required: - inbox_id - thread_id - labels - timestamp - senders - recipients - last_message_id - message_count - size - updated_at - created_at - messages title: Thread type_threads:ThreadReceivedTimestamp: type: string format: date-time description: Timestamp of last received message. title: ThreadReceivedTimestamp type_:Limit: type: integer description: Limit of number of items returned. title: Limit type_messages:MessageBcc: type: array items: type: string description: Addresses of BCC recipients. In format `username@domain.com` or `Display Name `. title: MessageBcc type_:PageToken: type: string description: Page token for pagination. title: PageToken type_:ErrorName: type: string description: Name of error. title: ErrorName type_threads:SearchThreadHighlights: type: object properties: from: type: array items: type: string description: Matched fragments from a sender address in the thread. recipients: type: array items: type: string description: Matched fragments from a recipient address in the thread (to, cc, or bcc). subject: type: array items: type: string description: Matched fragments from the subject. text: type: array items: type: string description: Matched fragments from a message body in the thread. description: 'Matched fragments per field on a thread search result, with matched terms wrapped in `**`. A field key is present only when the query matched that field, so the present keys also tell you which fields produced the hit.' title: SearchThreadHighlights type_messages:MessageTimestamp: type: string format: date-time description: Time at which message was sent or drafted. title: MessageTimestamp type_threads:ThreadSentTimestamp: type: string format: date-time description: Timestamp of last sent message. title: ThreadSentTimestamp type_threads:ThreadTimestamp: type: string format: date-time description: Timestamp of last sent or received message. title: ThreadTimestamp type_threads:ThreadMessageCount: type: integer description: Number of messages in thread. title: ThreadMessageCount type_threads:UpdateThreadResponse: type: object properties: thread_id: $ref: '#/components/schemas/type_threads:ThreadId' labels: $ref: '#/components/schemas/type_threads:ThreadLabels' required: - thread_id - labels title: UpdateThreadResponse type_threads:ThreadUpdatedAt: type: string format: date-time description: Time at which thread was last updated. title: ThreadUpdatedAt type_:ErrorDocs: type: string description: Link to the error reference entry for this code. title: ErrorDocs type_messages:MessageSize: type: integer description: Size of message in bytes. title: MessageSize type_threads:ThreadCreatedAt: type: string format: date-time description: Time at which thread was created. title: ThreadCreatedAt type_attachments:AttachmentContentType: type: string description: Content type of attachment. title: AttachmentContentType type_:ErrorResponse: type: object properties: name: $ref: '#/components/schemas/type_:ErrorName' code: $ref: '#/components/schemas/type_:ErrorCode' message: $ref: '#/components/schemas/type_:ErrorMessage' fix: $ref: '#/components/schemas/type_:ErrorFix' docs: $ref: '#/components/schemas/type_:ErrorDocs' required: - name - message title: ErrorResponse type_messages:MessageCc: type: array items: type: string description: Addresses of CC recipients. In format `username@domain.com` or `Display Name `. title: MessageCc type_threads:ThreadLabels: type: array items: type: string description: Labels of thread. title: ThreadLabels type_messages:Message: type: object properties: inbox_id: $ref: '#/components/schemas/type_inboxes:InboxId' thread_id: $ref: '#/components/schemas/type_threads:ThreadId' message_id: $ref: '#/components/schemas/type_messages:MessageId' labels: $ref: '#/components/schemas/type_messages:MessageLabels' timestamp: $ref: '#/components/schemas/type_messages:MessageTimestamp' from: $ref: '#/components/schemas/type_messages:MessageFrom' reply_to: type: array items: type: string description: Reply-to addresses. In format `username@domain.com` or `Display Name `. to: $ref: '#/components/schemas/type_messages:MessageTo' cc: $ref: '#/components/schemas/type_messages:MessageCc' bcc: $ref: '#/components/schemas/type_messages:MessageBcc' subject: $ref: '#/components/schemas/type_messages:MessageSubject' preview: $ref: '#/components/schemas/type_messages:MessagePreview' text: $ref: '#/components/schemas/type_messages:MessageText' html: $ref: '#/components/schemas/type_messages:MessageHtml' extracted_text: type: string description: Extracted new text content. extracted_html: type: string description: Extracted new HTML content. attachments: $ref: '#/components/schemas/type_messages:MessageAttachments' in_reply_to: $ref: '#/components/schemas/type_messages:MessageInReplyTo' references: $ref: '#/components/schemas/type_messages:MessageReferences' headers: $ref: '#/components/schemas/type_messages:MessageHeaders' size: $ref: '#/components/schemas/type_messages:MessageSize' updated_at: $ref: '#/components/schemas/type_messages:MessageUpdatedAt' created_at: $ref: '#/components/schemas/type_messages:MessageCreatedAt' required: - inbox_id - thread_id - message_id - labels - timestamp - from - to - size - updated_at - created_at title: Message type_threads:ThreadSubject: type: string description: Subject of thread. title: ThreadSubject type_messages:MessageFrom: type: string description: Address of sender. In format `username@domain.com` or `Display Name `. title: MessageFrom type_messages:MessageId: type: string description: ID of message. title: MessageId type_threads:ThreadPreview: type: string description: Text preview of last message in thread. title: ThreadPreview type_threads:ThreadRecipients: type: array items: type: string description: Recipients in thread. In format `username@domain.com` or `Display Name `. title: ThreadRecipients type_:Ascending: type: boolean description: Sort in ascending temporal order. title: Ascending type_:Labels: type: array items: type: string description: Labels to filter by. title: Labels securitySchemes: Bearer: type: http scheme: bearer