Skip to main content
POST
/
lens
/
sessions
/
destroy
curl -X POST https://api.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_DESTROYED",
  "session_runner": "lens_service:runner:lens-node-worker-node-abc123",
  "session_endpoint": "wss://api.u1.archetypeai.app/v0.5/lens/sessions/lsn-2512078e5c9ce4d312a6681e771542",
  "session_duration_sec": 53.79125928878784
}

Documentation Index

Fetch the complete documentation index at: https://docs.archetypeai.app/llms.txt

Use this file to discover all available pages before exploring further.

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

session_id
string
required
The unique session ID to destroy. This is returned when creating a session.

Response

On success, returns the destroyed session record. Errors are returned with an HTTP 4xx status and an errors array (no is_valid field).
session_id
string
The ID of the destroyed session.
lens_id
string
The lens ID the session was attached to.
session_status
string
Final status of the session (typically SESSION_STATUS_DESTROYED).
session_runner
string
Identifier of the backend runner that hosted the session.
session_endpoint
string
WebSocket URL the session was reachable at.
last_update_timestamp
float
Unix timestamp of the last update to the session record.
session_duration_sec
float
Total duration the session was active in seconds.
curl -X POST https://api.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_DESTROYED",
  "session_runner": "lens_service:runner:lens-node-worker-node-abc123",
  "session_endpoint": "wss://api.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