Overview
Restore sessions from saved snapshots to continue working with preserved browser state, authentication, and data.
Restoration Methods
There are two ways to restore from snapshots:
From Specific Session Restore from a specific session’s snapshot
Use restore_from_session_id
From Default Environment Restore from user’s default environment
Use restore_default_environment_from_user_id
Restore from Specific Session
Restore from a specific session’s snapshot by providing the session ID:
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_from_session_id: 'session-uuid-to-restore-from'
})
});
const session = await response . json ();
response = requests.post(
"https://api.agi.tech/v1/sessions" ,
headers = { "Authorization" : f "Bearer { api_key } " },
json = {
"agent_name" : "agi-0" ,
"restore_from_session_id" : "session-uuid-to-restore-from"
}
)
session = response.json()
http POST https://api.agi.tech/v1/sessions \
Authorization:"Bearer $AGI_API_KEY " \
agent_name=agi-0 \
restore_from_session_id=session-uuid-to-restore-from
Use this method when you want to restore from a specific session snapshot, not the default environment.
Restore from Default Environment
Restore from your default environment by providing your user ID:
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'
})
});
const session = await response . json ();
response = requests.post(
"https://api.agi.tech/v1/sessions" ,
headers = { "Authorization" : f "Bearer { api_key } " },
json = {
"agent_name" : "agi-0" ,
"restore_default_environment_from_user_id" : "your-user-id"
}
)
session = response.json()
http POST https://api.agi.tech/v1/sessions \
Authorization:"Bearer $AGI_API_KEY " \
agent_name=agi-0 \
restore_default_environment_from_user_id=your-user-id
This is the recommended approach for most applications. Set up your default environment once, then all future sessions can automatically restore from it.
Automatic Default Restoration
To make sessions automatically restore from the default environment, always include restore_default_environment_from_user_id in your session creation:
async function createSessionWithDefault ( userId , apiKey ) {
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: userId
})
});
return await response . json ();
}
// Usage
const session = await createSessionWithDefault ( 'your-user-id' , apiKey );
import requests
def create_session_with_default ( user_id : str , api_key : str ):
response = requests.post(
"https://api.agi.tech/v1/sessions" ,
headers = { "Authorization" : f "Bearer { api_key } " },
json = {
"agent_name" : "agi-0" ,
"restore_default_environment_from_user_id" : user_id
}
)
return response.json()
# Usage
session = create_session_with_default( 'your-user-id' , api_key)
# Create session with automatic default restoration
http POST https://api.agi.tech/v1/sessions \
Authorization:"Bearer $AGI_API_KEY " \
agent_name=agi-0 \
restore_default_environment_from_user_id= $USER_ID
Memory Snapshot Mode
Control whether memory snapshots are enabled when restoring:
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_from_session_id: 'session-uuid' ,
enable_memory_snapshot: true // Default: true
})
});
response = requests.post(
"https://api.agi.tech/v1/sessions" ,
headers = { "Authorization" : f "Bearer { api_key } " },
json = {
"agent_name" : "agi-0" ,
"restore_from_session_id" : "session-uuid" ,
"enable_memory_snapshot" : True # Default: True
}
)
http POST https://api.agi.tech/v1/sessions \
Authorization:"Bearer $AGI_API_KEY " \
agent_name=agi-0 \
restore_from_session_id=session-uuid \
enable_memory_snapshot:= true
Options:
enable_memory_snapshot: true - Uses memory snapshots for faster restoration (recommended)
enable_memory_snapshot: false - Uses filesystem snapshots only (slower but more reliable)
Restoration Priority
When creating a session, the system uses this precedence order:
restore_from_session_id - Explicit session ID (highest priority)
restore_default_environment_from_user_id - User’s default environment
Fresh session - No restoration (default)
If both restore_from_session_id and restore_default_environment_from_user_id are provided, restore_from_session_id takes precedence.
Complete Example
Complete workflow: save snapshot and restore in new session:
// 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 } ` }
});
// Step 4: Create new session that automatically restores from default
const newSessionResponse = 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' ,
restore_default_environment_from_user_id: 'your-user-id'
})
});
const newSession = await newSessionResponse . json ();
import requests
# Step 1: Create a session
session_response = requests.post(
"https://api.agi.tech/v1/sessions" ,
headers = {
"Authorization" : f "Bearer { API_KEY } " ,
"Content-Type" : "application/json"
},
json = { "agent_name" : "agi-0" }
)
session_id = session_response.json()[ "session_id" ]
# Step 2: Use the session (login, navigate, etc.)
# ... perform actions that establish authentication ...
# Step 3: Save snapshot and set as default
requests.delete(
f "https://api.agi.tech/v1/sessions/ { session_id } " ,
headers = { "Authorization" : f "Bearer { API_KEY } " },
params = {
"save_snapshot_mode" : "filesystem" ,
"save_as_default" : "true"
}
)
# Step 4: Create new session that automatically restores from default
new_session_response = requests.post(
"https://api.agi.tech/v1/sessions" ,
headers = {
"Authorization" : f "Bearer { API_KEY } " ,
"Content-Type" : "application/json"
},
json = {
"agent_name" : "agi-0" ,
"restore_default_environment_from_user_id" : "your-user-id"
}
)
new_session = new_session_response.json()
# Step 1: Create a session
SESSION_ID = $( http POST https://api.agi.tech/v1/sessions \
Authorization:"Bearer $API_KEY " \
agent_name=agi-0 | jq -r '.session_id' )
# Step 2: Use the session (login, navigate, etc.)
# ... perform actions that establish authentication ...
# Step 3: Save snapshot and set as default
http DELETE "https://api.agi.tech/v1/sessions/ $SESSION_ID ?save_snapshot_mode=filesystem&save_as_default=true" \
Authorization:"Bearer $API_KEY "
# Step 4: Create new session that automatically restores from default
NEW_SESSION = $( http POST https://api.agi.tech/v1/sessions \
Authorization:"Bearer $API_KEY " \
agent_name=agi-0 \
restore_default_environment_from_user_id=your-user-id | jq -r '.session_id' )