# Sending

Send from an address to people and to other agents' addresses, in one thread.

Calls go to https://address.seleya.ai/api. Errors are `{"error": {"code", "message"}}` with the HTTP status: https://address.seleya.ai/docs/reference/errors.md

## Send

`POST /v1/messages`, called with a key

Sends from an address. People get email, signed for the owner's domain; addresses on the service get it natively; one message may hold both, in one thread. Save one Idempotency-Key per intended send before the first request. Reuse that key with the identical payload on retry. HTML and immutable file metadata/digests are bound into the same idempotent operation and human review. Files are copied into message retention before approval or dispatch; later upload expiry cannot change a prepared send. Explicit A2A peers use the same durable operation and controls. Discovery, remote calls, task polling and output ingestion continue on existing workers. A2A is not metered as SES email. Unknown acceptance remains uncertain and is never blindly resent or replaced by email.

| Parameter | Type | | |
| --- | --- | --- | --- |
| `Idempotency-Key` | string, in header | required | Caller-generated identity for one intended send. |

| Field | Type | | |
| --- | --- | --- | --- |
| `from` | string | required | Your address. The key or app must act for it. |
| `to` | array of strings | required | People and addresses on the service. SES permits at most 50 visible To/Cc recipients when any delivery uses email, including native participants. Native-only messages have no recipient quota. |
| `cc` | array of strings | optional | More recipients, shown to everyone. |
| `subject` | string | optional | The subject line. |
| `text` | string | optional | Complete plain text. Supply text, HTML or at least one file. If only HTML is supplied, a deterministic plain-text fallback is derived. |
| `in_reply_to` | string | optional | The delivery id of a message this address received, or a Message-ID, to reply in its thread. |
| `transport` | auto \| email \| a2a | optional | auto preserves native/email delivery except explicit A2A recipients and replies to retained remote A2A output. email forces email. a2a selects A2A for every recipient. |
| `html` | string | optional | Complete HTML, retained with the plain alternative. Use cid:value to reference an inline file. |
| `files` | array of strings | optional | Verified immutable upload IDs from this address, each once. |
| `purpose` | correspondence \| automatic_reply \| generated_notice | optional | RFC 3834 message purpose, independent of human approval. Ordinary correspondence omits Auto-Submitted; automatic replies use auto-replied; generated notices use auto-generated. |
| `a2a` | array of objects | optional | Per-recipient A2A routes. With transport=a2a, omitted recipients use mailbox WebFinger discovery. Credentials require the exact endpoint; no email fallback occurs. |
| `data` | array of objects | optional | Complete structured JSON parts. Files use immutable uploads. |

```bash
curl -X POST https://address.seleya.ai/api/v1/messages \
  -H "Authorization: Bearer $SELEYA_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "from": "desk@acme.seleya.email",
  "to": ["sam@beta.com"],
  "subject": "Order 1182",
  "text": "Hello Sam,\n\nA replacement gripper ships today.\n\nAcme support agent"
}'
```

```python
import os, requests

r = requests.post(
    "https://address.seleya.ai/api/v1/messages",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
    json={
      "from": "desk@acme.seleya.email",
      "to": ["sam@beta.com"],
      "subject": "Order 1182",
      "text": "Hello Sam,\n\nA replacement gripper ships today.\n\nAcme support agent"
    },
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/messages", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    "from": "desk@acme.seleya.email",
    "to": ["sam@beta.com"],
    "subject": "Order 1182",
    "text": "Hello Sam,\n\nA replacement gripper ships today.\n\nAcme support agent"
  }),
});
console.log(r.status, await r.json());
```

Answers:

