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

# Keep alive

> Keep sessions alive across disconnects, allowing you to reconnect without ending your session.

The `keepAlive` feature lets you **keep sessions alive across disconnects**, so you can reconnect and continue using the same session.

|                        | When connection closes                   |
| ---------------------- | ---------------------------------------- |
| **Without keep alive** | Session ends                             |
| **With keep alive**    | Session stays available for reconnection |

<Note>
  Session keep alive is only available on paid plans.
</Note>

## Why use keep alive?

* **Reconnection workflows**: Connect, disconnect, and reconnect to the same session
* **Multiple connections**: Different scripts or tools can connect to the same session
* **Survive disconnects**: Network issues won't end your session
* **Performance**: Reconnecting to an existing session is faster than creating a new one
* **Session reuse**: Re-run scripts against the same session without recreating it
* **Billing optimization**: keep alive lets you [avoid minimum browser usage charges](/account/billing/plans) if running many short-lived sessions (under 1 minute)

## Using keep alive

### Creating a keep alive session

Setting `keepAlive` to `true` keeps the session available for later use. Reconnect to the keep alive session using the same connect URL.

<Tabs>
  <Tab title="Node.js">
    <CodeGroup>
      ```typescript SDK theme={null}
      import Browserbase from "browserbase";

      const bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY! });
      const session = await bb.sessions.create({
        keepAlive: true,
      });

      // Reconnect later using the same connect URL
      console.log("Connect URL:", session.connectUrl);
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Python">
    <CodeGroup>
      ```python SDK theme={null}
      from browserbase import Browserbase
      import os

      bb = Browserbase(api_key=os.environ["BROWSERBASE_API_KEY"])
      session = bb.sessions.create(
        keep_alive=True
      )

      # Reconnect later using the same connect URL
      print("Connect URL:", session.connect_url)
      ```
    </CodeGroup>
  </Tab>
</Tabs>

### Releasing a keep alive session

Keep alive sessions must be explicitly released to stop; otherwise, they'll continue until the session's timeout.

<Note>
  Release keep alive sessions when you're done to avoid being charged for unused browser minutes.
</Note>

<Tabs>
  <Tab title="Node.js">
    <CodeGroup>
      ```typescript SDK theme={null}
      await bb.sessions.update(session.id, {
        status: "REQUEST_RELEASE",
      });
      ```

      ```typescript API theme={null}
      const headers = {
        "X-BB-API-Key": "<your-api-key>",
        "Content-Type": "application/json",
      };

      const body = JSON.stringify({
        status: "REQUEST_RELEASE",
      });

      fetch("https://api.browserbase.com/v1/sessions/<session-id>", {
        method: "POST",
        headers,
        body,
      })
        .then((response) => response.json())
        .then((response) => console.log(response))
        .catch((err) => console.error(err));
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Python">
    <CodeGroup>
      ```python SDK theme={null}
      bb.sessions.update(
        session.id,
        status="REQUEST_RELEASE"
      )
      ```

      ```python API theme={null}
      import os
      import requests

      headers = {"X-BB-API-Key": os.environ["BROWSERBASE_API_KEY"]}
      json = {
          "status": "REQUEST_RELEASE",
      }

      response = requests.post(
          f"https://api.browserbase.com/v1/sessions/<session-id>",
          headers=headers,
          json=json,
      )

      # Raise an exception if there wasn't a good response from the endpoint
      response.raise_for_status()
      print(response.json())
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Keep alive and timeouts

Keep alive sessions still respect [session timeouts](/platform/browser/long-sessions/timeouts). If you need a session that both survives disconnects and runs for an extended period, configure both options:

```typescript theme={null}
const session = await bb.sessions.create({
  keepAlive: true,
  timeout: 3600, // 1 hour
});
```

<Card title="Session timeouts" icon="clock" href="/platform/browser/long-sessions/timeouts">
  Learn how to extend session duration beyond the default timeout.
</Card>
