Lifecycle & Limits
A WebSocket connection does not last forever. This page lists the timers and limits, what the server does when one is reached, and what your client should do. The client libraries follow these rules for you.
Timers at a glance
| What | Value | Your client |
|---|---|---|
| Ping interval | 25 seconds | Send {"action":"ping","t":...} every 25 s. |
| Pong watchdog | 60 seconds | No pong for 60 s: close and reconnect. |
| Stale connection | 60 seconds without a ping | The connection no longer counts against your limit. |
| Idle timeout | 10 minutes | The gateway closes a connection with no traffic. Regular pings prevent it. |
| Maximum lifetime | 2 hours | The gateway closes every connection after 2 h. Rotate before that, at about 115 minutes. |
Ping and pong
Send a ping every 25 seconds:
Ping
{ "action": "ping", "t": 1795467870123 }
- The
"action": "ping"key sends the message to the ping route. A ping without it (for example{"type": "ping"}) is read as a subscribe and answered with an error in the v2 form:{"action":"error","error":"Ping messages should be sent to the ping route"}. Only when that message also carries"payloadVersion": 3is the answerconnection.errorwith codePING_ON_DEFAULT_ROUTE. tis any number of your choice, for example the current time in milliseconds. The pong echoes it, so you can measure the round trip.- The answer is
connection.pong. Before your first subscribe it comes in the v2 form{"action":"pong", ...}. Both count as a pong. - Each ping also tells the server that the connection is alive. A connection without a ping for more than 60 seconds is stale: it no longer counts against your connection limit, and a new connection can take its place.
Keep a watchdog: when no pong of either form arrived for 60 seconds, close the socket, connect again and send the same subscribe.
connection.pong
{ "event": "connection.pong", "payloadVersion": 3, "data": { "t": 1795467870123, "serverNow": 1795467870160 } }
Two hour limit and rotation
The gateway closes every connection after 2 hours. To avoid a gap, rotate before that, at about 115 minutes:
- Open a new connection while the old one is still open.
- Send the same subscribe on the new connection.
- When the new connection sends
connection.admitted, close the old one. - Drop duplicates between the two connections. The new connection starts with the initial push, which you may already have.
If your plan allows only one connection, the old one still counts and the new one is refused with 403 Too many concurrent connections. .... In that case close the old connection first, wait for the close to finish, and connect again at once. The gap is about one connection setup long. Only if that second attempt is refused too, wait as described below.
Do not use takeover for rotation. It works, but the old connection then receives connection.preempted with reason connection_limit, which a client should treat as "stop".
Reconnect rules
| Situation | What to do |
|---|---|
| Connect refused with 401 | Stop. The key is missing or wrong. |
Connect refused with 403 Your subscription does not include WebSockets | Stop. Your plan has no WebSocket access. |
connection.error with VALIDATION_FAILED | Stop. Fix the subscribe message. |
connection.preempted with reason connection_limit | Stop. Another of your connections took over. |
Close with code 1008 | Stop. |
Connect refused with 403 Too many concurrent connections. ... | Wait at least 60 s, then try again. Or close another connection. |
Connect refused with 403 WebSocket quota exceeded for the current period, or connection.preempted with reason quota_exceeded | Wait for the next period. Try again once per hour. |
Connect refused with 403 Too many concurrent connections (without the takeover hint) | Reconnect after a short, growing wait. |
Connect refused with 5xx, HANDSHAKE_FAILED, SEARCH_FAILED, pong watchdog, any other close | Reconnect after a short, growing wait. |
PING_ON_DEFAULT_ROUTE, INTERNAL_ERROR, unknown codes and unknown events | Log and continue. |
A good growing wait starts at 1 second, doubles up to 30 seconds, and starts over only after a pong or an article arrived. Do not reset it on connection.admitted: it comes before the server checks your subscribe, so a loop of "admitted, then closed" must still slow down.
After every reconnect, send the same subscribe again. The server does not remember it.
Preemption
The server can end a connection on purpose. It sends connection.preempted first and then closes the connection.
connection_limit: you connected again with takeover while at your limit, and this was your stalest connection.newLeaseIdis theleaseIdof the new connection. Do not reconnect from the old one, or two clients replace each other in a loop.quota_exceeded: the WebSocket delivery quota of this period is used up. Every connection of yours receives this frame and is closed.newLeaseIdisnull. New connections are refused with 403 until the next period starts.
A connection that never sent a subscribe receives the frame in the v2 form, {"action":"preempted", ...}. See Frames.
WebSocket quota
Each live article frame the server sends to you counts against the WebSocket delivery quota of your plan. The count is taken before the frame goes out, so these count too: a frame that is dropped because it is larger than 32,000 bytes, a frame for a connection that has already closed, and an article.updated that is not sent because your plan sees none of its changes. The initial push and control frames do not. WebSocket deliveries do not use credits. When the quota is used up:
- All your connections receive
connection.preemptedwith reasonquota_exceededand are closed. - New connections are refused with 403
WebSocket quota exceeded for the current period. - At the start of the next period you can connect again.
The client libraries keep the stream alive in this case: they try again once per hour and report each wait to a hook. You can switch that off to end the stream instead. See Rate limits & credits for the quotas of each plan.
Plan changes
The server reads your plan when it sends each live frame. It keeps the plan in a cache for up to 10 minutes, so an upgrade or downgrade can take that long to show in the blocks you receive. The initial push after a subscribe uses the plan from the moment you connected. Reconnect to pick up a new plan for it at once.
Fill gaps after a reconnect
While you are disconnected, articles are not stored for you. The stream does not replay them, and the client libraries do not backfill on their own. Fill the gap through REST:
- On the enriched stream, remember the newest
availableAtyou received. After the reconnect, search withorderBy: "availableAt",order: "asc"andfromset to that time. - On the raw stream,
availableAtis alwaysnull. UsefirstSeenAtwithorderBy: "firstSeenAt"instead. - Use the same filters as your subscription. On REST,
languagebecomes the listlanguages, and the query is checked strictly: an unknown field is a 400 there. - Drop articles you already have by
id. - Every page costs one credit. See Rate limits & credits.
The client libraries give you the last time they saw in their reconnect hook (lastSeenAt in TypeScript, last_seen_at in Python).
Fill a gap
curl -X POST https://api.finlight.me/v3/articles/search \
-H "X-API-KEY: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "ticker:NVDA",
"languages": ["en"],
"orderBy": "availableAt",
"order": "asc",
"from": "2026-11-24T18:45:54.657Z",
"include": ["companies", "events"],
"limit": 100
}'