---
title: "Timeout"
description: "Extend session duration beyond the default timeout period."
image: "https://help.agent.mq/og.svg"
---

> Documentation Index
> Fetch the complete documentation index at: https://help.agent.mq/llms.txt
> Use this file to discover all available pages before exploring further.

# Timeout

By default, Browsers sessions have a timeout period after which they automatically terminate, which prevents sessions from running forever unexpectedly.

You can **extend this duration** either application-wide or per-session, allowing you to keep working without worrying about the session timing out.

> **Note**
>
> The maximum session duration is 6 hours. When a session times out, you'll see a `TimeoutError`: `Timeout _____ms exceeded`.

## Application-wide timeout

You can change the default session timeout for all sessions in your application through the console settings.

## Per-session timeout

You can also set a custom timeout through code by specifying the `timeout` option in the API request body or with the SDK.

This is useful when different sessions need different timeouts, or when you need more granular control than the console toggle provides.

> **Note**
>
> The examples below set timeout to 3600 seconds (1 hour), overriding the application default. Unless explicitly closed beforehand, the session continues running for an hour before terminating. At disconnect, it ends.

### Node.js

```typescript SDK
  import Browsers from "agentmq";

  const browsers = new Browsers({
    apiKey: process.env.AGENTMQ_TOKEN!,
  });

  // Creates a session with a timeout of 3600 seconds (1 hour)
  const session = await browsers.sessions.create({
    timeout: 3600,
  });
```

```typescript API
  const options = {
    method: "POST",
    headers: {
      "Authorization: Bearer": "<your-api-key>",
      "Content-Type": "application/json",
    },
    body: '{"timeout": 3600}',
  };

  fetch("https://api.agent.mq/v1/browsers/sessions", options)
    .then((response) => response.json())
    .then((response) => console.log(response))
    .catch((err) => console.error(err));
```

### Python

```python SDK
  from agentmq.browsers import Browsers
  import os

  browsers = Browsers(api_key=os.environ["AGENTMQ_TOKEN"])

  # Creates a session with a timeout of 3600 seconds (1 hour)
  session = browsers.sessions.create(
      api_timeout=3600
  )
```

```python API
  import os
  import requests

  headers = {"Authorization": os.environ["AGENTMQ_TOKEN"]}
  json = {
      "api_timeout": 3600,
  }

  response = requests.post(
      "https://api.agent.mq/v1/browsers/sessions",
      json=json,
      headers=headers,
  )

  response.raise_for_status()
  print(response.json())
```

## Timeouts and keep alive

Setting a custom timeout extends how long a session can run, but the session still terminates when you disconnect.

If you need to **disconnect and reconnect** to the same session, use [Keep Alive](/browsers/long-sessions/keep-alive) instead. For sessions that need both extended duration and reconnection support, configure both options:

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

- **Keep alive** — [Learn how to keep sessions alive across disconnects.](/browsers/long-sessions/keep-alive)

Source: https://help.agent.mq/browsers/long-sessions/timeouts/index.mdx
