Health Resource
API methods for health operations.
Methods
check_liveness
Liveness Probe Kubernetes-style liveness probe endpoint.
This endpoint indicates whether the application is alive and running. It's used by Kubernetes and other orchestration platforms to determine if the container should be restarted.
A successful response (200 OK) indicates the application is alive. If this endpoint fails or returns an error, the orchestration platform may restart the container.
Returns: HealthResponse: A response object with message=True indicating the application is alive.
Example:
GET /livez
# Response:
{
"message": true
}
Note:
- This endpoint should always return quickly (< 1 second)
- It should not perform expensive operations or external calls
- Used for liveness probes in Kubernetes deployments
- Does not require authentication
Method: GET
Path: /livez
response = client.health.check_liveness()
Parameters
Responses
200 - Successful Response
- Content-Type:
application/json - Schema:
HealthResponse
check_readiness
Readiness Probe Kubernetes-style readiness probe endpoint.
This endpoint indicates whether the application is ready to serve traffic. It's used by Kubernetes and load balancers to determine if the instance should receive incoming requests.
A successful response indicates the application is ready to handle requests. If this endpoint fails, the instance will be removed from the load balancer pool until it becomes ready again.
This endpoint performs the following readiness checks:
- Verifies that the CREDOAI_SERVER_BASE_URL service is ready by calling its /readyz endpoint
Returns: HealthResponse: A response object with message=True indicating the application is ready to serve traffic.
Raises: HTTPException: 503 Service Unavailable if any dependency check fails.
Example:
GET /readyz
# Response:
{
"message": true
}
Note:
- This endpoint verifies that all dependencies are available
- Includes checks for external API availability (CREDOAI_SERVER_BASE_URL)
- Used for readiness probes in Kubernetes deployments
- Should return quickly but may be slightly slower than /livez
- Does not require authentication
Method: GET
Path: /readyz
response = client.health.check_readiness()
Parameters
Responses
200 - Successful Response
- Content-Type:
application/json - Schema:
HealthResponse
Usage Examples
Here's a complete example using the check_liveness method:
import asyncio
from credoai import
async def main():
# Initialize client
client = (
base_url="https://api.credo.ai",
api_key="test_password-your-api-key"
)
try:
# Liveness Probe
response = await client.health.check_liveness()
print(f"Success: {response}")
except Exception as e:
print(f"Error: {e}")
finally:
await client.close()
# Run the example
asyncio.run(main())
Error Handling
All methods in this resource can raise the following exceptions:
ValidationError- Invalid request dataAPIError- Server-side errorsAuthenticationError- Invalid or missing API keyNotFoundError- Resource not found (404)RateLimitError- Too many requests
from credoai.errors import APIError, ValidationError
try:
response = client.health.check_liveness()
except ValidationError as e:
print(f"Invalid request: {e}")
except APIError as e:
print(f"API error {e.status_code}: {e.message}")