Skip to main content
POST
https://api.u1.archetypeai.app/v0.5
/
lens
/
sessions
/
destroy
curl -X POST https://api.dev.u1.archetypeai.app/v0.5/lens/sessions/destroy \
  -H "Authorization: Bearer $ATAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "lsn-250313c2177253cbaa7a73542edd90"
  }'
{
  "session_id": "lsn-2512078e5c9ce4d312a6681e771542",
  "lens_id": "lns-test-lens-3de60a5c",
  "last_update_timestamp": 1765095462.576972,
  "session_status": "SESSION_STATUS_STALE",
  "session_endpoint": "wss://api.dev.u1.archetypeai.app/v0.5/lens/sessions/lsn-2512078e5c9ce4d312a6681e771542",
  "session_duration_sec": 53.79125928878784
}

Overview

This endpoint destroys an active lens session, closing any open connections and freeing up resources. Always destroy sessions when you’re done using them to avoid hitting concurrent session limits.

Request

Authorization
string
required
Bearer token for authentication. Format: Bearer $ATAI_API_KEY
session_id
string
required
The unique session ID to destroy. This is returned when creating a session.

Response

session_id
string
The ID of the destroyed session
session_status
string
Final status of the session (typically “SESSION_STATUS_STALE”)
session_duration_sec
float
Total duration the session was active in seconds
is_valid
boolean
Whether the operation was successful. Check this field to detect errors.
errors
array
Array of error messages if the request failed
curl -X POST https://api.dev.u1.archetypeai.app/v0.5/lens/sessions/destroy \
  -H "Authorization: Bearer $ATAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "lsn-250313c2177253cbaa7a73542edd90"
  }'
{
  "session_id": "lsn-2512078e5c9ce4d312a6681e771542",
  "lens_id": "lns-test-lens-3de60a5c",
  "last_update_timestamp": 1765095462.576972,
  "session_status": "SESSION_STATUS_STALE",
  "session_endpoint": "wss://api.dev.u1.archetypeai.app/v0.5/lens/sessions/lsn-2512078e5c9ce4d312a6681e771542",
  "session_duration_sec": 53.79125928878784
}

Best Practices

Always clean up sessions: Implement proper cleanup in your code to ensure sessions are destroyed even if errors occur:
try:
    # Create and use session
    session = create_session(lens_id)
    process_data(session)
finally:
    # Always destroy the session
    destroy_session(session['session_id'])
Sessions that are not explicitly destroyed will:
  • Continue consuming your concurrent session quota
  • Timeout after 30 minutes of inactivity
  • May result in hitting rate limits for new session creation