# Collaboration

> Canonical URL: https://docs.mountaya.com/en/apis/map-studio/reference/collaboration/
> Last updated: 2026-11-26
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

The live event stream for a resource being edited: who is present, what they have selected, and what changed.

 It is what lets two people edit one route without overwriting each other.

## Stream one itinerary's collaboration session over SSE

### GET /v1/itineraries/{itinerary_id}/events

- Operation: `getItineraryEvents`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member)
- Behavior: idempotent, safe to retry

Opens a Server-Sent Events (SSE) stream of one itinerary's real-time editing session, so every member with the itinerary open converges on the same view and sees who else is editing. The response Content-Type is `text/event-stream` and the connection stays open until the client disconnects or the credential it was opened with ends.

The member's access is checked again about every ten seconds while the stream is open. When the member does not reach the itinerary, the stream ends, and reopening it answers 404, or 402 when the organization does not hold Map Studio. A member who holds no write role keeps watching, and any soft lock or uncommitted draft they hold is released and cleared for the other members (`lock.released`, `draft.clear`).

On connect the server sends, directly to this connection, a `presence.snapshot` of the members currently present and a `lock.snapshot` of every soft lock already held, then broadcasts a `presence.join` to the session, which reaches this connection too, as every signal of the member's own comes back to it. It then re-sends a fresh `presence.snapshot` and `lock.snapshot` down this connection periodically (every few seconds); the pair sent on connect can be up to one such interval old, and so can miss this connection's own arrival. A peer that disconnects uncleanly, from a killed tab or a dropped network that sends no `presence.leave` or `lock.released`, keeps its entries until they lapse, 45 seconds for its presence and 60 seconds for its locks after its stream ends, so its stale avatar and lock badge clear on the first snapshot after that: within about a minute. Each event is framed as `id: <stream-id>`, `event: <type>`, and `data: <json>`; only the durable change events carry an `id:`, the live-only signals do not.

The stream ends with its credential. When the session token reaches its expiry, or the key is revoked, loses the `studio-embedded` scope or its organization is canceled, the stream writes a last `reconnect` event, whose `data:` carries `reason` `credential-expired` or `credential-revoked`, and closes. That is not a failure: reopen at once with a fresh session token and `Last-Event-ID`, and the durable changes written in between are replayed. A `401` on the reopen means the credential itself is gone, and the stream ends there. A `HEAD` on this path opens no subscription.

It also ends when the server cannot keep delivering its events, because the reader fell behind or the server's subscription was lost: it writes a last `reconnect` event whose `reason` is `interrupted`, and closes. Reopen at once with `Last-Event-ID`, and the durable events written in between are replayed.

The `event:` type is one of:

- `itinerary.changed`, `segment.changed`, `waypoint.changed`: a durable structural change to the itinerary or one of its segments/waypoints.
- `presence.snapshot`: the authoritative set of members present, sent on connect and re-sent periodically; a client replaces its roster wholesale from it.
- `lock.snapshot`: the authoritative full set of held locks, sent on connect and re-sent periodically; a client replaces its lock state wholesale from it, so a lock held by an uncleanly disconnected peer clears once its registry entry lapses.
- `presence.join`, `presence.leave`: a member joined or left the session.
- `selection`: a member's current selection (a segment or waypoint), or null.
- `cursor`: a member's cursor position, or null.
- `lock.acquired`, `lock.released`: a member took or released the soft edit lock on an entity (a live delta between snapshots).
- `draft.update`, `draft.clear`: a member's uncommitted draft of an entity, or its clear.
- `reconnect`: the credential the stream was opened with ended, or the server cannot keep delivering the stream, and the stream closes after it (see above).

The `event:` type and the shape of the matching `data:` payload are the CollabStreamEvent schema: it is a union discriminated on `type`, so every frame kind this stream can send is stated once and cannot drift from the list above. The union spans all three collaboration streams; the frames named here are the subset this one carries.

To resume after a dropped connection, the client reconnects with the `Last-Event-ID` request header set to the last `id:` it received; the server replays the durable change events after that id before resuming the live feed. The live-only signals (presence, cursor, lock, draft) are never replayed. Without the header, the server first replays every durable change it still holds for the itinerary, so a fresh connection receives recent changes it may already reflect; applying one again is harmless, since each only names what to refetch. The stream keeps about the last thousand changes, for an hour after the latest one, so a `Last-Event-ID` older than that replays only what remains: after a long disconnect, refetch the itinerary rather than rely on the replay. A `Last-Event-ID` that is not a stream id (two numbers joined by a hyphen, the form of every `id:`) is a **400**, answered before the stream opens.

While the stream is open the server writes a comment (a line beginning with a colon) every 15 seconds, whatever else the stream carries. A comment is not an event: it has no `id:` and no `data:`, and a client discards it. It keeps the connection, and any proxy in between, from closing a quiet stream as idle.

