Skip to docs content

WebSocket quickstart

Add one monitored account, open a server-side WebSocket, and print each v1 envelope.

Get your API key
Open in chat
Reviewed against product code on September 24, 2026

Run a 5-minute smoke test

Add one monitored account, copy the example, and run it. TweetStream connected confirms authentication. Events appear when that account posts.

// bun add ws
// TWEETSTREAM_API_KEY=ts_... bun run smoke.ts
import WebSocket from "ws";
 
const apiKey = process.env.TWEETSTREAM_API_KEY;
if (!apiKey) {
  throw new Error("Missing TWEETSTREAM_API_KEY");
}
 
const ws = new WebSocket("wss://ws-global.tweetstream.io/ws", [
  "tweetstream.v1",
  `tweetstream.auth.token.${apiKey}`,
]);
 
ws.on("open", () => {
  console.log("TweetStream connected");
});
 
ws.on("message", (raw) => {
  const event = JSON.parse(raw.toString());
  console.log(event.t, event.op, event.d);
});
 
ws.on("close", (code, reason) => {
  console.log("TweetStream closed", code, reason.toString());
});
 
ws.on("unexpected-response", (_request, response) => {
  console.error(
    "Connection rejected",
    response.statusCode,
    response.statusMessage,
  );
  response.resume();
  process.exitCode = 1;
});
 
ws.on("error", (error) => {
  console.error("WebSocket error", error.message);
});

Route operations

Each event names its family in t and its operation in op. The delivery reference lists all 18 server operations.

Make it durable