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

# FastAPI - Health checks

> Discover how to integrate health checks into your FastAPI app in Sevalla.

To support zero-downtime deployments, configure a health check endpoint in your FastAPI application. This endpoint allows Sevalla to verify that your app is running correctly before routing traffic to it.

There are multiple ways to implement a health check in FastAPI, depending on the level of control and visibility required.

## Option 1: Use an existing endpoint

If you prefer not to create a separate health check path, you can use any existing public endpoint in your app. Choose a path that will return an error if a critical service, like your database, is not functioning correctly.

## Option 2: Use a dedicated health check endpoint

A dedicated health check endpoint allows you to explicitly verify the health of your app’s dependencies. For example, you can check database connectivity by executing a simple query such as `session.exec(text("SELECT 1"))`. If the connection fails, the endpoint will return an error.

```python theme={null}
# app/main.py
from fastapi import FastAPI
from app.core.config import settings
from app.api.deps import SessionDep
from sqlalchemy import text

app = FastAPI()

@app.get("/health_check")
def health_check(session: SessionDep):
    session.exec(text("SELECT 1"))
    return "OK"
```

You can extend this endpoint to include additional checks for other services your app depends on.

## Option 3: Use a health check library

Health check libraries provide ready-made solutions for monitoring the state of your app’s dependencies, such as databases, task queues, caches, and email services. One popular library for FastAPI is [**FastAPI Health**](https://pypi.org/project/fastapi-health/), which simplifies the creation of robust health check endpoints.
