Skip to main content

Overview

Save snapshots when deleting sessions to preserve browser state, authentication, and data for future use.

Snapshot Modes

Choose the right snapshot mode for your use case:

Memory

Fastest restoration
⚡ Quick to restore
⚠️ May be less reliable
💡 Good for temporary state

Filesystem

Most reliable
✅ Preserves all browser data
🔐 Best for authentication
💡 Recommended for production

None

No snapshot
🗑️ State is lost
💡 Default behavior

Save a Snapshot

Save a snapshot when deleting a session using the save_snapshot_mode parameter:
// Save a memory snapshot (fast, less reliable)
await fetch(`https://api.agi.tech/v1/sessions/${sessionId}?save_snapshot_mode=memory`, {
  method: 'DELETE',
  headers: { 'Authorization': `Bearer ${apiKey}` }
});

// Save a filesystem snapshot (recommended for authentication)
await fetch(`https://api.agi.tech/v1/sessions/${sessionId}?save_snapshot_mode=filesystem`, {
  method: 'DELETE',
  headers: { 'Authorization': `Bearer ${apiKey}` }
});

// Delete without saving snapshot
await fetch(`https://api.agi.tech/v1/sessions/${sessionId}?save_snapshot_mode=none`, {
  method: 'DELETE',
  headers: { 'Authorization': `Bearer ${apiKey}` }
});
Use filesystem mode for authentication-critical applications. It preserves all browser data including cookies, localStorage, and sessionStorage.

Set as Default Environment

Save a snapshot and set it as the default environment in one step:
// Save snapshot and set as default
await fetch(`https://api.agi.tech/v1/sessions/${sessionId}?save_snapshot_mode=filesystem&save_as_default=true`, {
  method: 'DELETE',
  headers: { 'Authorization': `Bearer ${apiKey}` }
});
When save_as_default=true:
  • ✅ The snapshot is saved to the environment associated with the session
  • ✅ The environment is set as the user’s default environment
  • ✅ Future session creations can automatically restore from this snapshot

Default Environments

How Default Environments Work

A default environment is an environment snapshot that is automatically restored when creating new sessions. The system uses the following precedence order:
  1. restore_from_session_id - Explicitly restore from a specific session ID (highest priority)
  2. restore_default_environment_from_user_id - Restore from user’s default environment (lower priority)
  3. Fresh session - No restoration (default)

Setting a Default Environment

Set a default environment by saving a snapshot during session deletion:
await fetch(`https://api.agi.tech/v1/sessions/${sessionId}?save_snapshot_mode=filesystem&save_as_default=true`, {
  method: 'DELETE',
  headers: { 'Authorization': `Bearer ${apiKey}` }
});
This saves the snapshot and sets it as the user’s default environment. Future session creations can then automatically restore from this snapshot using restore_default_environment_from_user_id.

Best Practices

Use Filesystem Mode

Always use filesystem mode for authentication-critical applications

Save After Login

Save snapshots immediately after successful authentication

Set as Default

Use save_as_default=true for automatic restoration

Update Regularly

Refresh snapshots before authentication tokens expire

Complete Example

Save a snapshot after logging in:
// Step 1: Create a session
const sessionResponse = await fetch('https://api.agi.tech/v1/sessions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ agent_name: 'agi-0' })
});
const { session_id } = await sessionResponse.json();

// Step 2: Use the session (login, navigate, etc.)
// ... perform actions that establish authentication ...

// Step 3: Save snapshot and set as default
await fetch(`https://api.agi.tech/v1/sessions/${session_id}?save_snapshot_mode=filesystem&save_as_default=true`, {
  method: 'DELETE',
  headers: { 'Authorization': `Bearer ${API_KEY}` }
});