Overview
Computer sessions have configurable lifetimes with automatic cleanup. Understanding the lifecycle helps you optimize costs and avoid unexpected terminations.Timeouts
Sessions have two independent timeout mechanisms:Max Lifetime (timeout_seconds)
The absolute maximum duration a session can exist.
Inactivity Timeout (inactivity_timeout_seconds)
How long a session can be idle before automatic termination.
auto_kill
Controls whether the session automatically terminates on inactivity.| Value | Behavior |
|---|---|
true (default) | Session terminates after inactivity_timeout_seconds of no activity |
false | Session runs until timeout_seconds max lifetime, regardless of activity |
Keepalive
For long-running sessions with intermittent activity, use keepalive to prevent inactivity timeout.- Processing data between actions (AI inference, API calls)
- Waiting for external events before next action
- Long pauses in interactive sessions
Session Status
Check the current status and remaining time for a session:Status Fields
| Field | Description |
|---|---|
status | Current state: ready, running, terminated |
created_at | When the session was created |
expires_at | When max lifetime expires |
idle_expires_at | When inactivity timeout expires |
last_activity_at | Timestamp of last action or keepalive |
max_lifetime_seconds | Configured max lifetime |
inactivity_timeout_seconds | Configured inactivity timeout |
auto_kill | Whether auto-termination is enabled |
Plan Limits
Your plan determines session limits:| Plan | Max Concurrent Sessions | Max Duration |
|---|---|---|
| Free | 2 | 1 hour |
| Pro | 10 | 4 hours |
| Enterprise | Unlimited | 24 hours |
Billing Errors
HTTP 402 - Payment Required
If your account has insufficient credits or a payment issue:- Account balance depleted
- Payment method failed
- Credit card expired
HTTP 429 - Rate Limited
Too many requests or concurrent sessions:- Exceeded concurrent session limit for your plan
- Too many failed authentication attempts (10 failures in 10 minutes blocks IP)
Best Practices
Always terminate when done
Always terminate when done
Use context managers or explicit
terminate() calls to stop billing immediately.Set appropriate timeouts
Set appropriate timeouts
Match timeouts to your workload. Short tasks should have short timeouts.
Use keepalive for long processing
Use keepalive for long processing
If processing takes longer than inactivity timeout, send keepalives.
Handle billing errors gracefully
Handle billing errors gracefully
Check for 402 errors and notify users to add credits.