Docsv1.0
Docs/Reference/SSE Endpoint

SSE Endpoint

Connection details, headers, and error handling for the event stream.

Endpoint

GET https://tizemint.com/api/tip-events/stream

Authentication

One of the two is required. If both are provided, the query parameter takes precedence.

Response Headers

On a successful connection, the server responds with:

HeaderValue
Content-Typetext/event-stream
Cache-Controlno-cache, no-transform
Connectionkeep-alive
X-Accel-Bufferingno

Connection Lifecycle

  1. Client opens the SSE connection with a valid token.
  2. Server authenticates the token (prefix lookup + SHA-256 hash comparison).
  3. Server opens an upstream WebSocket to the overlay-sync worker for your profile.
  4. A {"type":"connected"} event is sent to confirm the stream is live.
  5. Tip events are forwarded as they arrive. Only events with a tip:* type prefix pass through.
  6. The stream ends when any of these occur:
    • The Vercel function reaches its 300-second (5 minute) timeout.
    • The client disconnects.
    • The upstream WebSocket closes unexpectedly.

Error Responses

The endpoint returns standard HTTP errors before the stream opens:

CodeReason
401Missing token, invalid token, token hash mismatch, or expired token.
502The overlay-sync worker is unreachable or NEXT_PUBLIC_OVERLAY_SYNC_URL is not configured.

Once the SSE stream is open, errors are not sent as HTTP status codes — the connection simply closes.

Client Examples

Using EventSource

The browser EventSource API handles SSE connections natively, including automatic reconnection:

js
const source = new EventSource(
  "https://tizemint.com/api/tip-events/stream?token=YOUR_TOKEN"
);
 
source.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log(data.type, data);
};
 
source.onerror = () => {
  // EventSource auto-reconnects with exponential backoff.
  // No action needed unless you want to log or update UI.
};
Info
EventSource does not support custom headers. Use the ?token= query parameter for browser-based clients.

Using fetch (Node.js / Deno)

For server-side consumers that need header-based auth:

js
const response = await fetch(
  "https://tizemint.com/api/tip-events/stream",
  { headers: { Authorization: "Bearer YOUR_TOKEN" } }
);
 
const reader = response.body.getReader();
const decoder = new TextDecoder();
 
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
 
  const text = decoder.decode(value);
  for (const line of text.split("\n")) {
    if (line.startsWith("data: ")) {
      const data = JSON.parse(line.slice(6));
      console.log(data.type, data);
    }
  }
}

What Happens When the WebSocket Closes

The SSE endpoint bridges your client to an internal WebSocket. If the WebSocket drops (e.g., worker restart), the SSE stream closes cleanly. EventSource clients reconnect automatically; custom consumers should implement retry logic (see Rate Limits).