RPC error close 4001: unauthorized

Last updated:

At a glance

Error details
PropertyValue
Applies toRobinhood Chain (chain ID 4663)
Close code4001
Surfacewss://triport.io/ws/robinhood and /ws/robinhood-feed
Headerx-token: $TRIPORT_API_KEY

Cause

A Robinhood WebSocket connection is authenticated at handshake time. Without a key the server closes the socket with code 4001. Browsers and some libraries cannot attach custom headers to a WebSocket, which is the most common reason the header never arrives.

Solution

  1. Send the API key in the x-token header when your client supports headers.
  2. Otherwise connect to wss://triport.io/ws/robinhood/<API_KEY> (or /ws/robinhood-feed/<API_KEY> for the feed) and keep that URL out of logs.
  3. Verify the key works over HTTPS first with a plain eth_blockNumber call.

FAQ

Why does my browser client always get 4001?
Browsers cannot set custom WebSocket headers. Use the keyed URL form instead of x-token.
Is the keyed URL as safe as the header?
It is the same credential in a less private place: it can land in logs and history. Prefer the header wherever your client allows it.