> ## Documentation Index
> Fetch the complete documentation index at: https://docs.synthraai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Session Management

> Isolated conversation contexts with automatic lifecycle management

Synthra provides isolated conversation contexts called sessions. Each session maintains its own message history, context window, and token usage tracking.

## Quick Start

```typescript theme={null}
const agent = new SynthraAgent({
  apiKey: process.env.SYNTHRA_API_KEY
});

// Create session
const session = agent.createSession('user_abc123def456');

// Send message
const response = await agent.sendMessage(
  session.id,
  'Hello, Synthra!'
);

// Delete session
await agent.deleteSession(session.id);
```

## Session Limits

| Tier       | Max Sessions | Max Messages | Context Window |
| ---------- | ------------ | ------------ | -------------- |
| Free       | 10           | 100          | 4,096 tokens   |
| Pro        | 100          | 1,000        | 8,192 tokens   |
| Enterprise | Unlimited    | Unlimited    | 32,768 tokens  |

## Lifecycle

Sessions automatically expire after 24 hours of inactivity. States: Created → Active → Idle → Expired

## Configuration

```typescript theme={null}
const session = agent.createSession('user_abc123def456', {
  metadata: {
    source: 'web',
    language: 'en'
  },
  contextConfig: {
    maxTokens: 8192,
    compressionEnabled: true,
    retentionPolicy: 'semantic'
  }
});
```

## Error Handling

```typescript theme={null}
try {
  const response = await agent.sendMessage(session.id, 'Hello!');
} catch (error) {
  if (error.code === 'session_not_found') {
    console.log('Session expired or deleted');
  }
}
```

<Note>
  Sessions are automatically compressed when approaching token limits.
</Note>

<Warning>
  Deleted sessions cannot be recovered. Use `clearSession()` to reset history while preserving the session.
</Warning>
