Skip to main content

Overview

Session snapshots allow you to preserve the complete state of a browser environment, including:
  • Filesystem state - Browser data, cookies, localStorage, sessionStorage
  • Memory state - Faster restoration, but less reliable
  • Authentication tokens - Logged-in sessions and credentials
  • Browser extensions - Extensions and configurations
When a session is deleted with snapshot saving enabled, the environment state is preserved and can be restored in future sessions. This is particularly useful for maintaining authentication state across multiple sessions.

Quick Start

1

1. Save a Snapshot

After logging in, delete the session with snapshot saving enabled:
await fetch(`https://api.agi.tech/v1/sessions/${sessionId}?save_snapshot_mode=filesystem&save_as_default=true`, {
  method: 'DELETE',
  headers: { 'Authorization': `Bearer ${apiKey}` }
});
2

2. Restore from Snapshot

Create a new session that restores from the saved snapshot:
const response = await fetch('https://api.agi.tech/v1/sessions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    agent_name: 'agi-0',
    restore_default_environment_from_user_id: 'your-user-id'
  })
});
3

3. Use Authenticated Session

Your new session will have all authentication state restored automatically.

Snapshot Modes

There are three snapshot modes available:

Memory

Fastest restoration
May be less reliable
Good for temporary state

Filesystem

Most reliable
Preserves all browser data
Recommended for authentication

None

No snapshot saved
Default behavior
Session state is lost

Common Use Cases


Key Concepts

How Snapshots Work

1. Create Session → Fresh environment
2. Login/Authenticate → State stored in browser
3. Delete with Snapshot → State saved to environment
4. Create New Session → Restore from snapshot
5. Continue Working → Already authenticated

Restoration Priority

When creating a session, the system uses this precedence:
  1. restore_from_session_id - Explicit session ID (highest priority)
  2. restore_default_environment_from_user_id - User’s default environment
  3. Fresh session - No restoration (default)