> ## Documentation Index
> Fetch the complete documentation index at: https://www.helius.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Use getHealth

> Learn getHealth use cases, code examples, request parameters, response structure, and tips.

The [`getHealth`](https://www.helius.dev/docs/api-reference/rpc/http/gethealth) endpoint is used to check the current health status of a Solana RPC node. A healthy node is generally considered to be one that is operational and reasonably synchronized with the rest of the cluster (specifically, within a certain slot distance of the latest cluster confirmed slot, known as `HEALTH_CHECK_SLOT_DISTANCE`).

This endpoint is crucial for monitoring node health, especially for applications or infrastructure that rely on the availability and reliability of an RPC node.

## How it Works

The `getHealth` method uses the standard JSON-RPC POST mechanism with the method `getHealth`. This method checks if the RPC node is healthy and synchronized with the Solana cluster.

## Common Use Cases

* **Node Monitoring:** Regularly check the health of RPC nodes to ensure they are operational and synchronized.
* **Load Balancing:** Use health checks to determine if a node should receive traffic in a load-balanced setup.
* **Failover Systems:** Trigger failover to a backup node if a primary node becomes unhealthy.
* **Debugging Connectivity:** Quickly ascertain if an RPC node is responsive.

## Request Parameters

This method does not take any parameters.

## Response Structure

* **For JSON-RPC `getHealth` POST:**
  * **`result`**: `"ok"` if the node is healthy.
  * It might return an error object or other string values (like `"behind"` or `"unknown"`) if unhealthy, though the exact error response for an unhealthy node can be unstable or vary between providers.

## Examples

### 1. Check Node Health using JSON-RPC (POST with cURL)

<CodeGroup>
  ```bash cURL (JSON-RPC POST) theme={"system"}
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getHealth"
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  const { Connection } = require('@solana/web3.js');

  async function checkRpcHealth(rpcUrl) {
      const connection = new Connection(rpcUrl);
      try {
          const health = await connection.rpcRequest('getHealth', []);
          console.log(`getHealth result for ${rpcUrl}:`, health);
          return health.result;
      } catch (error) {
          console.error(`Error calling getHealth for ${rpcUrl}:`, error.message);
          return null;
      }
  }

  // Example usage:
  checkRpcHealth('https://mainnet.helius-rpc.com/?api-key=<api-key>');
  ```
</CodeGroup>

**Expected JSON-RPC response (for a healthy node):**

```json theme={"system"}
{
  "jsonrpc": "2.0",
  "result": "ok",
  "id": 1
}
```

## Developer Tips

* **Definition of Healthy:** "Healthy" generally means the node is responsive and not too far behind the cluster's tip. The exact slot difference (`HEALTH_CHECK_SLOT_DISTANCE`) can be configured on the node.
* **Interpreting `"behind"` or `"unknown"`:** If you receive `"behind {distance}"` or `"unknown"`, the node is operational but may not be fully caught up or able to ascertain its status relative to the cluster. Depending on your application's requirements, you might treat these states differently.
* **Provider Differences:** The exact behavior and response codes/bodies for an unhealthy node might vary slightly between RPC providers.
* **Error Handling:** Always implement proper error handling when calling `getHealth`, as network issues or node problems can cause the request to fail entirely.

This guide provides the necessary information to use the `getHealth` endpoint for monitoring the status of a Solana RPC node.