Any member of the key's organization may watch, whatever their role; sending any signal through `postItineraryCollab`, a cursor or a selection as much as a lock or a draft, needs a write role. A personal itinerary, owned by no organization, has no collaboration session.

Opening the stream is limited to 60 opens a minute per user and 1200 a minute per organization, counted across every event stream, and every open is a read made with a session token besides, limited to 1200 requests a minute per user and 6000 a minute per organization; past any of them, the open is refused with **429** and `Retry-After`, and no stream starts. A reopen after a `reconnect` event counts as an open.

At most 20 streams are held open at once for each user, 50 for each client IP address and 1,000 for each organization, counted across every event stream. An open past any of them is a `429` with `Retry-After`, and no stream starts; a stream gives its place back when it ends.

The `studio-embedded` scope is NOT the scope the resource itself reads under. `getItinerary` takes `publishing`, and holding `publishing` does not grant `studio-embedded`: a key carrying only `publishing` reads the resource and is refused here with a `403`. The stream is scoped to `studio-embedded` because it is the live editing session an embedded studio opens on behalf of a member, not a change feed on a resource.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with any role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

**Headers**

- `Last-Event-ID` (string, in header, optional): The last stream id the client received, `<milliseconds>-<sequence>` as the stream wrote it, for example `1778577393417-0`. A value of any other shape is a `400`, answered before the stream opens. When set, the server replays the events after that id that the stream still holds before resuming the live feed. A stream holds about its last thousand events, for an hour after the latest one, or for five minutes after an agent run's `done` event, so a client that reconnects within that window misses no event that carries an id. An id older than what the stream still holds is not refused: the replay starts at the oldest event held, and nothing marks the gap.

  Live-only signals carry no id and are never replayed: cursors, selections and uncommitted drafts on a collaboration stream, whose presence and locks are sent again as snapshots instead, and the partial text of an agent's answer, which its final message supersedes.

  A browser's own `EventSource` sends this by itself on a reconnect. A client reading the stream some other way sends it explicitly. Without it the stream does not start at the live edge: the server replays every event the stream still holds, from the oldest, before the live feed, so a client that omits it on a reconnect receives again what it has already seen.

  A replayed event is written as it was first sent, with one exception. On an agent run's stream, a replayed `tool-call` or `confirm-required` whose outcome the replay also holds, a `tool-result` or a `tool-abandoned` for the same tool call id, carries `settled: true`, so a client that reads a run again neither runs that call nor asks about that confirmation a second time. One replayed without the marker has no outcome on the stream yet, and the client answers it as it would a live one.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200` `text/event-stream`

A `text/event-stream` of the itinerary's collaboration session, framed as `id:`/`event:`/`data:` records, open until the client disconnects or the credential ends, when a last `reconnect` event closes it. The schema describes one decoded frame, the `data:` JSON of a single record with the record's `event:` type folded in, not the byte stream as a whole.

**Errors** `400`, `401`, `402`, `403`, `404`, `429`, `500`, `503`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: Bad Request
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement, for either of two products the organization does not hold. Embedded Studio is the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member; it is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. Map Studio is the product every change to an organization's itineraries, collections and zones needs, editing together included, and an organization that does not hold it is refused here as well. Both are granted by the organization's agreement with Mountaya, so the answer is the same for both and clears when the agreement changes rather than when the request does. The reads that take `publishing` are unaffected either way.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: No itinerary with that identifier is reachable: either none exists, or this credential cannot view it. The two answer alike, so this status cannot be used to learn which itinerary ids exist. So does another organization's itinerary, public ones included, since a collaboration session is reached only through the organization that owns it, and a personal itinerary, owned by no organization, which has no session.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `503`: The stream cannot be opened right now: the session's live events, or what the member's access is checked against, could not be reached for a moment on Mountaya's side. The user has not joined the session and no event was missed: open the stream again once `Retry-After` has passed, with the `Last-Event-ID` of the last event received, or with none.

**cURL**

```bash
curl -sN "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/events" \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"

# Every durable frame carries an id. Send the last one you handled when you reopen,
# after a drop or after a `reconnect` event with a fresh session token, and the
# stream replays from just after it, so an edit made in between is not lost.
curl -sN "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/events" \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Last-Event-ID: 1778577393417-1"
```

**TypeScript**

```typescript
// `@mountaya/client/events` reads these streams with reconnects and typed frames.
const response = await fetch("https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/events", {
  headers: { "X-API-Key": publishableKey, "X-Session-Token": sessionToken },
});

const reader = response.body?.pipeThrough(new TextDecoderStream()).getReader();
for (let chunk = await reader?.read(); chunk && !chunk.done; chunk = await reader?.read()) {
  // `id:`, `event:` and `data:` lines, one frame per blank-line-separated record.
  console.log(chunk.value);
}
```

