> For the complete documentation index, see [llms.txt](https://docs.infoway.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.infoway.io/en-docs/websocket/heartbeat.md).

# Heartbeat

### Overview

To keep a WebSocket session active, clients must periodically send a **heartbeat message** to the server. If the server does not receive a heartbeat within **one minute**, the connection is considered **inactive** and will be **terminated automatically**.

Implement a recurring heartbeat routine on the client side to ensure the connection remains open. See the example below for reference.

### Rate Limits

Each WebSocket connection is limited to **60 total messages per minute**, including **subscribe**, **unsubscribe**, and **heartbeat** messages.

If this limit is exceeded:

* The connection will be **automatically closed**.
* Repeated violations may be treated as **abuse**, and the associated **API Key** may be **suspended**.

Design your message-sending logic carefully to stay within these limits.

### **Error Code Explanation**

Please refer to the [WebSocket error code](/en-docs/getting-started/error-codes/websocket-error-codes.md) documentation for further details.

### **Subscription Address**

Please refer to the [WebSocket subscription addresses](#subscription-address).

### Heartbeat Message (Protocol Number: 10010)

```json
{
    "code": 10010,
    "trace": "423afec425004bd8a5e02e1ba5f9b2b0"
}
```

### Parameters

| Field   | Type    | Required | Description                                                                                  | Example                            |
| ------- | ------- | -------- | -------------------------------------------------------------------------------------------- | ---------------------------------- |
| `code`  | Integer | Yes      | The message type identifier. Use `10010` to indicate a heartbeat message.                    | `10010`                            |
| `trace` | String  | Yes      | A unique request ID used for tracking and debugging. Typically a random UUID or hash string. | `423afec425004bd8a5e02e1ba5f9b2b0` |

### Notes

* **Send heartbeats regularly**, typically every **30 seconds**.
* If no heartbeat is received for **more than 60 seconds**, the server will close the connection.
* The `trace` field should be **unique per message** to make it easier to trace and debug message logs.
* Keep the **aggregate send rate** (including all message types) below **60 per minute** to avoid throttling or key suspension.
* If the connection closes due to timeout, the client should **reconnect and re-subscribe** to restore the session.
