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.
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.
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,
});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));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
)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 instead. For sessions that need both extended duration and reconnection support, configure both options:
const session = await browsers.sessions.create({
keepAlive: true,
timeout: 3600, // 1 hour
});