**Python**

```python
import json
import requests

with requests.get(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/events",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
    },
    stream=True,
    timeout=(10, None),
) as response:
    response.raise_for_status()
    for line in response.iter_lines(decode_unicode=True):
        if line.startswith("data:"):
            print(json.loads(line[5:]))
```

## Send a collaboration signal into an itinerary's session

### POST /v1/itineraries/{itinerary_id}/collab

- Operation: `postItineraryCollab`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member)
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Sends a live collaboration signal into an itinerary's real-time session, fanned out over the editor stream (getItineraryEvents) to every connection on it. The sender's own connections receive it too, recognizable by their `user_id`, which is the sender's. The request body shape is selected by its `type` discriminator:

- `selection`: the current selection (a segment or waypoint), or null to clear it.
- `cursor`: the cursor position, or null to clear it.
- `lock.acquire`: take the soft edit lock on an entity; refused with 409 when another member holds it. The lock lapses after 60 seconds unless the member keeps the editor stream open.
- `lock.release`: release the soft edit lock the member holds on an entity.
- `draft.update`: an uncommitted draft of an entity being edited; requires the member to already hold the entity's lock (409 otherwise).
- `draft.clear`: clear the member's uncommitted draft; requires the lock too.

The lock and draft signals name an entity this session guards, one the itinerary's writes check: a segment, a segment group or a waypoint. A zone is locked in its own session, `postZoneCollab`; named here, it is the `400` below and takes no lock.

The server always stamps the user the session token names onto the broadcast; a user id inside the body is never trusted. Every signal needs a member with a write role, a `selection` or a `cursor` as much as a lock: a viewer may watch the stream but not send into it. Beyond that, the itinerary must be one the key's organization owns: another organization's, public ones included, is the 404 below. The response is 200 with no data once the signal is accepted.

A signal states where the sender is rather than adding to anything: a selection, a cursor, a lock the sender holds, a draft. Sending the same signal again restates it, so the request is safe to repeat, and it takes no `Idempotency-Key`: a retry needs no stored answer to be safe.

Signals are limited to 1200 a minute per user, across every collaboration session; past that, the request is refused with **429** and `Retry-After`. A client that sends a signal on every pointer move throttles it to well under that.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

Records no webhook event. Runs the task `itinerary.collab.signal`.

**Path parameters**

- `itinerary_id` (string (uuid), in path, required): Identifier of the itinerary the operation acts on. An itinerary this credential does not reach is a 404 rather than a 403, and so is one that does not exist, so the parameter cannot be used to learn which itinerary ids exist.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The collaboration signal to broadcast to everyone editing this itinerary: a selection, a cursor move, a lock, or a draft update.

**Response** `200`

The collaboration signal is accepted and fanned out to the editor stream. `data` is null.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (any | null, required): Always null: this operation answers with no payload.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. A lock or draft signal naming a `zone` is refused here, at `["entity", "kind"]`, and takes no lock: this session guards the itinerary's segments, segment groups and waypoints, and a lock on anything else would refuse no write while refusing the itinerary's publication until it lapsed.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement, for either of two products the organization does not hold. Embedded Studio is the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member; it is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. Map Studio is the product every change to an organization's itineraries, collections and zones needs, editing together included, and an organization that does not hold it is refused here as well. Both are granted by the organization's agreement with Mountaya, so the answer is the same for both and clears when the agreement changes rather than when the request does. The reads that take `publishing` are unaffected either way.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: No itinerary with that identifier is reachable: either none exists, or this credential cannot view it. The two answer alike, so this status cannot be used to learn which itinerary ids exist. So does another organization's itinerary, public ones included, since a collaboration session is reached only through the organization that owns it, and a personal itinerary, owned by no organization, which has no session.
- `409`: Conflict. The entity is soft-locked by another member (`lock.acquire`), or the user the session token names does not hold the lock a draft signal requires. The holder is carried at `extensions.metadata.holder.id`, the all-zero UUID when the entity is simply unlocked.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Signals are ephemeral: they go out on the editor stream and are never stored.
# Send the durable change through the ordinary write instead.
curl -s -X POST https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/collab \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Content-Type: application/json" \
  -d '{"type": "cursor", "position": {"lng": 6.8712, "lat": 45.9231}}'
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.collab.postItineraryCollab({
  itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  body: { type: "cursor", position: { lng: 6.8712, lat: 45.9231 } },
});

console.log(data);
```

**Python**

```python
import requests

