> ## Documentation Index
> Fetch the complete documentation index at: https://docs.myworklayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Events

> Tell your factory what happened—from your API, Channels, or Signals—and control whether it reacts immediately, queues the work, or stores it as context.

An **Event** tells your factory that something happened—a new support ticket arrived, a customer replied, or an order changed state. When an Event lands in a Room, the factory reads it and decides whether to reply, spawn or steer a Worker, or simply keep it in mind.

Send an Event from your backend:

```bash theme={null}
curl -X POST "https://api.myworklayer.com/v1/rooms/$ROOM_ID/events"   -H "Authorization: Bearer $WORKLAYER_API_KEY"   -H "Content-Type: application/json"   -H "Idempotency-Key: zendesk-ticket-4821-created"   -d '{
    "type": "ticket.created",
    "content": "Ticket 4821 from Dana Lee: I was charged twice for order 1188. Please refund one charge.",
    "attributes": { "ticketId": "4821", "orderId": "1188" },
    "modelContext": { "customerPlan": "Business" },
    "delivery": "queue"
  }'
```

```json theme={null}
{ "eventId": "b7e4c1d2-8a3f-4f6e-9d20-5c1a7e9b3f08", "delivery": "queue" }
```

## How work enters a factory

Every inbound Event—whether sent from your backend, a [Channel](https://docs.myworklayer.com/channels.md), or a [Signal](https://docs.myworklayer.com/signals.md)—flows through the same durable event pipeline before being routed to its target Room (and, when a Worker is already following that thread, directly to the relevant Worker).

| Source | Trigger | Destination today | Configured in |
| - | - | - | - |
| **Factory API** | Your backend sends `POST /v1/rooms/{roomId}/events`. | Any Room you choose (for example, one Room per issue or ticket) | This API |
| **[Channels](https://docs.myworklayer.com/channels.md)** | A teammate messages the factory in Slack. | That Slack conversation's isolated Room | Web app |
| **[Signals](https://docs.myworklayer.com/signals.md)** | A connected app emits something new, like an incoming Gmail email. | The [main Room](https://docs.myworklayer.com/rooms.md#the-main-room) (`web`) | Web app |

Two additional mechanisms run without an inbound Room Event:

* **Scheduled runs (Loops):** recurring tasks you configure in the web app—for example, *"Every Monday at 9:00 AM, summarize open issues"*. Each run starts a fresh task.
* **Monitors:** background checks a [Worker](https://docs.myworklayer.com/workers.md) sets up for itself while working on a task—for example, *"Watch PR #412 until CI passes"* or *"Watch order 1188 until the carrier marks it delivered"*. Monitors poll on a timer and resume the task as soon as something changes. You can inspect active Monitors in the web app.

### Event routing vs. outbound Subscriptions

Worklayer separates **inbound Event routing** from **outbound webhook [Subscriptions](https://docs.myworklayer.com/subscriptions.md)**:

* **Inbound Events** flow *into* your factory (via `POST /v1/rooms/{roomId}/events`, Channels, or Signals) and route to a specific Room.
* **Outbound Subscriptions** (`/v1/subscriptions`) flow *out of* your factory—pushing signed HTTPS webhooks (`room.response`, `room.status`, `worker.status`, `reviews.*`) to your backend across all Rooms whenever the factory replies, changes state, or requests a Review.

> [!NOTE]
>
> Today, API-created Rooms receive only the Events your backend sends to `/v1/rooms/{roomId}/events`. Configuring per-Room subscriptions to external Signals or surfacing auto-created Channel Rooms in `GET /v1/rooms` is not yet supported in `/v1`. To feed third-party webhooks (such as GitHub, Sentry, or PostHog alerts) into per-item Rooms today, receive them on your backend and forward them to `POST /v1/rooms/{roomId}/events`.

## Event lifecycle

![Event lifecycle: POST /rooms/\{id}/events returns 202 Accepted and routes via queue, steer, or context into the Factory Room and outbound webhooks.](https://mintcdn.com/worklayer-17401167/cpUXFKQRIMsNdzrq/images/diagrams/events-lifecycle-light.svg?fit=max\&auto=format\&n=cpUXFKQRIMsNdzrq\&q=85\&s=60c646a7408667b213b42fe5630e6c60)

1. Worklayer validates and persists the Event, returning `202 Accepted` with its `eventId` and resolved `delivery` mode.
2. The Event is recorded in [Room History](https://docs.myworklayer.com/rooms.md#room-history) with `kind: "event"` and the same `eventId`.
3. Depending on `delivery`, the factory evaluates the Event and decides whether to reply, launch or steer a [Worker](https://docs.myworklayer.com/workers.md), or do nothing.
4. Whenever the factory replies in the Room, Worklayer dispatches a `room.response` [Subscription event](https://docs.myworklayer.com/subscriptions.md).

`202 Accepted` guarantees the Event is durably stored—not that the factory has finished reading or acting on it. Use [Subscriptions](https://docs.myworklayer.com/subscriptions.md) or [Room History](https://docs.myworklayer.com/rooms.md#room-history) to track outcomes.

## Choose when the factory reads an Event

The `delivery` field tells Worklayer how urgently the factory should process an Event. If omitted, it defaults to `queue`.

| `delivery` | Behavior | Best for |
| - | - | - |
| `queue` | Waits for the factory to finish its current work in the Room, then processes the Event. Starts immediately if the Room is idle. | New tickets, customer replies, standard workflow triggers. |
| `steer` | Interrupts at the next step boundary so the factory reads the Event mid-flight, along with any waiting `queue` and `context` Events (oldest first). Starts immediately if the Room is idle. | Urgent corrections—for example, *"Stop, it's order 1189, not 1188."* |
| `context` | Stored silently without waking the factory. Delivered alongside the next `queue` or `steer` Event (or user message), clearly marked as background context rather than a request. | Ambient updates—like an internal teammate note added to a ticket or background Slack chatter. |

In the support example, the initial ticket arrives with `delivery: "queue"`. If Dana Lee immediately corrects the order number while the factory is already investigating, send the update with `delivery: "steer"`:

```bash theme={null}
curl -X POST "https://api.myworklayer.com/v1/rooms/$ROOM_ID/events"   -H "Authorization: Bearer $WORKLAYER_API_KEY"   -H "Content-Type: application/json"   -H "Idempotency-Key: zendesk-ticket-4821-reply-2"   -d '{
    "type": "ticket.reply",
    "content": "Sorry—the duplicate charge is on order 1189, not 1188.",
    "delivery": "steer"
  }'
```

If the factory is in the middle of a slow tool call, it picks up the `steer` Event as soon as that step completes.

### Which webhooks an Event causes

| `delivery` | Subscription events emitted |
| - | - |
| `queue` | `room.status` (`running`), `room.response` (if the factory replies), then `room.status` (`idle`). |
| `steer` | Same as `queue` if the Room was idle. If already working, no new `room.status` is sent (it remains `running`), followed by `room.response` when it replies. |
| `context` | None. Because `context` never wakes the factory, no webhooks fire until a later `queue`, `steer`, or user message triggers work. |

> [!NOTE]
>
> Waiting for a webhook after sending a `context` Event will time out until a `queue` or `steer` Event arrives. That is by design.

## Event payload

| Field | Required | Description |
| - | - | - |
| `type` | Yes | A short label for the event kind, such as `ticket.created` (1–120 non-blank characters). |
| `content` | Yes | The main message or description the factory reads (must be non-blank). |
| `modelContext` | No | Structured JSON facts passed directly to the factory alongside `content`. |
| `attributes` | No | Structured metadata stored with the Event (for example, your internal IDs). Not automatically shown to the factory. The key `type` is reserved and disallowed. |
| `delivery` | No | `queue` (default), `steer`, or `context`. See [Choose when the factory reads an Event](#choose-when-the-factory-reads-an-event). |

Put everything the factory needs to reason and act inside `content` and `modelContext`. Use `attributes` for IDs and labels your own systems need when reading the Event back via [Get an Event](https://docs.myworklayer.com/api-reference/events/get-an-event.md), which returns all fields including `delivery`.

## Size and context limits

* **Request body:** up to **1 MiB** (larger requests return `413`).
* **`attributes` and `modelContext`:** up to **32 KiB** JSON each, maximum nesting depth **8**, and at most **128 keys** per object. Keys `__proto__`, `prototype`, and `constructor` are disallowed, and unknown top-level fields are rejected.
* **Full storage:** Worklayer persists the complete Event text, available anytime via [Get an Event](https://docs.myworklayer.com/api-reference/events/get-an-event.md) and accessible on demand by the factory inside its Room.

When injecting waiting Events into the factory's live context window:

* **`queue` and `steer`:** up to the first **16,000 characters** of `content` are shown inline (longer text is truncated with `…`, while the full Event remains readable on demand).
* **`context`:** the newest **20** waiting `context` Events are included in full (up to 16,000 characters each) within a **120,000-character** budget. Beyond that, up to the **60** newest waiting `context` Events include their first **1,000 characters** plus a pointer to the full text.
* **High-volume `context` backlogs:** if more than 60 `context` Events accumulate before the factory wakes, older ones are rolled up into a single summary line showing the count and time span so the factory can look them up if needed.
* **Read-once delivery:** once the factory processes newer `context` Events, skipped older ones are not re-injected automatically, though their full content remains stored and accessible.

## Safe retries with Idempotency-Key

Include an `Idempotency-Key` header (1–191 visible ASCII characters, single header) so retries after timeouts or `503` responses never duplicate Events:

| Request | Result |
| - | - |
| New key | `202 Accepted` with a new `eventId`. |
| Same key, same Room, same body | `202 Accepted` returning the original `eventId` without creating a second Event. |
| Same key, different body (including a different `delivery`) | `409 Conflict` — `Idempotency key has a different Event body`. |
| Same key in a different Room | `409 Conflict` — `Idempotency key is already in use`. |
| No key | `202 Accepted` with a new `eventId` on every request. |

> [!NOTE]
>
> Idempotency keys are unique across the **entire factory**, not just a single Room. Prefix keys with your Room or entity ID—for example, `zendesk-ticket-4821-created`.

Body comparison runs after JSON parsing and default resolution: object key order does not matter, and omitting `delivery` is treated identically to `"delivery": "queue"`.

## Errors

| Status | Cause |
| - | - |
| `400` | Invalid request body or `Idempotency-Key` header. An unrecognized `delivery` value returns `Invalid Event body`. |
| `404` | Room not found for this API key, or the Room is archived. |
| `409` | `Idempotency key has a different Event body` or `Idempotency key is already in use`. |
| `413` | Request body exceeds 1 MiB. |
| `503` | Temporary service unavailability. Retry with the same `Idempotency-Key`. |

> [card] [Channels](https://docs.myworklayer.com/channels.md)
>
> Connect Slack or build your own conversational Channel.

> [card] [Workers](https://docs.myworklayer.com/workers.md)
>
> Track, stream, and steer background tasks spawned by Events.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.