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

# Serverless and shutdown

> Flush bounded background capture without putting Keeps on the critical path.

The SDK buffers delivery in the background. Flush at a natural response or
shutdown boundary, not after every individual SDK call.

<CodeGroup>
  ```ts Node theme={null}
  export const handler = keeps.withFlush(async (request) => {
    return generateMedia(request);
  });
  ```

  ```python Python theme={null}
  @keeps.with_flush
  def handler(request):
      return generate_media(request)
  ```
</CodeGroup>

For a long-running process, create one client at process scope and close it
during graceful shutdown. A flush has a bounded timeout and does not turn a
delivery failure into an application failure.