response = requests.post(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21/collab",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
    },
    json={"type": "cursor", "position": {"lng": 6.8712, "lat": 45.9231}},
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": null
}
```

## Stream one zone's collaboration session over SSE

### GET /v1/zones/{zone_id}/events

- Operation: `getZoneEvents`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member)
- Behavior: idempotent, safe to retry

Opens a Server-Sent Events (SSE) stream of one zone's real-time editing session, so every member with the zone open converges on the same view and sees who else is editing. The response Content-Type is `text/event-stream` and the connection stays open until the client disconnects or the credential it was opened with ends. It is the zone twin of the itinerary editor stream, `getItineraryEvents`. A `HEAD` on this path answers the stream's headers and opens no subscription.

The member's access is checked again about every ten seconds while the stream is open. When the member does not reach the zone, the stream ends, and reopening it answers 404, or 402 when the organization does not hold Map Studio. A member who holds no write role keeps watching, and any soft lock or uncommitted draft they hold is released and cleared for the other members (`lock.released`, `draft.clear`).

A stream ends with its credential. When the session token reaches its expiry, or the publishable key is revoked, loses the `studio-embedded` scope or its organization is canceled, the stream writes one last record, `event: reconnect` with `data: {"reason":"credential-expired"}` or `data: {"reason":"credential-revoked"}`, and closes. That close is not a failure: reopen at once with a fresh session token and the `Last-Event-ID` last received, and the durable changes written in between are replayed. A `401` on that reopen means the credential itself is gone, and the stream ends there.

It also ends when the server cannot keep delivering its events, because the reader fell behind or the server's subscription was lost: it writes a last `reconnect` event whose `reason` is `interrupted`, and closes. Reopen at once with `Last-Event-ID`, and the durable events written in between are replayed.

On connect the server sends, directly to this connection, a `presence.snapshot` of the members currently present and a `lock.snapshot` of every soft lock already held, then broadcasts a `presence.join` to the session, which reaches this connection too, as every signal of the member's own comes back to it. It then re-sends a fresh `presence.snapshot` and `lock.snapshot` down this connection periodically (every few seconds); the pair sent on connect can be up to one such interval old, and so can miss this connection's own arrival. A peer that disconnects uncleanly, from a killed tab or a dropped network that sends no `presence.leave` or `lock.released`, keeps its entries until they lapse, 45 seconds for its presence and 60 seconds for its locks after its stream ends, so its stale avatar and lock badge clear on the first snapshot after that: within about a minute. Each event is framed as `id: <stream-id>`, `event: <type>`, and `data: <json>`; only the durable change events carry an `id:`, the live-only signals and the closing `reconnect` do not.

The `event:` type is one of:

- `zone.changed`: a durable structural change to the zone.
- `presence.snapshot`: the authoritative set of members present, sent on connect and re-sent periodically; a client replaces its roster wholesale from it.
- `lock.snapshot`: the authoritative full set of held locks, sent on connect and re-sent periodically; a client replaces its lock state wholesale from it, so a lock held by an uncleanly disconnected peer clears once its registry entry lapses.
- `presence.join`, `presence.leave`: a member joined or left the session.
- `selection`: a member's current selection, or null.
- `cursor`: a member's cursor position, or null.
- `lock.acquired`, `lock.released`: a member took or released the soft edit lock on an entity (a live delta between snapshots).
- `draft.update`, `draft.clear`: a member's uncommitted draft of an entity, or its clear.
- `reconnect`: the last record, written when the credential ends or the server cannot keep delivering the stream.

The `event:` type and the shape of the matching `data:` payload are the CollabStreamEvent schema: it is a union discriminated on `type`, so every frame kind this stream can send is stated once and cannot drift from the list above. The union spans all three collaboration streams; the frames named here are the subset this one carries.

To resume after a dropped connection, the client reconnects with the `Last-Event-ID` request header set to the last `id:` it received; the server replays the durable change events after that id before resuming the live feed. The live-only signals (presence, cursor, lock, draft) are never replayed. Without the header, the server first replays every durable change it still holds for the zone, so a fresh connection receives recent changes it may already reflect; applying one again is harmless, since each only names what to refetch. The stream keeps about the last thousand changes, for an hour after the latest one, so a `Last-Event-ID` older than that replays only what remains: after a long disconnect, refetch the zone rather than rely on the replay. A `Last-Event-ID` that is not a stream id (two numbers joined by a hyphen, the form of every `id:`) is a **400**, answered before the stream opens.

While the stream is open the server writes a comment (a line beginning with a colon) every 15 seconds, whatever else the stream carries. A comment is not an event: it has no `id:` and no `data:`, and a client discards it. It keeps the connection, and any proxy in between, from closing a quiet stream as idle.

Any member of the key's organization may watch, whatever their role; sending any signal through `postZoneCollab`, a cursor or a selection as much as a lock or a draft, needs a write role. A personal zone, owned by no organization, has no collaboration session.

The `studio-embedded` scope is NOT the scope the resource itself reads under. `getZone` takes `publishing`, and holding `publishing` does not grant `studio-embedded`: a key carrying only `publishing` reads the resource and is refused here with a `403`. The stream is scoped to `studio-embedded` because it is the live editing session an embedded studio opens on behalf of a member, not a change feed on a resource.

Opening the stream is limited to 60 opens a minute per user and 1,200 per organization, and each open is also a read made with a session token, held to the 1200 reads per user and the 6000 per organization per minute every such read shares; over any of them, the open is a `429` carrying `Retry-After`, and no stream starts.

At most 20 streams are held open at once for each user, 50 for each client IP address and 1,000 for each organization, counted across every event stream. An open past any of them is a `429` with `Retry-After`, and no stream starts; a stream gives its place back when it ends.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with any role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Path parameters**

- `zone_id` (string (uuid), in path, required): Identifier of the zone the operation acts on.

**Headers**

- `Last-Event-ID` (string, in header, optional): The last stream id the client received, `<milliseconds>-<sequence>` as the stream wrote it, for example `1778577393417-0`. A value of any other shape is a `400`, answered before the stream opens. When set, the server replays the events after that id that the stream still holds before resuming the live feed. A stream holds about its last thousand events, for an hour after the latest one, or for five minutes after an agent run's `done` event, so a client that reconnects within that window misses no event that carries an id. An id older than what the stream still holds is not refused: the replay starts at the oldest event held, and nothing marks the gap.

  Live-only signals carry no id and are never replayed: cursors, selections and uncommitted drafts on a collaboration stream, whose presence and locks are sent again as snapshots instead, and the partial text of an agent's answer, which its final message supersedes.

  A browser's own `EventSource` sends this by itself on a reconnect. A client reading the stream some other way sends it explicitly. Without it the stream does not start at the live edge: the server replays every event the stream still holds, from the oldest, before the live feed, so a client that omits it on a reconnect receives again what it has already seen.

  A replayed event is written as it was first sent, with one exception. On an agent run's stream, a replayed `tool-call` or `confirm-required` whose outcome the replay also holds, a `tool-result` or a `tool-abandoned` for the same tool call id, carries `settled: true`, so a client that reads a run again neither runs that call nor asks about that confirmation a second time. One replayed without the marker has no outcome on the stream yet, and the client answers it as it would a live one.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200` `text/event-stream`

