# Streaming

Using WebSockets provides the ability to stream responses back to a client in order to allow partial results for certain requests. This improves the perceived responsiveness of applications and offers a better user experience.

The **WebSocket url** is `https://api.lingoblocks.com`.

### Message Streaming

Stream a message response back to a client as it's being generated.

* **WebSocket URL**: `https://api.lingoblocks.com`
* &#x20;**Requirements**:
  * `accessToken`: The existing access token for the session (see [Authentication](/docs/api/authentication.md)).
  * `socket.io-client`: WebSocket client library (see [npm package](https://www.npmjs.com/package/socket.io-client)).

#### Setup and Connection

1. Import `socket.io-client` to create a WebSocket connection.

```javascript
import { io } from "socket.io-client";
```

2. Initialize socket connection.

```javascript
const options = {
  transportOptions: {
    polling: {
      extraHeaders: {
        "access-token": "<access-token>"
      }
    }
  }
};

const socket = io("https://api.lingoblocks.com", options);
```

#### Receiving Messages

* Listen for messages on the `message` event.
* Filter messages by checking if the event data matches `chatbot.responseGenerated`.
* Process the streamed message data.

```javascript
socket.on("message", (eventData) => {
  if (eventData.event === "chatbot.responseGenerated") {
    console.log("Streaming message data:", eventData.data);
  }
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lingoblocks.com/docs/api/streaming.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
