Skip to main content

Overview

The health check endpoint allows you to verify API connectivity and get API version information.

Endpoint

Health Check

Check API health and status. Endpoint: GET /v1/health Request:
curl -X GET "https://bapi.bread.com.ai/v1/health" \
  -H "Authorization: Bearer $BREAD_API_KEY"
Response: 200 OK
{
  "status": "healthy",
  "api": "bread-api",
  "version": "1.0.0"
}
Response Fields:
  • status: string - ‘healthy’ or ‘degraded’
  • api: string - API name
  • version: string - API version

Examples

Basic Health Check

curl -X GET "https://bapi.bread.com.ai/v1/health" \
  -H "Authorization: Bearer $BREAD_API_KEY"
Response:
{
  "status": "healthy",
  "api": "bread-api",
  "version": "1.0.0"
}

Connection Test

Use health check to test connectivity:
# Test connection
response=$(curl -s -w "\n%{http_code}" -X GET "https://bapi.bread.com.ai/v1/health" \
  -H "Authorization: Bearer $BREAD_API_KEY")

http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)

if [ "$http_code" = "200" ]; then
  status=$(echo "$body" | jq -r '.status')
  version=$(echo "$body" | jq -r '.version')
  echo "✓ API is healthy (version $version)"
else
  echo "✗ Connection failed (HTTP $http_code)"
fi

Application Startup Check

Verify API connectivity during application initialization:
#!/bin/bash

# Health check script
response=$(curl -s -w "\n%{http_code}" -X GET "https://bapi.bread.com.ai/v1/health" \
  -H "Authorization: Bearer $BREAD_API_KEY")

http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)

if [ "$http_code" = "200" ]; then
  status=$(echo "$body" | jq -r '.status')
  version=$(echo "$body" | jq -r '.version')
  
  if [ "$status" != "healthy" ]; then
    echo "Warning: API status is $status"
  fi
  
  echo "Connected to Bread API v$version"
else
  echo "Failed to connect to Bread API (HTTP $http_code)"
  exit 1
fi

Monitoring Script

Continuous health monitoring:
#!/bin/bash

# Monitor API health every 60 seconds
while true; do
  timestamp=$(date '+%Y-%m-%d %H:%M:%S')
  
  response=$(curl -s -w "\n%{http_code}" -X GET "https://bapi.bread.com.ai/v1/health" \
    -H "Authorization: Bearer $BREAD_API_KEY")
  
  http_code=$(echo "$response" | tail -n1)
  body=$(echo "$response" | head -n-1)
  
  if [ "$http_code" = "200" ]; then
    status=$(echo "$body" | jq -r '.status')
    version=$(echo "$body" | jq -r '.version')
    echo "[$timestamp] Status: $status | Version: $version"
    
    if [ "$status" != "healthy" ]; then
      echo "⚠ API degraded at $timestamp"
    fi
  else
    echo "[$timestamp] ✗ Connection failed (HTTP $http_code)"
  fi
  
  sleep 60
done

Status Values

healthy

API is operating normally

degraded

API is experiencing issues but still operational

Best Practices

Perform a health check when your application starts to verify connectivity
Add health checks to your monitoring and alerting systems
Implement graceful degradation when API status is ‘degraded’
Health checks are lightweight but shouldn’t be called excessively (every 30-60s is reasonable)

Error Handling

Connection Error

Cannot reach the API server:
curl -X GET "https://bapi.bread.com.ai/v1/health" \
  -H "Authorization: Bearer $BREAD_API_KEY"
Response: Connection timeout or network error Troubleshooting:
  • Check network connectivity
  • Verify base URL is correct
  • Check firewall/proxy settings

Authentication Error

Invalid or missing API key:
curl -X GET "https://bapi.bread.com.ai/v1/health" \
  -H "Authorization: Bearer invalid_key"
Response: 401 Unauthorized
{
  "error": "Invalid API key"
}
Troubleshooting:
  • Verify your API key is correct
  • Check that BREAD_API_KEY environment variable is set
  • Ensure API key has proper permissions

Timeout Error

API is slow or unresponsive: Response: Request timeout Troubleshooting:
  • API may be experiencing high load
  • Check API status page
  • Retry after a few seconds

Response Type

HealthCheckResponse

{
  "status": "healthy",
  "api": "bread-api",
  "version": "1.0.0"
}
Fields:
  • status: string - ‘healthy’ or ‘degraded’
  • api: string - API name
  • version: string - API version

Next Steps