# Train spam filter from multiple messages

Submits spam or ham training feedback for a batch of messages in a single request. Same per-message idempotence as the single form: a message already taught this class is answered `accepted` but not sent again.

## `POST /api/v1/mailboxes/{mailboxId}/messages/learn`

### Path parameters

- `mailboxId` (string, required) — Mailbox ULID identifier

### Request body (required)

`application/json`

- `class` ("spam" | "ham", required) — Feedback classification ('spam' for junk, 'ham' for legitimate)
- `ids` (string[], required, min 1 items, max 200 items) — Array of message IDs to train on

### Responses

**202** — Batch feedback accepted with per-message queue status

`application/json` → BatchLearnResult

- `results` (BatchLearnEntry[], required) — List of training submission outcomes
  - `id` (string, required) — Message ULID
  - `status` ("accepted" | "not_found", required) — Spam/ham training submission status

**400** — validation_failed

`application/json` → ErrorOrValidation

**401** — unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a `WWW-Authenticate: Bearer` challenge

`application/json` → ErrorBody

**404** — Mailbox not found or not accessible to this principal

`application/json` → ErrorBody

**413** — too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing

`application/json` → ErrorBody

**503** — learning_unavailable — spam filter service is not configured. Or temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description)

`application/json` → ErrorBody

### Example request

```bash
curl -X POST 'https://api.open.email/api/v1/mailboxes/{mailboxId}/messages/learn' \
  -H 'Authorization: Bearer oek_…' \
  -H 'Content-Type: application/json' \
  -d '{
    "class": "spam",
    "ids": [
      "string"
    ]
  }'
```

## TypeScript SDK

[`openemail.messages.learnMany`](/docs/sdks/typescript/messages/learn-many)

```ts
const batchLearnResult = await openemail.messages.learnMany(mailboxId, { ids: ['…'], class: 'spam' })
```
