> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/cloudflare/cloudflare-typescript/llms.txt
> Use this file to discover all available pages before exploring further.

# Healthchecks

> Monitor origin server health and availability

The Healthchecks API allows you to configure and manage health checks for your origin servers. Health checks monitor your origins and can detect when they become unhealthy.

## Create health check

Create a new health check for a zone.

```typescript theme={null}
const healthcheck = await client.healthchecks.create({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
  address: 'www.example.com',
  name: 'server-1',
  check_regions: ['WNAM', 'ENAM'],
  type: 'HTTPS',
  http_config: {
    method: 'GET',
    path: '/health',
    expected_codes: ['200'],
    follow_redirects: false,
    allow_insecure: false,
    header: {
      'Host': ['www.example.com']
    }
  },
  interval: 60,
  retries: 2,
  timeout: 5,
  consecutive_fails: 3,
  consecutive_successes: 2
});
```

<ParamField path="zone_id" type="string" required>
  Zone identifier
</ParamField>

<ParamField body="address" type="string" required>
  The hostname or IP address of the origin server to run health checks on
</ParamField>

<ParamField body="name" type="string" required>
  A short name to identify the health check. Only alphanumeric characters, hyphens, and underscores are allowed
</ParamField>

<ParamField body="type" type="string">
  The protocol to use for the health check

  Options: `HTTP` | `HTTPS` | `TCP`
</ParamField>

<ParamField body="check_regions" type="string[] | null">
  A list of regions from which to run health checks. Null means Cloudflare will pick a default region

  Options: `WNAM`, `ENAM`, `WEU`, `EEU`, `NSAM`, `SSAM`, `OC`, `ME`, `NAF`, `SAF`, `IN`, `SEAS`, `NEAS`, `ALL_REGIONS` (Business and Enterprise only)
</ParamField>

<ParamField body="description" type="string">
  A human-readable description of the health check
</ParamField>

<ParamField body="interval" type="number">
  The interval between each health check in seconds. Shorter intervals may give quicker notifications but will increase load on the origin
</ParamField>

<ParamField body="retries" type="number">
  The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately
</ParamField>

<ParamField body="timeout" type="number">
  The timeout (in seconds) before marking the health check as failed
</ParamField>

<ParamField body="consecutive_fails" type="number">
  The number of consecutive fails required from a health check before changing the health to unhealthy
</ParamField>

<ParamField body="consecutive_successes" type="number">
  The number of consecutive successes required from a health check before changing the health to healthy
</ParamField>

<ParamField body="suspended" type="boolean">
  If suspended, no health checks are sent to the origin
</ParamField>

<ParamField body="http_config" type="object | null">
  Parameters specific to an HTTP or HTTPS health check

  <Expandable>
    <ParamField body="method" type="string">
      The HTTP method to use for the health check

      Options: `GET` | `HEAD`
    </ParamField>

    <ParamField body="path" type="string">
      The endpoint path to health check against
    </ParamField>

    <ParamField body="expected_codes" type="string[] | null">
      The expected HTTP response codes (e.g., "200") or code ranges (e.g., "2xx")
    </ParamField>

    <ParamField body="expected_body" type="string">
      A case-insensitive sub-string to look for in the response body. If not found, the origin will be marked as unhealthy
    </ParamField>

    <ParamField body="follow_redirects" type="boolean">
      Follow redirects if the origin returns a 3xx status code
    </ParamField>

    <ParamField body="allow_insecure" type="boolean">
      Do not validate the certificate when the health check uses HTTPS
    </ParamField>

    <ParamField body="header" type="object | null">
      The HTTP request headers to send in the health check. It is recommended to set a Host header. The User-Agent header cannot be overridden
    </ParamField>

    <ParamField body="port" type="number">
      Port number to connect to (defaults to 80 for HTTP or 443 for HTTPS)
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="tcp_config" type="object | null">
  Parameters specific to TCP health check

  <Expandable>
    <ParamField body="method" type="string">
      The TCP connection method to use

      Options: `connection_established`
    </ParamField>

    <ParamField body="port" type="number">
      Port number to connect to for the health check (defaults to 80)
    </ParamField>
  </Expandable>
</ParamField>

## Response fields

<ResponseField name="id" type="string">
  Health check identifier
</ResponseField>

<ResponseField name="address" type="string">
  The hostname or IP address of the origin server
</ResponseField>

<ResponseField name="name" type="string">
  Health check name
</ResponseField>

<ResponseField name="status" type="string">
  The current status of the origin server according to the health check

  Options: `unknown` | `healthy` | `unhealthy` | `suspended`
</ResponseField>

<ResponseField name="failure_reason" type="string">
  The current failure reason if status is unhealthy
</ResponseField>

<ResponseField name="type" type="string">
  The protocol used for the health check
</ResponseField>

<ResponseField name="check_regions" type="string[] | null">
  Regions from which health checks are run
</ResponseField>

<ResponseField name="created_on" type="string">
  When the health check was created
</ResponseField>

<ResponseField name="modified_on" type="string">
  When the health check was last modified
</ResponseField>

<ResponseField name="interval" type="number">
  Interval between health checks in seconds
</ResponseField>

<ResponseField name="retries" type="number">
  Number of retries before marking as unhealthy
</ResponseField>

<ResponseField name="timeout" type="number">
  Timeout in seconds
</ResponseField>

<ResponseField name="consecutive_fails" type="number">
  Consecutive fails required to mark as unhealthy
</ResponseField>

<ResponseField name="consecutive_successes" type="number">
  Consecutive successes required to mark as healthy
</ResponseField>

<ResponseField name="suspended" type="boolean">
  Whether health checks are suspended
</ResponseField>

<ResponseField name="http_config" type="object | null">
  HTTP/HTTPS health check configuration
</ResponseField>

<ResponseField name="tcp_config" type="object | null">
  TCP health check configuration
</ResponseField>

## List health checks

List all configured health checks for a zone.

```typescript theme={null}
for await (const healthcheck of client.healthchecks.list({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353'
})) {
  console.log(healthcheck.name, healthcheck.status);
}
```

## Get health check

Retrieve a single configured health check.

```typescript theme={null}
const healthcheck = await client.healthchecks.get(
  '023e105f4ecef8ad9ca31a8372d0c353',
  { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);
```

## Update health check

Update all properties of a configured health check.

```typescript theme={null}
const healthcheck = await client.healthchecks.update(
  '023e105f4ecef8ad9ca31a8372d0c353',
  {
    zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
    address: 'www.example.com',
    name: 'server-1-updated',
    interval: 90
  }
);
```

## Edit health check

Patch specific properties of a configured health check.

```typescript theme={null}
const healthcheck = await client.healthchecks.edit(
  '023e105f4ecef8ad9ca31a8372d0c353',
  {
    zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
    address: 'www.example.com',
    name: 'server-1',
    suspended: true
  }
);
```

## Delete health check

Delete a health check.

```typescript theme={null}
const result = await client.healthchecks.delete(
  '023e105f4ecef8ad9ca31a8372d0c353',
  { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);
```

<ResponseField name="id" type="string">
  ID of the deleted health check
</ResponseField>
