> This page is part of EVVA for Developers (https://developers.evvahub.com), the documentation of the EVVA Partner API. The API is in developer preview and the SDK packages are not yet published: do not suggest installing them. Index: https://developers.evvahub.com/llms.txt

# Realtime

Your application holds **one** connection and **one** channel — its own — and receives every event it may see, for
every creator it is granted. Events are the same v1 envelope as the [event feed](/event-feed) and
[webhooks](/webhooks/overview), each with its feed `cursor`, so a reconnect resumes exactly where you stopped.

| Topic        | Detail                                                                                             |
| ------------ | -------------------------------------------------------------------------------------------------- |
| WebSocket    | `wss://api.evvahub.com/realtime` — no query string, no `Origin`, no cookie                         |
| WebTransport | `https://realtime.evvahub.com` (HTTP/3) — same frames and semantics                                |
| Protocol     | JSON frames, version `1`, negotiated in the first frame                                            |
| Credential   | Your access token, inside the first frame — never in the URL                                       |
| Channel      | `partner:application:<applicationId>` — the `id` from `GET /partner/v1/app/me`, not your client id |

## The session

```mermaid
sequenceDiagram
    autonumber
    participant App as Your application
    participant RT as EVVA realtime
    App->>RT: Open the WebSocket
    App->>RT: hello {credential: evpa_ token, principal: "application", resume?}
    RT-->>App: welcome {connectionRef}
    App->>RT: subscribe ["partner:application:<applicationId>"]
    RT-->>App: subscribed
    loop While connected
        RT-->>App: event {seq, payload: event envelope with cursor}
        App->>App: Handle, then remember seq + cursor
        App->>RT: ack {seq} (cumulative)
        App->>RT: ping
        RT-->>App: pong
    end
    Note over App,RT: Token expires or access is revoked
    RT-->>App: error SESSION_REVOKED (on revocation)
    RT--xApp: close 4401 UNAUTHENTICATED
    App->>RT: Reconnect with a fresh token and hello.resume
```

## 1. Connect and say hello

The first frame must be `hello`. It carries your token and explicitly sets `principal` to `"application"`.

**`hello`**

```json title="hello"
{
  "protocolVersion": 1,
  "type": "hello",
  "frameId": "c-1",
  "sentAt": "2026-12-01T10:00:00.000Z",
  "channel": null,
  "seq": null,
  "correlationId": null,
  "payload": { "credential": "evpa_live_…", "principal": "application" }
}
```

The token is judged exactly as the REST API judges it: live, the application and its agency active, and its scopes
within what the application is allowed. The answer is `welcome`, which carries the `connectionRef` you use to resume.

## 2. Subscribe to your channel

Subscribe to `partner:application:<applicationId>`. It is the only channel an application may hold; any other channel
is answered `denied`. No presence is ever held or shown for an application.

## 3. Handle events and acknowledge

Each `event` frame carries a `seq` — dense per connection on your channel — and the event envelope, including its
feed `cursor`. Handle the event, then send a cumulative `ack` with that `seq`. An ack paces delivery and marks your
progress on this connection; it never changes a message's status.

Every event is checked again at delivery time: your current grants, the creator's consent and your token's scopes must
allow it, and your application and its agency must still be active. An event you may not see is not delivered.

## 4. Resume after a reconnect

Name the channel in `hello.resume.cursors` with the `seq` **and** the `cursor` of the last event you handled. EVVA
replays the recorded events after that cursor from the durable [event feed](/event-feed) — filtered by today's grants —
and continues at `seq + 1`.

**`hello with resume (payload)`**

```json title="hello with resume (payload)"
{
  "credential": "evpa_live_…",
  "principal": "application",
  "resume": {
    "token": "<connectionRef from the previous welcome>",
    "cursors": [
      { "channel": "partner:application:app_EXAMPLE", "seq": 41, "cursor": "<cursor of event 41>" }
    ]
  }
}
```

Only a feed cursor of your application that covers the whole feed resumes the channel. If the cursor is another
application's, a webhook's `whc1.` cursor or a consumer-group lease's cursor that covers only some partitions, is past
retention, or is too far behind for realtime to replay, the server answers an `error` frame `RESUME_REJECTED` naming
the channel. Then read the [event feed](/event-feed) from your
cursor; a `410 CURSOR_EXPIRED` there means a resync through the REST API. Without a cursor, a subscription starts at
"now".

## Revocation and token expiry

| What happened                                                                       | What you see                                                                                                                                |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| Your token expired                                                                  | The connection closes `4401 UNAUTHENTICATED` at that moment. Reconnect with a fresh token.                                                  |
| The token was revoked, the application disabled or revoked, or the agency suspended | An `error` frame `SESSION_REVOKED`, then close `4401` (WebTransport `3`) within about a second.                                             |
| A grant was narrowed or revoked, or EVVA put a creator on hold                      | The connection stays open — it serves your other creators. That creator's events stop, and you receive `grant.changed` or `access.revoked`. |

> **Warning**
>
> After a `4401`, reconnect **once** with a fresh token. If that is refused too, stop and check the application's
> status — retrying in a loop will not help.

## Close codes

| Reason                         | WebSocket | WebTransport | Reconnect with the same token? |
| ------------------------------ | --------- | ------------ | ------------------------------ |
| `CLIENT_CLOSED`                | 1000      | 1            | Yes                            |
| `SERVER_SHUTDOWN`              | 1001      | 8            | Yes                            |
| `PROTOCOL_VIOLATION`           | 4400      | 5            | No — fix the client            |
| `UNAUTHENTICATED`              | 4401      | 3            | No — get a new token           |
| `PROTOCOL_VERSION_UNSUPPORTED` | 4406      | 4            | No                             |
| `HANDSHAKE_TIMEOUT`            | 4408      | 2            | Yes                            |
| `FRAME_TOO_LARGE`              | 4413      | 6            | No                             |
| `CONNECTION_TOO_SLOW`          | 4429      | 10           | Yes                            |
| `CONNECTION_LIFETIME_EXCEEDED` | 4440      | 7            | Yes                            |
| `INTERNAL_ERROR`               | 4500      | 9            | Yes                            |

`error` frames carry one of: `INVALID_FRAME`, `SUBSCRIPTION_LIMIT_EXCEEDED`, `UNSUPPORTED_PROTOCOL_VERSION`,
`UNAUTHENTICATED`, `INTERNAL_ERROR`, `SESSION_REVOKED`, `RESUME_REJECTED`, `ACK_INVALID`, `SUBSCRIPTION_REVOKED`.

## When realtime is at capacity

If the realtime service is full, the WebSocket upgrade is refused with HTTP `503` and `Retry-After`. That is not an
authentication failure: wait at least `Retry-After` plus some random jitter, then reconnect with the same resume
request.

## Use an SDK

The official SDKs implement all of the above — hello, subscribe, ack after your handler, ping, reconnect with
full-jitter backoff, resume by cursor, a single retry with a fresh token after `4401` — and combine realtime with the
feed so a gap is always filled.

**`TypeScript`**

```typescript title="TypeScript"
const me = await evva.app.me();

const stream = evva.eventStream({
  consumerId: 'my-bot',
  applicationId: me.application.id, // the application's id — never the OAuth client id
  handler: async (event) => {
    console.log(event.type, event.creatorId, event.eventId);
  },
});
evva.shutdownOnSignals();
await stream.start();
```

**`Python`**

```python title="Python"
from evva_partner import PartnerEventStream, SQLiteStore

store = SQLiteStore("evva-state.db")  # durable checkpoint + dedup

async def on_event(event):
    print(event.type, event.creator_id, event.event_id)

# client: an AsyncEvvaPartnerClient
await PartnerEventStream(client, consumer_id="my-bot", handler=on_event,
                         checkpoints=store, dedup=store).run()
```

**`Go`**

```go title="Go"
checkpoints, _ := evvapartner.NewFileCheckpointStore("./state/checkpoints")
dedup, _ := evvapartner.OpenFileDedupStore("./state/dedup.log")

stream, _ := client.NewEventStream(evvapartner.EventStreamConfig{
	ConsumerID:  "my-bot",
	Checkpoints: checkpoints,
	Dedup:       dedup,
	Handler: func(ctx context.Context, ev *evvapartner.Event) error {
		log.Println(ev.Type, ev.CreatorID, ev.EventID)
		return nil // nil acknowledges; an error has the event delivered again
	},
})
log.Fatal(stream.Run(ctx))
```

**`PHP`**

```php title="PHP"
$evva->eventStream('my-bot', function (PartnerEvent $event, EventContext $ctx) { /* … */ },
    applicationId: $me->applicationId,
    checkpointStore: new PdoCheckpointStore($pdo), dedupStore: new PdoDedupStore($pdo))->run();
```

> **Note**
>
> WebTransport is available in the Go SDK. The PHP SDK uses WebSocket only; the semantics are identical.

## Next steps

#### [Event feed and consumer groups](/event-feed)

The durable record behind realtime.

#### [Event catalogue](/webhooks/events)

Every event type and its data.

#### [Requesting tokens](/authentication/tokens)

Get the token your hello frame carries.

#### [SDKs](/sdks/overview)

Event streams in four languages.