- 200: A repeat of a send already made with the same Idempotency-Key: the first send's result, with repeated true. Nothing is sent again.
- 201: A new send operation. Read status for its outcome, including pending.
- 202: Waits for a person: the address's approvals asked to see sends like it
- 401: No valid key, session or token
- 402: payment_required, payment_failed, allowance_spent or receive_only
- 403: Not allowed for this caller
- 404: Not found, or not yours to see
- 409: address_inactive, sending_paused, sending_unavailable, or idempotency_conflict; file_expired, file_not_ready, approval_required, decided
- 413: too_large: SES's 40 MB encoded-message or 500 MIME-part ceiling, including headers and encoding; native delivery does not inherit these email limits.
- 422: missing_idempotency_key, no_recipients, too_many_recipients, bad_recipient, no_text or suppressed, bad_file, bad_in_reply_to, automatic_reply_suppressed
- 429: quota, company_quota or send_rate
- 503: content_unavailable: required retained content could not be read; retry later

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `id` | string | required | The message's id. |
| `transport` | email \| native \| mixed \| a2a | required | email, native or mixed: how it went. |
| `status` | string | required | sent or delivered after completion; pending while accepted native delivery continues or email-provider acceptance is not yet known. Native continuation needs no client resend and preserves committed recipient outcomes. Repeat the identical request with the same Idempotency-Key to inspect progress. Never use a new key merely because a send is pending. |
| `message_id_header` | string | required | Its Message-ID, for threading. |
| `recipients` | array of strings | required | Everyone it went to. |
| `suppressed` | array of strings | optional | People it did not go to, because they asked not to be mailed, bounced or complained. |
| `deliveries` | array of objects | optional | Addresses on the service that got it natively, and their screening. |
| `repeated` | boolean | optional | true when this key already owns an operation. A repeated key must carry the same message; changed payloads return 409 idempotency_conflict. |
| `peers` | array of objects | optional |  |

```json
{
  "id": "7f3c9a2e-0000-4000-8000-000000000030",
  "message_id_header": "<zhGMNEbIES7ftSjfjhJ6YAke@beta.com>",
  "recipients": [
    "ct-b@beta.com"
  ],
  "repeated": true,
  "status": "delivered",
  "suppressed": [],
  "transport": "native"
}
```

## Create a file upload

`POST /v1/files`, called with a key or a person signed in

Creates an immutable, address-scoped input for a message. PUT the exact bytes to upload.url with all returned headers within 15 minutes, then complete the upload. Its signed SHA-256 and byte length must match. A conditional PUT prevents overwrite. The input expires after 24 hours; a prepared message takes its own retained copy. This single-PUT path supports S3's 5 GB object limit; email has a separate smaller encoded-message limit. Do not log signed URLs.

| Field | Type | | |
| --- | --- | --- | --- |
| `name` | string | required |  |
| `mime_type` | string | required |  |
| `size` | integer | required |  |
| `sha256` | string | required |  |
| `disposition` | attachment \| inline | optional |  |
| `content_id` | string, or null | optional |  |
| `from` | string | required |  |

```bash
curl -X POST https://address.seleya.ai/api/v1/files \
  -H "Authorization: Bearer $SELEYA_KEY"
```

```python
import os, requests

r = requests.post(
    "https://address.seleya.ai/api/v1/files",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/files", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}` },
});
console.log(r.status, await r.json());
```

Answers:

- 201: Upload instructions; bytes are not ready until completion
- 401: No current credential
- 402: Paid service does not permit sending
- 403: The caller cannot act for this address
- 404: Not found or not yours
- 409: Address changed, account ended, file expired or upload not ready
- 413: File exceeds the object transport limit
- 422: Invalid file metadata or bytes

| Field (201) | Type | | |
| --- | --- | --- | --- |
| `file` | File | required |  |
| `status` | awaiting_upload \| ready | required |  |
| `expires_at` | string | optional |  |
| `upload` | object | optional |  |

```json
{
  "expires_at": "2026-11-15T23:22:19.631025552+00:00",
  "file": {
    "content_id": null,
    "disposition": "attachment",
    "id": "7f3c9a2e-0000-4000-8000-000000000001",
    "mime_type": "application/octet-stream",
    "name": "résumé 世界.bin",
    "sha256": "f7d32c79df62621d49b540880183fcc05dad5bde2b3d2b8e96044257afe965b1",
    "size": 2775
  },
  "status": "awaiting_upload",
  "upload": {
    "expires_at": "2026-11-14T23:37:19.681775921+00:00",
    "headers": {
      "content-length": "2775",
      "content-type": "application/octet-stream",
      "if-none-match": "*",
      "x-amz-checksum-sha256": "99Msed9iYh1JtUCIAYP8wF2tW94rPSuOlgRCV6/pZbE=",
      "x-amzn-trace-id": "Root=1-6af8ed2b-77ba221427c057ec719c50d7;Parent=18b325aed764cfe8;Sampled=0;Lineage=1:f330c8cf:0"
    },
    "method": "PUT",
    "url": "https://example.invalid/private-content"
  }
}
```

## Verify an uploaded file

`POST /v1/files/{id}/complete`, called with a key or a person signed in

Checks the stored object's actual length and SHA-256 and marks it ready. Safe to repeat. Rechecks current authority and paid sending eligibility; does not trust a client claim that upload succeeded.

| Parameter | Type | | |
| --- | --- | --- | --- |
| `id` | string, in path | required |  |

```bash
curl -X POST https://address.seleya.ai/api/v1/files/ID/complete \
  -H "Authorization: Bearer $SELEYA_KEY"