The zone's collaboration session as a `text/event-stream`, framed as `id:`/`event:`/`data:` records and ended by a `reconnect` record when the credential ends. The schema describes one decoded frame, the `data:` JSON of a single record with the record's `event:` type folded in, not the byte stream as a whole.

**Errors** `400`, `401`, `402`, `403`, `404`, `429`, `500`, `503`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: Bad Request
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement, for either of two products the organization does not hold. Embedded Studio is the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member; it is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. Map Studio is the product every change to an organization's itineraries, collections and zones needs, editing together included, and an organization that does not hold it is refused here as well. Both are granted by the organization's agreement with Mountaya, so the answer is the same for both and clears when the agreement changes rather than when the request does. The reads that take `publishing` are unaffected either way.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: No zone with that identifier is reachable: either none exists, or this credential cannot view it. The two answer alike, so this status cannot be used to learn which zone ids exist. So does another organization's zone, since a collaboration session is reached only through the organization that owns it, and a personal zone, owned by no organization, which has no session.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `503`: The stream cannot be opened right now: the session's live events, or what the member's access is checked against, could not be reached for a moment on Mountaya's side. The user has not joined the session and no event was missed: open the stream again once `Retry-After` has passed, with the `Last-Event-ID` of the last event received, or with none.

**cURL**

```bash
# Server-sent events, held open. Read it with a client that streams; buffering the
# whole response waits forever by design.
curl -sN https://api.mountaya.com/v1/zones/c40f8a25-7e63-4d19-b8a0-9f2e5c31d764/events \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"
```

**TypeScript**

```typescript
// `@mountaya/client/events` reads these streams with reconnects and typed frames.
const response = await fetch("https://api.mountaya.com/v1/zones/c40f8a25-7e63-4d19-b8a0-9f2e5c31d764/events", {
  headers: { "X-API-Key": publishableKey, "X-Session-Token": sessionToken },
});

const reader = response.body?.pipeThrough(new TextDecoderStream()).getReader();
for (let chunk = await reader?.read(); chunk && !chunk.done; chunk = await reader?.read()) {
  // `id:`, `event:` and `data:` lines, one frame per blank-line-separated record.
  console.log(chunk.value);
}
```

**Python**

