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

# Concurrent sessions

> Cap how many sessions, jobs or browsers each customer runs at once, per plan, with every start decided atomically.

> **Starter:** 2 concurrent browser sessions. **Pro:** 10. **Enterprise:** 50.

Ledger enforces each plan's concurrency limit, so a customer runs exactly as many sessions as they pay for, even when starts race. Concurrency is a [held feature](https://docs.integrateledger.com/pricing/limits.md): a count of what the customer runs right now. Your app adds one when a session starts and removes one when it ends, and Ledger stops a start past the plan's limit. A periodic `count` sets the number to what your own session table says, so a slot held by a worker that crashed before its remove comes back on the next sync.

## The catalog

```ts ledger.config.ts theme={"system"}
import { defineCatalog, feature, plan } from "integrateledger-cli";

export default defineCatalog({
	features: [feature({ id: "sessions", name: "Concurrent sessions", type: "held" })],
	plans: [
		plan({ id: "starter", name: "Starter", monthlyCredits: 0, priceCents: 0,
			items: [{ featureId: "sessions", included: 2 }] }),
		plan({ id: "pro", name: "Pro", monthlyCredits: 0, priceCents: 9900,
			items: [{ featureId: "sessions", included: 10 }] }),
		plan({ id: "enterprise", name: "Enterprise", monthlyCredits: 0, priceCents: 49_900,
			items: [{ featureId: "sessions", included: 50 }] }),
	],
	creditPacks: [],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [{ "id": "sessions", "name": "Concurrent sessions", "type": "held" }],
  "plans": [
    { "id": "starter", "name": "Starter", "monthlyCredits": 0, "priceCents": 0,
      "items": [{ "featureId": "sessions", "included": 2 }] },
    { "id": "pro", "name": "Pro", "monthlyCredits": 0, "priceCents": 9900,
      "items": [{ "featureId": "sessions", "included": 10 }] },
    { "id": "enterprise", "name": "Enterprise", "monthlyCredits": 0, "priceCents": 49900,
      "items": [{ "featureId": "sessions", "included": 50 }] }
  ],
  "addOns": []
}
```

## The calls

**A session starts:** track `quantity: 1` before you open it. The track is the gate: Ledger decides it in one transaction per customer, so of two starts racing for the last slot, exactly one wins. A `409 limit_reached` means every slot is in use.

```typescript TypeScript theme={"system"}
import { TrackError } from "integrateledger/models/errors";

try {
	await billing.trackUsage({
		customerId: account.id,
		featureId: "sessions",
		requestId: `session-start-${session.id}`,
		quantity: 1,
	});
} catch (error) {
	if (error instanceof TrackError && error.data$.error === "limit_reached") {
		return res.status(429).json({ error: "all_sessions_in_use" });
	}
	throw error;
}
await openBrowser(session);
```

```python Python theme={"system"}
from integrateledger import LedgerAPIError

try:
    billing.track_usage(
        customer_id=account.id,
        feature_id="sessions",
        request_id=f"session-start-{session.id}",
        quantity=1,
    )
except LedgerAPIError as error:
    if error.code == "limit_reached":
        return {"error": "all_sessions_in_use"}, 429
    raise
open_browser(session)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "acct_17", "featureId": "sessions", "request_id": "session-start-s_5501", "quantity": 1}'
```

```json Response theme={"system"}
{
  "allowed": true,
  "availableCredits": 0,
  "chargedCredits": 0,
  "overageCredits": 0,
  "overageRemainingCents": null,
  "request_id": "session-start-s_5501",
  "idempotent": false,
  "featureType": "held",
  "chargedQuantity": 1,
  "balance": { "included": 10, "used": 7, "remaining": 3, "overageAllowed": false, "resetsAt": null }
}
```

To show "3 of 10 free" before the customer clicks, `check` with `quantity: 1`; it holds nothing, so the track still decides.

**A session ends:** track `quantity: -1` with the session's own end ID. A retried end counts once, and an end at 0 applies nothing.

```typescript TypeScript theme={"system"}
await billing.trackUsage({
	customerId: account.id,
	featureId: "sessions",
	requestId: `session-end-${session.id}`,
	quantity: -1,
});
```

```python Python theme={"system"}
billing.track_usage(
    customer_id=account.id,
    feature_id="sessions",
    request_id=f"session-end-{session.id}",
    quantity=-1,
)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "acct_17", "featureId": "sessions", "request_id": "session-end-s_5501", "quantity": -1}'
```

**Every minute: set the true count.** Count the customer's live sessions in your own table, where a crashed worker's session has timed out, and send it as `count`. Ledger sets the held number to it outright, and `chargedQuantity` is the difference it applied. Give each sync its own `request_id`.

```typescript TypeScript theme={"system"}
const live = await db.sessions.count({ accountId: account.id, heartbeatAfter: minutesAgo(2) });

await billing.trackUsage({
	customerId: account.id,
	featureId: "sessions",
	requestId: `sessions-sync-${account.id}-${syncRun.id}`,
	count: live,
});
```

```python Python theme={"system"}
live = db.sessions.count(account_id=account.id, heartbeat_after=minutes_ago(2))

billing.track_usage(
    customer_id=account.id,
    feature_id="sessions",
    request_id=f"sessions-sync-{account.id}-{sync_run.id}",
    count=live,
)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "acct_17", "featureId": "sessions", "request_id": "sessions-sync-acct_17-r_20261123_1015", "count": 6}'
```

A worker that died holding a slot left `used` at 7 while 6 sessions run; the sync answers `chargedQuantity: -1` and `used: 6`, and the slot is free again.

## Rules

* **Your session table is the truth.** `count` applies even above the limit, since it reports what runs. A customer over the limit after a downgrade keeps their sessions, and new starts resume once the count is under it.
* **Sync on a short interval.** A slot lost to a crash is reclaimed on the next sync, so the interval is the longest a customer waits for it. A start tracked between your table read and the sync's track is corrected by the sync after.
* **Send either `quantity` or `count`.** `count` sets held features, and a held track's `quantity` is non-zero.
* **With [fail open](https://docs.integrateledger.com/fail-open.md) on,** a start during a Ledger outage or timeout is allowed and its track is queued; the next sync sets the true count.
* **The start's track is the hold.** Held features take tracks; a `reserve` on one answers `400 reserve_not_supported`.
* **The count carries across** billing periods and plan changes ([Limits](https://docs.integrateledger.com/pricing/limits.md#rules)).

## Related

* [Limits](https://docs.integrateledger.com/pricing/limits.md): held features, add, remove and `count`.
* [Per-seat pricing](https://docs.integrateledger.com/pricing/per-seat.md): bill for a held count.
* [Check and track](https://docs.integrateledger.com/customers/check-and-track.md): refusals and how to handle them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.