Websocket

The NLX WebSocket API provides a persistent, bidirectional connection to your AI apps. Unlike the REST API, which requires a new HTTP handshake for every turn, the WebSocket interface allows for lower latency communication and real-time event streaming.

When to use this API

Voice interfaces

Where latency is critical

Real-time games/avatars

Where connection state needs to be maintained continuously

High-frequency chat

Applications with very rapid back-and-forth interactions

Connection lifecycle

Connect (/connect)

To establish a connection, open a standard WebSocket connection to the server. All routing and authentication information is passed via query parameters.

URL pattern: wss://us-east-1-ws.apps.nlx.ai

Query parameters:

  • apiKey (Required) Your NLX API Key

  • deploymentKey (Required) The unique identifier for your AI app deployment

  • channelKey (Required) The channel identifier including language suffix (e.g., xxxxxxxx-en-US)

  • conversationId (Optional) ID to resume a previously active session

Example:

Connection acknowledgement:

Upon successful connection, the server will send a JSON message containing the conversationId

Send message (/message)

To send a user turn, send a JSON payload matching the ConversationRequest structure used in the REST API.

Payload:

Receive response

The server will push messages asynchronously. The payload structure matches the ConversationResponse from the REST API.

Payload:

Disconnect (/disconnect)

To end the session, simply close the WebSocket connection from the client side.

The server identifies disconnected sessions using the connectionId internal header. No manual API call is required to cleanup the session state on the backend; simply dropping the socket triggers the disconnect logic.

Last updated