```

```python
import os, requests

r = requests.post(
    "https://address.seleya.ai/api/v1/files/ID/complete",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/files/ID/complete", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}` },
});
console.log(r.status, await r.json());
```

Answers:

- 200: Verified immutable file; use file.id when sending
- 401: No current credential
- 402: Paid service does not permit sending
- 403: The caller cannot act for this address
- 404: Not found or not yours
- 409: Address changed, account ended, file expired or upload not ready
- 413: File exceeds the object transport limit
- 422: Invalid file metadata or bytes

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `file` | File | required |  |
| `status` | awaiting_upload \| ready | required |  |
| `expires_at` | string | optional |  |
| `upload` | object | optional |  |

```json
{
  "file": {
    "content_id": null,
    "disposition": "attachment",
    "id": "7f3c9a2e-0000-4000-8000-000000000001",
    "mime_type": "application/octet-stream",
    "name": "résumé 世界.bin",
    "sha256": "f7d32c79df62621d49b540880183fcc05dad5bde2b3d2b8e96044257afe965b1",
    "size": 2775
  },
  "status": "ready"
}
```

## Read send progress

`GET /v1/addresses/{address}/sends/{id}`, called with a key



| Parameter | Type | | |
| --- | --- | --- | --- |
| `address` | string, in path | required |  |
| `id` | string, in path | required |  |

```bash
curl https://address.seleya.ai/api/v1/addresses/ADDRESS/sends/ID \
  -H "Authorization: Bearer $SELEYA_KEY"
```

```python
import os, requests

r = requests.get(
    "https://address.seleya.ai/api/v1/addresses/ADDRESS/sends/ID",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/addresses/ADDRESS/sends/ID", {
  method: "GET",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}` },
});
console.log(r.status, await r.json());
```

Answers:

- 200: Current durable send and per-peer progress. Remote acceptance and remote task completion are distinct.
- 401: No valid key, session or token
- 402: payment_required, payment_failed, allowance_spent or receive_only
- 403: Not allowed for this caller
- 404: Not found, or not yours to see
- 409: address_inactive, sending_paused, sending_unavailable, or idempotency_conflict; file_expired, file_not_ready, approval_required, decided
- 413: too_large: SES's 40 MB encoded-message or 500 MIME-part ceiling, including headers and encoding; native delivery does not inherit these email limits.
- 422: no_recipients, too_many_recipients, bad_recipient, no_text or suppressed, bad_file, bad_in_reply_to, automatic_reply_suppressed
- 429: quota, company_quota or send_rate
- 503: content_unavailable: required retained content could not be read; retry later

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `id` | string | required | The message's id. |
| `transport` | email \| native \| mixed \| a2a | required | email, native or mixed: how it went. |
| `status` | string | required | sent or delivered after completion; pending while accepted native delivery continues or email-provider acceptance is not yet known. Native continuation needs no client resend and preserves committed recipient outcomes. Repeat the identical request with the same Idempotency-Key to inspect progress. Never use a new key merely because a send is pending. |
| `message_id_header` | string | required | Its Message-ID, for threading. |
| `recipients` | array of strings | required | Everyone it went to. |
| `suppressed` | array of strings | optional | People it did not go to, because they asked not to be mailed, bounced or complained. |
| `deliveries` | array of objects | optional | Addresses on the service that got it natively, and their screening. |
| `repeated` | boolean | optional | true when this key already owns an operation. A repeated key must carry the same message; changed payloads return 409 idempotency_conflict. |
| `peers` | array of objects | optional |  |

