Skip to main content
The WebSocket stream delivers tweets for your filter rules and monitored accounts in real time.

One connection per API key

Each API key can have one WebSocket connection at a time.
  • If a new connection opens with the same API key, the new connection takes over. The older connection receives a replaced event and is closed with code 4001.
  • Messages the old connection had already taken but not delivered are re-sent to the new connection.
  • If you see 4001, another process is using your key. Do not reconnect the client that received 4001, or the two clients will keep kicking each other off.

Errors before the connection opens

If the server refuses a connection, it answers the handshake with a normal HTTP error and a JSON body. Most WebSocket libraries expose this as a failed handshake with a status code. Example body:

Events and close codes after the connection opens

The server also sends WebSocket protocol pings. Standard libraries answer them automatically. A connection that stops answering (for example after a network drop) is closed after about 50 seconds.

Reconnecting safely

  • Close the old connection before you open a new one, and run only one client per API key.
  • After a normal disconnect, wait at least 5 seconds before reconnecting, and back off if it keeps failing.
  • On 4029, wait Retry-After seconds.
  • On 4001 or 4009, stop. Another client is using the key.
  • On 4003, stop and fix the API key.

Sample client (Python)