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

# ID Manager

> Internal sequential ID management for Supabase tables.

## Overview

`IDManager` maintains auto-incrementing ID sequences for LangChat's Supabase tables. It handles concurrent inserts gracefully by using a retry-with-conflict-resolution strategy.

This is an internal component — you don't interact with it directly under normal use.

```python theme={null}
from langchat.adapters.database.id_manager import IDManager
```

***

## How it works

1. On initialization, `IDManager` reads the current maximum ID from each table
2. IDs are assigned from an in-memory counter
3. When two concurrent requests try to insert with the same ID, the retry logic increments and retries automatically
4. This avoids database sequences while maintaining consistent IDs

***

## Constructor

```python theme={null}
IDManager(
    supabase_client,
    initial_value: int = 1,
    retry_attempts: int = 3,
)
```

<ParamField path="supabase_client" type="Client">
  Supabase client instance.
</ParamField>

<ParamField path="initial_value" type="int" default="1">
  Starting ID value for new tables.
</ParamField>

<ParamField path="retry_attempts" type="int" default="3">
  Number of retry attempts on ID conflict before raising an error.
</ParamField>

***

## Methods

### `insert_with_retry()`

Insert a record with automatic ID assignment and conflict retry.

```python theme={null}
def insert_with_retry(
    self,
    table: str,
    data: dict,
) -> dict | None
```

Used internally by `session.save_message()` and metrics recording. You only need this if building a custom adapter.
