Troubleshooting
4001 and 4003 are key or plan problems you must fix before retrying, 4008 means the client read too slowly or sent too much, 4029 means the key already has 2 connections, and 1006 or 1001 are network drops or a server restart. For every retryable close, reconnect with backoff and send your last cursor as since: you get back every event you missed from the last 24 hours.Included with Signal8 Pro, $29.50/mo or $294/yr. One API key covers the REST API, the MCP server and the streams.
| Code | Why it closed | Retry? |
|---|---|---|
| 4001 | Authentication: no auth message within 10 s (AUTH_TIMEOUT), another message before auth (AUTH_REQUIRED), or an invalid key (AUTH_FAILED). | No. Fix the key or the client first. |
| 4003 | Plan: the key is valid but its account does not include streams (PRO_REQUIRED). | No. Upgrade to Signal8 Pro first. |
| 4008 | Rate: more than 30 client messages in 10 s (RATE_LIMITED), or a client too slow to read, with over 4 MB waiting to be sent (SLOW_CONSUMER). | Yes, with backoff and your last cursor. Read faster or narrow your filters. |
| 4029 | Too many connections: the key already has 2 open (TOO_MANY_CONNECTIONS). | After closing another connection. |
| 4400 | API key in the URL (KEY_IN_URL): the handshake completes, one error frame is sent and the socket closes. | No. Send the key in the Authorization header, or in the auth message from a browser. |
| 4503 | Streams are switched off on our side (STREAMS_DISABLED). | Later, with backoff and your last cursor. |
| 1011 | Server-side failure. | Yes, with backoff and your last cursor. |
| 1001 | Server restart (SERVER_RESTART). | Yes, reconnect with your last cursor. |
1006 is not sent by us: it is what your library reports when the connection dropped with no close frame (a network change, a proxy or load balancer idle timeout, a laptop going to sleep). Treat it like 1001: reconnect with your cursor.
The server sends {"type":"heartbeat"} every 15 seconds even when nothing is filed. If nothing at all arrives for 45 seconds (three missed heartbeats), the link is dead even if your socket still says open: close it and reconnect. Both examples below do this with a watchdog.
A corporate proxy or load balancer with a short idle timeout can also cut a quiet connection. The heartbeat keeps the line busy, so if you still see drops at a fixed interval, check that interval against the proxy's timeout.
| Symptom | Fix |
|---|---|
4001 AUTH_TIMEOUT | Send the key in the Authorization header at the handshake, or send the auth message within 10 seconds of connecting. |
4001 AUTH_FAILED | The key is wrong or revoked. Get a current one from the API keys page. Do not retry in a loop. |
4003 PRO_REQUIRED | The key's account does not include streams. Upgrade to Signal8 Pro; do not retry until then. |
4400 KEY_IN_URL | Remove the key from the URL query string. Use the header, or the auth message from a browser. |
4029 TOO_MANY_CONNECTIONS | A key can hold 2 connections. An old process (a crashed worker, a second deploy, a dev laptop) is still connected. Close it, or use a second key, then reconnect. Put many filters on one connection: it takes 10 subscriptions. |
4008 SLOW_CONSUMER | More than 4 MB was waiting for your client to read. Hand events to a queue and return from the message handler at once, and narrow your filters. |
4008 RATE_LIMITED | The client sent more than 30 messages in 10 seconds, usually a subscribe or ping loop. Subscribe once after connecting. |
4503 STREAMS_DISABLED or 1011 | A problem on our side. Reconnect with backoff and your cursor. |
CURSOR_EXPIRED error frame | Your cursor is older than 24 hours. Not fatal: you get the last 24 hours, and anything older has to come from the REST API. |
Save cursor from each event after you have handled it. On reconnect, send it as since in the subscribe: the server replays everything after it, sends replay_complete, then carries on live. One cursor covers every channel in the subscription. Back off exponentially (1, 2, 4 seconds up to 30, plus some jitter) so a fleet of clients does not reconnect in the same second.
// npm install ws
import WebSocket from "ws";
const URL = "wss://api.signal8.ai/api/v1/stream";
const subscription = {
type: "subscribe",
id: "watch",
channels: ["filings", "filings.ai"],
filters: { tickers: ["XMPL"] },
};
let lastCursor = null; // Persist it (file, database) in production.
let attempt = 0;
function connect() {
const ws = new WebSocket(URL, {
headers: { Authorization: `Bearer ${process.env.SIGNAL8_API_KEY}` },
});
// A heartbeat arrives every 15 s. Three missed: treat the link as dead.
let watchdog;
const resetWatchdog = () => {
clearTimeout(watchdog);
watchdog = setTimeout(() => ws.terminate(), 45_000);
};
ws.on("open", () => {
attempt = 0;
resetWatchdog();
// One cursor covers every channel, so one since resumes the whole subscription.
ws.send(JSON.stringify(lastCursor ? { ...subscription, since: lastCursor } : subscription));
});
ws.on("message", (raw) => {
resetWatchdog();
const msg = JSON.parse(raw.toString());
if (msg.type === "replay_complete") console.log("caught up, live from here");
if (msg.type === "error") console.warn(msg.code, msg.message); // CURSOR_EXPIRED is not fatal
if (msg.type !== "event") return;
handle(msg);
lastCursor = msg.cursor; // save only after the event is handled
});
ws.on("close", (code) => {
clearTimeout(watchdog);
if (code === 4001 || code === 4003 || code === 4400) return; // bad key, no Pro plan or key in the URL: retrying will not help
const delay = Math.min(30_000, 1_000 * 2 ** attempt++) + Math.random() * 1_000;
setTimeout(connect, delay);
});
ws.on("error", () => {}); // "close" always follows and schedules the retry
}
function handle(msg) {
console.log(msg.channel, msg.id, msg.data);
}
connect();
# pip install websockets
import asyncio, json, os, random
import websockets
URL = "wss://api.signal8.ai/api/v1/stream"
HEADERS = {"Authorization": f"Bearer {os.environ['SIGNAL8_API_KEY']}"}
SUBSCRIPTION = {
"type": "subscribe",
"id": "watch",
"channels": ["filings", "filings.ai"],
"filters": {"tickers": ["XMPL"]},
}
last_cursor = None # Persist it in production.
def handle(msg):
print(msg["channel"], msg["id"], msg["data"])
async def run_once():
global last_cursor
async with websockets.connect(URL, additional_headers=HEADERS) as ws:
sub = dict(SUBSCRIPTION, since=last_cursor) if last_cursor else SUBSCRIPTION
await ws.send(json.dumps(sub))
while True:
# Heartbeat every 15 s; 45 s of silence means the link is dead.
raw = await asyncio.wait_for(ws.recv(), timeout=45)
msg = json.loads(raw)
if msg["type"] == "event":
handle(msg)
last_cursor = msg["cursor"] # save only after the event is handled
async def main():
attempt = 0
while True:
try:
await run_once()
except websockets.ConnectionClosed as exc:
if exc.rcvd and exc.rcvd.code in (4001, 4003, 4400):
raise # bad key, no Pro plan or key in the URL: retrying will not help
except (OSError, asyncio.TimeoutError):
pass
await asyncio.sleep(min(30, 2 ** attempt) + random.random())
attempt += 1
asyncio.run(main())
Events can arrive twice around a reconnect. Use the event id to drop duplicates. For more, see the protocol reference and the Python streaming tutorial.
Email [email protected] with the error code, the time it happened in UTC and the endpoint or MCP client you used. Never send your API key.
Included with Signal8 Pro, $29.50/mo or $294/yr. One API key covers the REST API, the MCP server and the streams.