Skip to content

An open-source, faster Devin alternative

TypeScript

docs: webhooks own page (+ delivery control); EventSource streaming; split from messaging

Igor Zalutski1d7d570ce2ba
diff --git a/docs/agent-sessions/api-reference.mdx b/docs/agent-sessions/api-reference.mdx
index fbfb8a24..19a0eb63 100644
--- a/docs/agent-sessions/api-reference.mdx
+++ b/docs/agent-sessions/api-reference.mdx
@@ -42,21 +42,28 @@ Event = { id, seq, ts, session, actor, kind, level, body, refs }
| --- | --- |
| `POST /sessions/:id/messages` | Append an input message; wakes the session. Body: `{ text, idempotency_key? }` or `{ envelope }`. Returns `{ seq }`. |
-## Destinations (webhooks)
+## Destinations
| Method · Path | Purpose |
| --- | --- |
-| `POST /sessions/:id/destinations` | Register a webhook. Body: `url`, `secret?`, `level?` (`user`), `kinds?[]`, `include_raw?` (`false`). |
-| `GET /sessions/:id/destinations` | List destinations. |
-| `DELETE /sessions/:id/destinations/:id` | Remove a destination. |
-| `GET /sessions/:id/destinations/:id/deliveries` | List deliveries (incl. dead-lettered). |
-| `POST /sessions/:id/destinations/:id/deliveries/:id/retry` | Retry a dead-lettered delivery. |
+| `POST /sessions/:id/destinations` | Register a webhook. Body: `url`, `secret?`, `level?` (`user`), `kinds?[]`, `include_raw?` (`false`), `enabled?` (`true`). |
+| `GET /sessions/:id/destinations` · `GET …/:did` | List / fetch. |
+| `PATCH /sessions/:id/destinations/:did` | Pause/resume (`enabled`), retune `level`/`kinds`, rotate `secret`. |
+| `DELETE /sessions/:id/destinations/:did` | Remove. |
-See [Messaging & webhooks](/agent-sessions/messaging#delivery-contract) for the signing and delivery contract.
+## Deliveries
+
+| Method · Path | Purpose |
+| --- | --- |
+| `GET /sessions/:id/deliveries?destination=&status=` | List deliveries — status, attempts, last response/error. |
+| `GET /sessions/:id/deliveries/:id` | One delivery, in detail. |
+| `POST /sessions/:id/deliveries/:id/redeliver` | Re-send any delivery (not just dead-lettered). |
+
+See [Webhooks](/agent-sessions/webhooks#delivery-contract) for the signing and delivery contract.
```
-Destination = { id, url, level, kinds, include_raw, created_at }
-Delivery = { id, status, attempts, last_error?, event_id }
+Destination = { id, url, level, kinds, include_raw, enabled, created_at }
+Delivery = { id, destination_id, event_id, status, attempts, last_attempt_at, response_code?, error? }
```
## Agents
diff --git a/docs/agent-sessions/authentication.mdx b/docs/agent-sessions/authentication.mdx
index fb84ad72..83662052 100644
--- a/docs/agent-sessions/authentication.mdx
+++ b/docs/agent-sessions/authentication.mdx
@@ -36,6 +36,8 @@ browser ◀──(client_token)── your backend
browser ──(client_token)──▶ GET …/events (SSE) · POST …/messages
```
+For the SSE stream the browser passes the client token as `?token=` (native `EventSource` can't set an `Authorization` header); other calls use the `Authorization` header normally.
+
## Model credentials (BYO key)
Model usage is **billed to your OpenComputer account** by default — zero setup, metered, capped per session. To run on **your own** provider key instead, add a **credential**. It's stored in our secret store (encrypted, write-only, never returned) — you never manage a raw secret store yourself.
diff --git a/docs/agent-sessions/events.mdx b/docs/agent-sessions/events.mdx
index 2e7e4c8f..7aa0ae81 100644
--- a/docs/agent-sessions/events.mdx
+++ b/docs/agent-sessions/events.mdx
@@ -36,4 +36,4 @@ Every event has a visibility level; filter the stream and webhooks by it.
- **`head`** — the highest `seq` in the session.
- **`cursor`** — how far a reader (or the runtime) has consumed.
-Read or stream with `after=<seq>` and you get everything since that point. This is how **resume** works: reconnect with the last `seq` you saw — you miss nothing and get no duplicates.
+Read or stream with `after=<seq>` and you get everything since that point. This is how **resume** works: reconnect with the last `seq` you saw — you miss nothing and get no duplicates. In the browser, native `EventSource` does this automatically — each event's `seq` is the SSE `id`, so it resumes via `Last-Event-ID` on reconnect (see the [quickstart](/agent-sessions/quickstart)).
diff --git a/docs/agent-sessions/messaging.mdx b/docs/agent-sessions/messaging.mdx
index 32dc1319..42d9a4ec 100644
--- a/docs/agent-sessions/messaging.mdx
+++ b/docs/agent-sessions/messaging.mdx
@@ -1,9 +1,9 @@
---
-title: "Messaging & webhooks"
-description: "Steer a session, and receive its output reliably"
+title: "Messaging"
+description: "Steer a session, and the shared message envelope"
---
-Messaging is two halves over one shape: **steer** sends a message in; **destinations** push messages out. Both use the same channel-agnostic envelope, so the channels we add later (Slack, GitHub, …) won't change it.
+**Steer** sends a message into a session. Inbound and outbound messages share one channel-agnostic **envelope**, so the channels we add later (Slack, GitHub, …) won't change it. Outbound delivery has its own page: [Webhooks](/agent-sessions/webhooks).
## Steer (inbound)
@@ -41,47 +41,6 @@ Every inbound and outbound message normalizes to this shape. The core fields are
- **`text`** — the content the agent reads (or that you receive).
- **`raw`** — untouched original payload; optional, never read by the core.
-## Destinations (outbound webhooks)
+To get a session's output **out**, register a webhook destination — see [Webhooks](/agent-sessions/webhooks).
-Register a destination and the agent's messages are delivered to it. Filter what you receive so you're not spammed with internal chatter.
-
-```bash
-curl https://api.opencomputer.dev/v3/sessions/$ID/destinations \
- -H "Authorization: Bearer $OPENCOMPUTER_API_KEY" \
- -d '{ "url": "https://your.app/oc-webhook",
- "secret": "whsec_…",
- "level": "user", // user (default) | progress
- "kinds": ["message"], // optional allow-list; default all
- "include_raw": false }' // strip raw from the delivered envelope
-```
-
-### Delivery contract
-
-- **HTTPS only.** Private, loopback, link-local, and cloud-metadata addresses are refused.
-- **At-least-once, idempotent per (event × destination)**, with exponential backoff. After the max attempts a delivery is **dead-lettered** — inspect and retry it:
-
-```bash
-curl https://api.opencomputer.dev/v3/sessions/$ID/destinations/$DID/deliveries \
- -H "Authorization: Bearer $OPENCOMPUTER_API_KEY" # includes dead-lettered
-curl -X POST .../deliveries/$DELIVERY_ID/retry -H "Authorization: Bearer $OPENCOMPUTER_API_KEY"
-```
-
-- **Signed.** Each request carries `X-OC-Signature` (HMAC-SHA256 over `timestamp + "." + body`, keyed by your `secret`) and `X-OC-Timestamp`. The `secret` is write-only — set once, never returned.
-- A delivery succeeds on HTTP `2xx`.
-
-### Verify a webhook
-
-```js
-import { createHmac, timingSafeEqual } from "node:crypto";
-
-function verify(req, secret, body) {
- const ts = req.headers["x-oc-timestamp"];
- if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; // reject stale → replay guard
- const expected = createHmac("sha256", secret).update(`${ts}.${body}`).digest("hex");
- const got = req.headers["x-oc-signature"];
- return got.length === expected.length &&
- timingSafeEqual(Buffer.from(got), Buffer.from(expected));
-}
-```
-
-<Note>v1 ships the **generic webhook** channel. Channel adapters (Slack, GitHub comments, Jira, email) — inbound and outbound — are coming soon and reuse this exact envelope and delivery contract.</Note>
+<Note>Inbound channels (Slack, GitHub, Jira, email) are coming soon — they map onto this same envelope; today you steer in via the API.</Note>
diff --git a/docs/agent-sessions/overview.mdx b/docs/agent-sessions/overview.mdx
index 80b50cf7..6177575d 100644
--- a/docs/agent-sessions/overview.mdx
+++ b/docs/agent-sessions/overview.mdx
@@ -13,7 +13,7 @@ Give an agent a prompt and a task; OpenComputer runs it on a managed runtime in
`POST /v3/sessions { agent, input }` and the agent starts working immediately; you get back the session and a browser-safe `client_token`. *(Or inline `{ prompt, model, input }` for a one-off, without a reusable agent.)*
</Step>
<Step title="Watch, steer, get notified">
- Stream `GET …/events?stream=sse` — reconnect from any cursor to [resume](/agent-sessions/events). `POST …/messages` to [steer](/agent-sessions/messaging), and register a [webhook](/agent-sessions/messaging) to have output pushed to you.
+ Stream `GET …/events?stream=sse` — reconnect from any cursor to [resume](/agent-sessions/events). `POST …/messages` to [steer](/agent-sessions/messaging), and register a [webhook](/agent-sessions/webhooks) to have output pushed to you.
</Step>
</Steps>
diff --git a/docs/agent-sessions/quickstart.mdx b/docs/agent-sessions/quickstart.mdx
index 3f3c04e5..f8702cec 100644
--- a/docs/agent-sessions/quickstart.mdx
+++ b/docs/agent-sessions/quickstart.mdx
@@ -13,7 +13,7 @@ export OPENCOMPUTER_API_KEY=your-api-key
## 1. Start a session
-One call starts the session. Pass a `model`, a `prompt` (the agent's instructions), and `input` (the task).
+You don't need to create an agent first — one call starts a session. Pass a `model`, a `prompt` (the instructions), and `input` (the task).
```bash
curl https://api.opencomputer.dev/v3/sessions \
@@ -30,26 +30,20 @@ curl https://api.opencomputer.dev/v3/sessions \
}
```
-<Note>Defining the agent inline like this is sugar for one-off sessions. To reuse an agent across sessions, [create one](/agent-sessions/api-reference#agents) and start sessions with `{ "agent": "agt_…", "input": … }`.</Note>
+<Note>Defining the agent inline like this is sugar for one-off sessions. To reuse an agent across sessions, [create one](/agent-sessions/agents) and start sessions with `{ "agent": "agt_…", "input": … }`.</Note>
## 2. Stream it live
-Tail the event log over SSE from a cursor. Use the `client_token` from step 1 — no API key needed in the client. `level=user` shows only what an end user should see (see [levels](/agent-sessions/events#levels)).
+Open an `EventSource` with the `client_token` from step 1. It rides the query string — browsers can't set headers on `EventSource`, so the scoped client token goes in the URL (never your API key). `level=user` shows only what an end user should see (see [levels](/agent-sessions/events#levels)).
```js
-const res = await fetch(
- `https://api.opencomputer.dev/v3/sessions/${id}/events?stream=sse&after=0&level=user`,
- { headers: { Authorization: `Bearer ${clientToken}` } }
+const es = new EventSource(
+ `https://api.opencomputer.dev/v3/sessions/${id}/events?stream=sse&level=user&token=${clientToken}`
);
-const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
-for (;;) {
- const { value, done } = await reader.read();
- if (done) break;
- console.log(value); // raw SSE chunk(s) — split on "\n\n", strip "data:", JSON.parse
-}
+es.onmessage = (e) => render(JSON.parse(e.data)); // each event: { seq, actor, kind, level, body, … }
```
-To **resume** after a disconnect, reconnect with `after=<last seq you saw>` — you won't miss or duplicate events.
+**Resume is automatic.** Each event carries its `seq` as the SSE event `id`, so on a dropped connection `EventSource` reconnects and resends `Last-Event-ID` — you pick up exactly where you left off, no bookkeeping. (Pass `after=<seq>` on the URL to start from a specific point.)
## 3. Steer it
@@ -71,7 +65,7 @@ curl https://api.opencomputer.dev/v3/sessions/$ID/destinations \
-d '{ "url": "https://your.app/oc-webhook", "secret": "whsec_…", "level": "user" }'
```
-See [Messaging & webhooks](/agent-sessions/messaging) to verify the signature.
+See [Webhooks](/agent-sessions/webhooks#verify-a-webhook) to verify the signature.
## Next steps
@@ -79,7 +73,7 @@ See [Messaging & webhooks](/agent-sessions/messaging) to verify the signature.
<Card title="Sessions" icon="book" href="/agent-sessions/sessions">
How a session works — lifecycle and events.
</Card>
- <Card title="Messaging & webhooks" icon="bell" href="/agent-sessions/messaging">
- The envelope, steering, and reliable delivery.
+ <Card title="Webhooks" icon="bell" href="/agent-sessions/webhooks">
+ Deliver output reliably, and control deliveries.
</Card>
</CardGroup>
diff --git a/docs/agent-sessions/webhooks.mdx b/docs/agent-sessions/webhooks.mdx
new file mode 100644
index 00000000..4672c4bb
--- /dev/null
+++ b/docs/agent-sessions/webhooks.mdx
@@ -0,0 +1,67 @@
+---
+title: "Webhooks"
+description: "Deliver a session's output, and control deliveries"
+---
+
+Register a **destination** and a session's outbound messages are delivered to it over the shared [envelope](/agent-sessions/messaging#the-envelope) — at-least-once, signed, and retried. Filter what you receive so you're not spammed with internal chatter.
+
+## Destinations
+
+```bash
+curl https://api.opencomputer.dev/v3/sessions/$ID/destinations \
+ -H "Authorization: Bearer $OPENCOMPUTER_API_KEY" \
+ -d '{ "url": "https://your.app/oc-webhook",
+ "secret": "whsec_…",
+ "level": "user", // user (default) | progress
+ "kinds": ["message"], // optional allow-list; default all
+ "include_raw": false }' // strip raw from the delivered envelope
+```
+
+| Method · Path | Purpose |
+| --- | --- |
+| `POST /sessions/:id/destinations` | Register a destination. |
+| `GET /sessions/:id/destinations` · `GET …/:did` | List / fetch. |
+| `PATCH /sessions/:id/destinations/:did` | Pause or resume (`enabled`), retune `level`/`kinds`, or rotate `secret`. |
+| `DELETE /sessions/:id/destinations/:did` | Remove. |
+
+## Deliveries
+
+Every send and its outcome — the data behind a deliveries dashboard.
+
+| Method · Path | Purpose |
+| --- | --- |
+| `GET /sessions/:id/deliveries?destination=&status=` | List deliveries — status, attempts, last response/error. |
+| `GET /sessions/:id/deliveries/:id` | One delivery, in detail. |
+| `POST /sessions/:id/deliveries/:id/redeliver` | Re-send — **any** delivery, not just dead-lettered. |
+
+A delivery moves `pending → delivering → delivered`, or `failed` (retrying) → `dead_letter` after the max attempts.
+
+```
+Delivery = { id, destination_id, event_id, status, attempts, last_attempt_at, response_code?, error? }
+```
+
+<Note>Coming soon: full request/response **body** capture in delivery detail (today records status, attempts, response code, and error); a **test-ping** for a destination; and **org/agent-scoped** destinations that persist across sessions.</Note>
+
+## Delivery contract
+
+- **HTTPS only.** Private, loopback, link-local, and cloud-metadata addresses are refused.
+- **At-least-once, idempotent per (event × destination)**, with exponential backoff; after the max attempts a delivery is **dead-lettered** (inspect and redeliver it above).
+- **Signed.** Each request carries `X-OC-Signature` (HMAC-SHA256 over `timestamp + "." + body`, keyed by your `secret`) and `X-OC-Timestamp`. The `secret` is write-only — set once, never returned.
+- A delivery succeeds on HTTP `2xx`.
+
+### Verify a webhook
+
+```js
+import { createHmac, timingSafeEqual } from "node:crypto";
+
+function verify(req, secret, body) {
+ const ts = req.headers["x-oc-timestamp"];
+ if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; // reject stale → replay guard
+ const expected = createHmac("sha256", secret).update(`${ts}.${body}`).digest("hex");
+ const got = req.headers["x-oc-signature"];
+ return got.length === expected.length &&
+ timingSafeEqual(Buffer.from(got), Buffer.from(expected));
+}
+```
+
+<Note>v1 ships the **generic webhook** channel. Channel adapters (Slack, GitHub comments, Jira, email) are coming soon and reuse this exact envelope and delivery contract.</Note>
diff --git a/docs/docs.json b/docs/docs.json
index 0e7d9695..fcb0745c 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -69,6 +69,7 @@
"agent-sessions/authentication",
"agent-sessions/durability",
"agent-sessions/messaging",
+ "agent-sessions/webhooks",
"agent-sessions/runtimes",
"agent-sessions/api-reference"
]