```python
import json
import requests

with requests.get(
    "https://api.mountaya.com/v1/zones/c40f8a25-7e63-4d19-b8a0-9f2e5c31d764/events",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
    },
    stream=True,
    timeout=(10, None),
) as response:
    response.raise_for_status()
    for line in response.iter_lines(decode_unicode=True):
        if line.startswith("data:"):
            print(json.loads(line[5:]))
```

## Send a collaboration signal into a zone's session

### POST /v1/zones/{zone_id}/collab

- Operation: `postZoneCollab`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member)
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Sends a live collaboration signal into a zone's real-time session, fanned out over the editor stream, `getZoneEvents`, to every connection on it. The sender's own connections receive it too, recognizable by their `user_id`, which is the sender's. It is the zone twin of `postItineraryCollab` and reuses the same signal shapes. The request body shape is selected by its `type` discriminator:

- `selection`: the current selection, or null to clear it.
- `cursor`: the cursor position, or null to clear it.
- `lock.acquire`: take the soft edit lock on an entity; refused with 409 when another member holds it. The lock lapses after 60 seconds unless the member keeps the editor stream open.
- `lock.release`: release the soft edit lock the member holds on an entity.
- `draft.update`: an uncommitted draft of an entity being edited; requires the member to already hold the entity's lock (409 otherwise).
- `draft.clear`: clear the member's uncommitted draft; requires the lock too.

The lock and draft signals name the one entity this session guards, the zone itself, of kind `zone`. A segment, a segment group or a waypoint is locked in its itinerary's session, `postItineraryCollab`; named here, it is the `400` below and takes no lock.

The server always stamps the user the session token names onto the broadcast; a user id inside the body is never trusted. Every signal needs a member with a write role, a `selection` or a `cursor` as much as a lock: a viewer may watch the stream but not send into it. Beyond that, `selection` and `cursor` need the zone to be one this credential can view, and the lock and draft signals need it to be one the member can edit. The response is 200 with no data once the signal is accepted.

A signal sets live state rather than adding to it: sending the same one again leaves the session as the first one left it, and taking a lock the member already holds renews it. A lock on the zone itself also refuses `patchZone` from every other member while it is held. That is why it takes no `Idempotency-Key`: a signal sent twice has no second effect, so a retry needs no stored answer to be safe.

Signals are limited to 1200 per user per minute; over it, the signal is a `429` carrying `Retry-After`, and it is not sent.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with a write role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

Records no webhook event. Runs the task `zone.collab.signal`.

**Path parameters**

- `zone_id` (string (uuid), in path, required): Identifier of the zone the operation acts on.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The collaboration signal to broadcast to everyone editing this zone: a selection, a cursor move, a lock, or a draft update.

**Response** `200`

The collaboration signal is accepted and fanned out to the editor stream. `data` is null.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (any | null, required): Always null: this operation answers with no payload.

**Errors** `400`, `401`, `402`, `403`, `404`, `409`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. A lock or draft signal naming any kind but `zone` is refused here, at `["entity", "kind"]`, and takes no lock: this session guards the zone itself, and a lock on anything else would refuse no write while refusing the zone's publication until it lapsed.
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement, for either of two products the organization does not hold. Embedded Studio is the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member; it is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. Map Studio is the product every change to an organization's itineraries, collections and zones needs, editing together included, and an organization that does not hold it is refused here as well. Both are granted by the organization's agreement with Mountaya, so the answer is the same for both and clears when the agreement changes rather than when the request does. The reads that take `publishing` are unaffected either way.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the user the session token names is not a member of the key's organization, or holds a role there that reads only. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: No zone with that identifier is reachable: either none exists, or this credential cannot view it. The two answer alike, so this status cannot be used to learn which zone ids exist. So does another organization's zone, since a collaboration session is reached only through the organization that owns it, and a personal zone, owned by no organization, which has no session.
- `409`: Conflict. The entity is soft-locked by another member (`lock.acquire`), or the user the session token names does not hold the lock a draft signal requires. The holder is carried at `extensions.metadata.holder.id`, the all-zero UUID when the entity is simply unlocked.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Signals are ephemeral: they go out on the editor stream and are never stored.
# Send the durable change through the ordinary write instead.
curl -s -X POST https://api.mountaya.com/v1/zones/c40f8a25-7e63-4d19-b8a0-9f2e5c31d764/collab \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Content-Type: application/json" \
  -d '{"type": "cursor", "position": {"lng": 6.8712, "lat": 45.9231}}'
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});

const { data } = await mountaya.studio.collab.postZoneCollab({
  zone_id: "c40f8a25-7e63-4d19-b8a0-9f2e5c31d764",
  body: { type: "cursor", position: { lng: 6.8712, lat: 45.9231 } },
});

console.log(data);
```

**Python**

```python
import requests