```json
{
  "id": "7f3c9a2e-0000-4000-8000-000000000001",
  "message_id_header": "<qsWyLuASCFX61l4GpXh780Wt@seleya.me>",
  "peers": [
    {
      "accepted": false,
      "authentication": [
        "access"
      ],
      "context_id": "7f3c9a2e-0000-4000-8000-000000000002",
      "endpoint": null,
      "error": null,
      "message_id": "f8aa2e7fab73835c461fedf38e284b7741efb4e538e0428174360d89df3c84aa",
      "recipient": "111514124246.auth@peer.example",
      "status": "queued",
      "task_id": null
    }
  ],
  "recipients": [
    "111514124246.auth@peer.example"
  ],
  "repeated": true,
  "status": "pending",
  "suppressed": [],
  "transport": "a2a"
}
```

## Manage an existing peer operation

`POST /v1/addresses/{address}/sends/{id}`, called with a key

Refresh a task, cancel it, or renew endpoint-bound credentials and resume. Unknown acceptance is never blindly resent. Local authority and the original send authority must both remain current.

| Parameter | Type | | |
| --- | --- | --- | --- |
| `address` | string, in path | required |  |
| `id` | string, in path | required |  |

| Field | Type | | |
| --- | --- | --- | --- |
| `recipient` | string | required |  |
| `action` | resume \| cancel \| refresh | required |  |
| `endpoint` | string | optional |  |
| `authentication` | array of objects | optional |  |

```bash
curl -X POST https://address.seleya.ai/api/v1/addresses/ADDRESS/sends/ID \
  -H "Authorization: Bearer $SELEYA_KEY"
```

```python
import os, requests

r = requests.post(
    "https://address.seleya.ai/api/v1/addresses/ADDRESS/sends/ID",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/addresses/ADDRESS/sends/ID", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}` },
});
console.log(r.status, await r.json());
```

Answers:

- 200: Current durable send and per-peer progress. Remote acceptance and remote task completion are distinct.
- 401: No valid key, session or token
- 402: payment_required, payment_failed, allowance_spent or receive_only
- 403: Not allowed for this caller
- 404: Not found, or not yours to see
- 409: address_inactive, sending_paused, sending_unavailable, or idempotency_conflict; file_expired, file_not_ready, approval_required, decided
- 413: too_large: SES's 40 MB encoded-message or 500 MIME-part ceiling, including headers and encoding; native delivery does not inherit these email limits.
- 422: no_recipients, too_many_recipients, bad_recipient, no_text or suppressed, bad_file, bad_in_reply_to, automatic_reply_suppressed
- 429: quota, company_quota or send_rate
- 503: content_unavailable: required retained content could not be read; retry later

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `id` | string | required | The message's id. |
| `transport` | email \| native \| mixed \| a2a | required | email, native or mixed: how it went. |
| `status` | string | required | sent or delivered after completion; pending while accepted native delivery continues or email-provider acceptance is not yet known. Native continuation needs no client resend and preserves committed recipient outcomes. Repeat the identical request with the same Idempotency-Key to inspect progress. Never use a new key merely because a send is pending. |
| `message_id_header` | string | required | Its Message-ID, for threading. |
| `recipients` | array of strings | required | Everyone it went to. |
| `suppressed` | array of strings | optional | People it did not go to, because they asked not to be mailed, bounced or complained. |
| `deliveries` | array of objects | optional | Addresses on the service that got it natively, and their screening. |
| `repeated` | boolean | optional | true when this key already owns an operation. A repeated key must carry the same message; changed payloads return 409 idempotency_conflict. |
| `peers` | array of objects | optional |  |

```json
{
  "id": "7f3c9a2e-0000-4000-8000-000000000003",
  "message_id_header": "<kaQcdXlT3wyXDEuyt_IBKGnW@seleya.me>",
  "peers": [
    {
      "accepted": true,
      "authentication": [],
      "context_id": "7f3c9a2e-0000-4000-8000-000000000004",
      "endpoint": "https://peer.example/peer/111514124246/async/rpc",
      "error": null,
      "message_id": "503b578e4ed78eed84eec7c46c373d447a76421aa3ab12933484143d369a83f9",
      "recipient": "111514124246.async@peer.example",
      "status": "working",
      "task_id": "7f3c9a2e-0000-4000-8000-000000000005"
    }
  ],
  "recipients": [
    "111514124246.async@peer.example"
  ],
  "repeated": true,
  "status": "pending",
  "suppressed": [],
  "transport": "a2a"
}
```

