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

# Keeping Containers Warm

> Control how long your apps stay running before shutting down.

By default, Beam is serverless, which means your applications will shut off automatically when they're not being used.

## Configuring Keep Warm

You can control how long your containers are kept alive by using the `keep_warm_seconds` flag in your deployment trigger.

For example, by adding a `keep_warm_seconds=300` argument to an endpoint, your app will stay running for 5 minutes before shutting off:

```python theme={null}
from beam import endpoint


# Container stays alive for 5 min before shutting down automatically
@endpoint(keep_warm_seconds=300)
def handler():
    return {}
```

<Warning>
  When `keep_warm_seconds` is set in your deployment, it will count as billable
  usage.
</Warning>

## Setting Always-On Containers

<Note>
  Any running containers count towards billable usage. Take care to avoid
  setting `min_containers` unless you're comfortable paying for usage 24/7.
</Note>

You can configure the number of containers running at baseline using the `min_containers` field.

By setting `min_containers=1`, 1 container will *always* remain running until the deployment is stopped.

<Warning>
  If you redeploy an app that has `min_containers` set, make sure to explicitly
  stop the previous deployment versions in order to avoid running containers
  that you are no longer using.
</Warning>

```python theme={null}
from beam import endpoint, QueueDepthAutoscaler


@endpoint(
    autoscaler=QueueDepthAutoscaler(
        min_containers=1, max_containers=3, tasks_per_container=1
    ),
)
def handler():
    return {"success": "true"}
```

## Pre-Warming Your Container

You can pre-warm your containers by adding `/warmup` to the end of your deployment URL:

```sh theme={null}
curl -X POST 'https://hello-world-a4bdc39-v1.app.beam.cloud/warmup' \
     -H 'Authorization: Bearer [YOUR_TOKEN]'
```

When invoked, this endpoint will send a request to the container to warm-up.

You can add `/warmup` to the end of any of your deployment APIs to warm-up your container:

```
id/:stubId/warmup
/:deploymentName/warmup
/:deploymentName/latest/warmup
/:deploymentName/v:version/warmup
```

## Default Container Spin-down Times

After handling a request, Beam keeps containers running ("warm") for a certain amount of time in order to quickly handle future requests. By default, these are the container "keep warm" times for each deployment type:

| Deployment Type         | Container Keep Warm Duration |
| ----------------------- | ---------------------------- |
| Endpoints/ASGI/Realtime | 180s                         |
| Task Queues             | 10s                          |
| Pods                    | 600s                         |
