RPC error close 4001: unauthorized
Last updated:
At a glance
| Property | Value |
|---|---|
| Applies to | Robinhood Chain (chain ID 4663) |
| Close code | 4001 |
| Surface | wss://triport.io/ws/robinhood and /ws/robinhood-feed |
| Header | x-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
- Send the API key in the x-token header when your client supports headers.
- 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.
- 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.