Documentation · WebSocket

WebSocket API

The live news event stream. Connect once and receive every fully-enriched news item as it is published.


Endpoint

wss://ai-hub.cryptobriefing.com/ws/pm/v2/news

Authentication

Pass your API key as a query parameter on the WebSocket upgrade request.

bashbash
wscat -c "wss://ai-hub.cryptobriefing.com/ws/pm/v2/news?api_key=$VERA_KEY"

WebSocket streaming requires a Pro or Enterprise plan; Free and Builder requests are rejected at the handshake with feature_not_in_plan.

WebSocket authPass your API key via the api_key query parameter on the upgrade request. Header-based authentication for WebSocket connections is on the roadmap.

Message format

The WebSocket is a global broadcast: all authenticated subscribers receive every fully-enriched news item. Client-side filtering (e.g. by news_event.feed_categories) is your responsibility.

server to client (news item)json
{
  "type": "data",
  "content": {
    "news_event": { ... },
    "related_markets": [ ... ],
    "meta": { ... }
  },
  "is_backfill": false
}

The content field contains the same NewsV2Item schema as the /pm/v2/news REST endpoint.

Connection lifecycle

On successful connection, you receive a confirmation message:

server to clientjson
{
  "type": "connected",
  "message": "Connection established. Subscribed to /pm/v2/news."
}

Heartbeats

The server sends periodic ping frames. Your client should respond with a pong. Most WebSocket libraries do this automatically; check yours.

If a pong is not received in time, the server closes the connection. Your client should auto-reconnect with exponential backoff (start at 1s, max 30s, jitter ±20%).

Reference client

vera-ws.tsts
import WebSocket from "ws";

const ws = new WebSocket(
  `wss://ai-hub.cryptobriefing.com/ws/pm/v2/news?api_key=${process.env.VERA_KEY!}`
);

ws.on("open", () => {
  console.log("Connected to Vera WebSocket");
});

ws.on("message", (raw) => {
  const msg = JSON.parse(raw.toString());

  if (msg.type === "connected") {
    console.log(msg.message);
    return;
  }

  if (msg.type === "data") {
    const item = msg.content;
    console.log(item.news_event.headline);
    for (const rm of item.related_markets) {
      for (const sm of rm.sub_markets) {
        console.log(
          sm.sub_market_title,
          sm.news_effect.affected_outcome,
          sm.news_effect.effect
        );
      }
    }
  }
});

ws.on("close", (code, reason) => {
  console.warn("Vera WS closed:", code, reason.toString());
  // Reconnect with exponential backoff
});

Error frames

Protocol errors (invalid JSON, unrecognised message types) come back as type: "error" messages without closing the connection. Authentication failures close the connection with a WebSocket close code.

Close codeReason
1008Policy Violation: invalid or revoked API key, invalid or expired token, missing authentication, or connection limit reached
1001Server going away (planned maintenance); reconnect with backoff
1011Internal server error; reconnect with backoff

Coming soon

  • Market-level subscriptions (filter the stream server-side instead of client-side)
  • Backfill on reconnect (pass a resume_from event id)
  • Header-based authentication for the WebSocket upgrade