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

# Health Check

> Check the health status of the Submagic API

# Health Check

The health endpoint provides a simple way to check if the Submagic API is operational. This endpoint does not require authentication and can be used for monitoring and health checks.

<Note>
  This endpoint does not require authentication and is not subject to rate
  limiting.
</Note>

## Request

<ParamField path="No parameters" type="void">
  This endpoint does not accept any parameters.
</ParamField>

## Response

<ResponseField name="status" type="string">
  The current status of the API service
</ResponseField>

<ResponseField name="service" type="string">
  The name of the service
</ResponseField>

<ResponseField name="timestamp" type="string">
  ISO 8601 timestamp of when the response was generated
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.submagic.co/health"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api.submagic.co/health");
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.get('https://api.submagic.co/health')
  data = response.json()
  print(data)
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "status": "healthy",
    "service": "submagic-public-api",
    "timestamp": "2024-01-15T10:30:00.000Z"
  }
  ```
</ResponseExample>

## Use Cases

<CardGroup cols={2}>
  <Card title="Uptime Monitoring" icon="chart-line">
    Use this endpoint to monitor API availability in your monitoring systems
  </Card>

  <Card title="Load Balancer Health Checks" icon="server">
    Configure your load balancer to use this endpoint for health checks
  </Card>

  <Card title="CI/CD Pipeline Validation" icon="code-branch">
    Verify API availability before running integration tests
  </Card>

  <Card title="Status Page Integration" icon="clock">
    Include this endpoint in your status page monitoring
  </Card>
</CardGroup>

## Status Values

| Status      | Description                                     |
| ----------- | ----------------------------------------------- |
| `healthy`   | API is operational and ready to accept requests |
| `degraded`  | API is operational but experiencing issues      |
| `unhealthy` | API is not operational                          |

## Example Monitoring Script

Here's a simple monitoring script you can use:

<CodeGroup>
  ```bash Bash theme={null}
  #!/bin/bash
  response=$(curl -s -o /dev/null -w "%{http_code}" https://api.submagic.co/health)
  if [ $response -eq 200 ]; then
      echo "API is healthy"
      exit 0
  else
      echo "API is not responding (HTTP $response)"
      exit 1
  fi
  ```

  ```javascript Node.js theme={null}
  const checkHealth = async () => {
    try {
      const response = await fetch("https://api.submagic.co/health");
      const data = await response.json();

      if (response.ok && data.status === "healthy") {
        console.log("✅ API is healthy");
        return true;
      } else {
        console.log("❌ API is not healthy:", data);
        return false;
      }
    } catch (error) {
      console.log("❌ Failed to check API health:", error.message);
      return false;
    }
  };

  // Run health check every 30 seconds
  setInterval(checkHealth, 30000);
  ```

  ```python Python theme={null}
  import requests
  import time
  import sys

  def check_health():
      try:
          response = requests.get('https://api.submagic.co/health', timeout=10)
          data = response.json()

          if response.status_code == 200 and data.get('status') == 'healthy':
              print('✅ API is healthy')
              return True
          else:
              print(f'❌ API is not healthy: {data}')
              return False
      except Exception as e:
          print(f'❌ Failed to check API health: {e}')
          return False

  if __name__ == '__main__':
      is_healthy = check_health()
      sys.exit(0 if is_healthy else 1)
  ```
</CodeGroup>

<Info>
  The health endpoint is designed to respond quickly (typically under 100ms) to
  provide fast health check results for monitoring systems.
</Info>

{" "}
