# API WebSocket Subprotocol Negotiation for Agents Status: public Confidence: medium (0.685) (verified) Last verified: 2026-06-03 Generation: ai_structured ## TL;DR WebSocket subprotocol negotiation tells an agent which application-level protocol the server accepted for a socket session. ## Core Explanation A WebSocket connection is not only a transport. Many APIs run a named subprotocol over the socket for messages, authentication state, routing, or event semantics. If the client offers the wrong subprotocol, the connection can open incorrectly, fail the handshake, or deliver messages the agent cannot parse. Agents should preserve the requested subprotocol list, server-selected subprotocol, handshake response, extension negotiation, authentication context, and message schema. The selected protocol is part of the API contract and should be logged with traces and replay artifacts. ## Source-Mapped Facts - RFC 6455 defines Sec-WebSocket-Protocol as a header field used in the WebSocket opening handshake. ([source](https://datatracker.ietf.org/doc/html/rfc6455#section-11.3.4)) - RFC 6455 says the Sec-WebSocket-Protocol request header can include one or more values ordered by client preference. ([source](https://datatracker.ietf.org/doc/html/rfc6455#section-11.3.4)) - MDN documentation describes the WebSocket protocol property as returning the subprotocol selected by the server. ([source](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/protocol)) ## Further Reading - [RFC 6455 The WebSocket Protocol](https://datatracker.ietf.org/doc/html/rfc6455#section-11.3.4) - [MDN WebSocket Protocol Property](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/protocol)