response = requests.post(
    "https://api.mountaya.com/v1/zones/c40f8a25-7e63-4d19-b8a0-9f2e5c31d764/collab",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
    },
    json={"type": "cursor", "position": {"lng": 6.8712, "lat": 45.9231}},
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": null
}
```

## Stream an organization's list events over SSE

### GET /v1/organizations/{organization_id}/events

- Operation: `getOrganizationEvents`
- Requires: scope `studio-embedded` · acting user required (a session token naming a member)
- Behavior: idempotent, safe to retry

Opens a Server-Sent Events (SSE) stream of the changes to the target organization's itineraries, zones and collections, so every member watching the studio sees its lists converge without polling. The path names the key's own organization: a key is pinned to the organization it was issued for, and naming another is a `403` whether or not it exists. The response Content-Type is `text/event-stream` and the connection stays open until the client disconnects or the credential it was opened with ends. A `HEAD` on this path answers the stream's headers and opens no subscription.

The member's membership is checked again about every ten seconds while the stream is open. When the member does not belong to the organization, the stream ends, and reopening it answers 403, or 402 when the organization does not hold Map Studio.

A stream ends with its credential. When the session token reaches its expiry, or the publishable key is revoked, loses the `studio-embedded` scope or its organization is canceled, the stream writes one last record, `event: reconnect` with `data: {"reason":"credential-expired"}` or `data: {"reason":"credential-revoked"}`, and closes. That close is not a failure: reopen at once with a fresh session token and the `Last-Event-ID` last received, and the events written in between are replayed. A `401` on that reopen means the credential itself is gone, and the stream ends there.

It also ends when the server cannot keep delivering its events, because the reader fell behind or the server's subscription was lost: it writes a last `reconnect` event whose `reason` is `interrupted`, and closes. Reopen at once with `Last-Event-ID`, and the durable events written in between are replayed.

The stream carries only durable events that move a resource in or out of a member's list, or change how it is filed: an itinerary, a zone or a collection changing in the organization. It does not carry the editing signals of one itinerary or one zone, which are on the editor streams, `getItineraryEvents` and `getZoneEvents`. Each event is framed as `id: <stream-id>`, `event: <type>`, and `data: <json>`.

The `event:` type is one of:

- `itinerary.changed`: an itinerary was created, updated, or deleted in the organization.
- `zone.changed`: a zone was created, updated, or deleted in the organization.
- `collection.changed`: a collection was created, updated, or deleted in the organization, or an itinerary or zone entered or left one. A collection has no editor stream of its own: it is a folder, so every change to it is a list concern and arrives here. The frame names the COLLECTION in `id` even when what moved was one of its members, because the consumer refetches the group; naming the itinerary that entered or left would be both ambiguous and useless. `itinerary_id` is the all-zero UUID and `revision` is always 0, since a collection is not revisioned.
- `reconnect`: the last record, written when the credential ends or the server cannot keep delivering the stream. It carries no `id:` and is never replayed.

The `event:` type and the shape of the matching `data:` payload are the CollabStreamEvent schema: it is a union discriminated on `type`, so every frame kind this stream can send is stated once and cannot drift from the list above. The union spans all three collaboration streams; the four frames named here are the subset this one carries, and the live-only editing signals are not among them.

To resume after a dropped connection, the client reconnects with the `Last-Event-ID` request header set to the last `id:` it received; the server replays events after that id from the organization's durable stream before resuming the live feed. Without the header, the server first replays every event it still holds for the organization, so a fresh connection receives recent changes its lists may already reflect; applying one again is harmless, since each only names what to refetch. The stream keeps about the last thousand events, for an hour after the latest one, so a `Last-Event-ID` older than that replays only what remains: after a long disconnect, refetch the lists rather than rely on the replay. A `Last-Event-ID` that is not a stream id (two numbers joined by a hyphen, the form of every `id:`) is a **400**, answered before the stream opens.

While the stream is open the server writes a comment (a line beginning with a colon) every 15 seconds, whatever else the stream carries. A comment is not an event: it has no `id:` and no `data:`, and a client discards it. It keeps the connection, and any proxy in between, from closing a quiet stream as idle.

Opening the stream is limited to 60 opens a minute per user and 1,200 per organization, and each open is also a read made with a session token, held to the 1200 reads per user and the 6000 per organization per minute every such read shares; over any of them, the open is a `429` carrying `Retry-After`, and no stream starts.

At most 20 streams are held open at once for each user, 50 for each client IP address and 1,000 for each organization, counted across every event stream. An open past any of them is a `429` with `Retry-After`, and no stream starts; a stream gives its place back when it ends.

Requires a publishable key with the `studio-embedded` scope AND a session token minted for `studio-embedded` naming a user, a member with any role, whom the request acts as. A publishable key without a session token minted for `studio-embedded` naming a user, a token minted for another surface included, is refused with **401**.

**Path parameters**

- `organization_id` (string (uuid), in path, required): Identifier of the organization the operation acts on. A publishable key reaches only its own organization: any other identifier is a 403, whether or not it exists, so the parameter cannot be used to probe which organization ids exist.

**Headers**

- `Last-Event-ID` (string, in header, optional): The last stream id the client received, `<milliseconds>-<sequence>` as the stream wrote it, for example `1778577393417-0`. A value of any other shape is a `400`, answered before the stream opens. When set, the server replays the events after that id that the stream still holds before resuming the live feed. A stream holds about its last thousand events, for an hour after the latest one, or for five minutes after an agent run's `done` event, so a client that reconnects within that window misses no event that carries an id. An id older than what the stream still holds is not refused: the replay starts at the oldest event held, and nothing marks the gap.

  Live-only signals carry no id and are never replayed: cursors, selections and uncommitted drafts on a collaboration stream, whose presence and locks are sent again as snapshots instead, and the partial text of an agent's answer, which its final message supersedes.

  A browser's own `EventSource` sends this by itself on a reconnect. A client reading the stream some other way sends it explicitly. Without it the stream does not start at the live edge: the server replays every event the stream still holds, from the oldest, before the live feed, so a client that omits it on a reconnect receives again what it has already seen.

  A replayed event is written as it was first sent, with one exception. On an agent run's stream, a replayed `tool-call` or `confirm-required` whose outcome the replay also holds, a `tool-result` or a `tool-abandoned` for the same tool call id, carries `settled: true`, so a client that reads a run again neither runs that call nor asks about that confirmation a second time. One replayed without the marker has no outcome on the stream yet, and the client answers it as it would a live one.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200` `text/event-stream`

The organization's list events as a `text/event-stream`, framed as `id:`/`event:`/`data:` records and ended by a `reconnect` record when the credential ends. The schema describes one decoded frame, the `data:` JSON of a single record with the record's `event:` type folded in, not the byte stream as a whole.

**Errors** `400`, `401`, `402`, `403`, `404`, `429`, `500`, `503`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: Bad Request
- `401`: Unauthorized
- `402`: A plain `PAYMENT_REQUIRED`, with no per-entry refinement, for either of two products the organization does not hold. Embedded Studio is the product the `studio-embedded` scope belongs to and the one a publishable key needs to act as a member; it is checked before the key's scopes, so a key that lacks the scope as well is answered this rather than a `403`. Map Studio is the product every change to an organization's itineraries, collections and zones needs, editing together included, and an organization that does not hold it is refused here as well. Both are granted by the organization's agreement with Mountaya, so the answer is the same for both and clears when the agreement changes rather than when the request does. The reads that take `publishing` are unaffected either way.
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `studio-embedded` scope, or the path names an organization other than the key's own, whether or not it exists, or the user the session token names is not a member of the key's organization. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Answered only from Mountaya's web application: the path names an organization the person is not a member of, or one that does not exist. The two answer alike, so the path cannot be used to learn which organizations exist. Under a publishable key an identifier other than the key's organization is a `403` instead, whether or not it exists.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `503`: The stream cannot be opened right now: the organization's live events, or what the member's access is checked against, could not be reached for a moment on Mountaya's side. No event was missed: open the stream again once `Retry-After` has passed, with the `Last-Event-ID` of the last event received, or with none.

**cURL**

```bash
# Server-sent events, held open. One stream for every itinerary, zone and
# collection in the organization, so a list view stays current without polling.
curl -sN https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/events \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"
```

**TypeScript**

```typescript
// `@mountaya/client/events` reads these streams with reconnects and typed frames.
const response = await fetch("https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/events", {
  headers: { "X-API-Key": publishableKey, "X-Session-Token": sessionToken },
});

const reader = response.body?.pipeThrough(new TextDecoderStream()).getReader();
for (let chunk = await reader?.read(); chunk && !chunk.done; chunk = await reader?.read()) {
  // `id:`, `event:` and `data:` lines, one frame per blank-line-separated record.
  console.log(chunk.value);
}
```

**Python**

```python
import json
import requests

with requests.get(
    "https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/events",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
    },
    stream=True,
    timeout=(10, None),
) as response:
    response.raise_for_status()
    for line in response.iter_lines(decode_unicode=True):
        if line.startswith("data:"):
            print(json.loads(line[5:]))
```

**Error answers the operations of this page share**

- `TooManyRequests` (`429`): A limit on this operation's requests is spent: the [rate limits](https://docs.mountaya.com/en/apis/conventions/rate-limits.md) page lists every one, the unknown publishable keys one address may present among them, and the operation's description names any of its own. The request was counted and nothing was done. `Retry-After` says how long until the limit lifts; wait that long, with a little jitter of your own, and send the request again. Where the operation takes an `Idempotency-Key`, a write sent again with the same key runs once.
