Session & User Tracking
Track individual users and conversation sessions across LLM interactions for per-user analytics, bounded recorded timelines, nullable cost attribution, and debugging.
Overview
Most LLM traffic is anonymous by default. You see request counts and token usage, but you can't answer “which user is burning through tokens?” or“what happened in that conversation?”. Session and user tracking closes this gap.
When you attach a user ID and/or session ID to your LLM requests, Ingate can retain them on recorded entries, subject to input validation, capture policy and persistence. This supports:
- Per-user cost attribution: see which users drive the most spend
- Session timelines: inspect a bounded sequence of recorded calls in a conversation
- Usage breakdowns: group analytics by user or session
- Debugging: trace a reported bug back to the exact exchange sequence
- Abuse detection: identify users with unusual request patterns
IDs are opaque strings
Three Extraction Points
Ingate can extract user and session IDs from three sources, depending on how your data enters the system. All three methods produce the same result: a user_id and/orsession_id attached to each log entry.
1. Proxy Headers
When routing requests through the Ingate proxy, set these headers on each request:
| Header | Description |
|---|---|
X-Ingate-User-Id | Your application's user identifier |
X-Ingate-Session-Id | Conversation or session identifier |
Both headers are stripped before forwarding to the upstream provider. This removes those headers, not identifiers copied into request bodies or prompts. Authorized readers may still see retained identifiers.
2. Ingestion API Tags
When sending data via the REST Ingestion API, include user and session IDs in the tags object on each exchange:
{
"provider": "openai",
"path": "/v1/chat/completions",
"method": "POST",
"status_code": 200,
"latency_ms": 350,
"request_body": { "..." : "..." },
"response_body": { "..." : "..." },
"tags": {
"user_id": "user_42",
"session_id": "session_abc123",
"environment": "production"
}
}The tags object can contain any key-value pairs. user_id andsession_id are the two that Ingate recognizes for session tracking. Other tags are stored as metadata and appear in log entries.
3. OpenTelemetry Span Attributes
When sending traces via the OTLP endpoint, Ingate extracts user and session IDs from supported span attributes:
| OTel Attribute | Ingate Field |
|---|---|
gen_ai.user.id | user_id |
gen_ai.session.id | session_id |
These are supported Ingate input attributes in the pinned source revision. See the OTLP guide for transport setup; assigning attributes alone does not prove delivery or correlate separate captures.
Keep the observation source
Sending User & Session IDs
The most common approach is setting proxy headers. Here's how to do it in each language:
cURL
curl https://api.ingateai.com/v1/chat/completions \
-H "X-Ingate-Provider: openai" \
-H "X-Ingate-Key: $INGATE_KEY" \
-H "X-Ingate-User-Id: user_42" \
-H "X-Ingate-Session-Id: session_abc123" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello"}]
}'Python
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.ingateai.com/v1",
api_key="unused",
default_headers={
"X-Ingate-Provider": "openai",
"X-Ingate-Key": os.environ["INGATE_KEY"],
}
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
extra_headers={
"X-Ingate-User-Id": current_user.id,
"X-Ingate-Session-Id": session.id,
}
)TypeScript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.ingateai.com/v1",
apiKey: "unused",
defaultHeaders: {
"X-Ingate-Provider": "openai",
"X-Ingate-Key": process.env.INGATE_KEY!,
},
});
const response = await client.chat.completions.create(
{
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello" }],
},
{
headers: {
"X-Ingate-User-Id": currentUser.id,
"X-Ingate-Session-Id": sessionId,
},
}
);Don't send PII as user IDs
Sessions API
These reads are scoped to the authenticated organization and require its permitted read role. Use its gateway key in X-Ingate-Key, or an authorized management session token. Set INGATE_URL to the API origin and retain the same filters for a read-only retry.
List sessions
/api/v1/sessionsBounded recorded session summaries for the current organization.
Supported filters are user_id, optional RFC3339 since/until, and limit (default 50, cap 500). Omitted dates do not imply a default retention window. Results are ordered by last activity. There is no offset/cursor pagination contract here;count counts returned summaries, not all matching historical sessions.
curl --fail-with-body --get "$INGATE_URL/api/v1/sessions" \
--data-urlencode "user_id=$INGATE_USER_ID" \
--data-urlencode "limit=20" \
-H "X-Ingate-Key: $INGATE_KEY"{
"sessions": [{
"session_id": "session_unknown",
"user_id": "user_unknown",
"request_count": 2,
"total_tokens": 12,
"total_cost": null,
"unpriced_rows": 2,
"first_seen": "2026-10-13T08:00:00Z",
"last_seen": "2026-10-13T08:01:00Z"
}],
"count": 1
}Interpret nullable cost
total_cost sums known recorded cost values. unpriced_rows counts records with unknown cost. Neither field proves complete provider billing.
| Recorded costs | total_cost | unpriced_rows | Meaning |
|---|---|---|---|
| unknown, unknown | null | 2 | No known cost, not free usage |
| known zero | 0 | 0 | Known zero for this recorded observation |
| 0.1, unknown | 0.1 | 1 | Known subtotal; incomplete cost |
Bounded session timeline
/api/v1/sessions/timelineChronological recorded entries selected by an opaque session identifier.
Use the query form for IDs containing slashes or other reserved characters. The legacy/sessions/:id/timeline route also exists. limit defaults to 100 and is capped at 1000. It bounds the earliest chronological records returned; there is no supported offset/cursor or continuation token. A short result does not establish complete history.
curl --fail-with-body --get "$INGATE_URL/api/v1/sessions/timeline" \
--data-urlencode "session_id=$INGATE_SESSION_ID" \
--data-urlencode "limit=2" \
-H "X-Ingate-Key: $INGATE_KEY"The response has session_id, entries and returned count. Entries retain created_at, source, request ID and nullable fields, plusrecord_id as a decimal string alongside the compatible numeric id. Content may be absent or withheld; a recorded timeline is not deterministic conversation replay.
User summary
/api/v1/users/summaryBounded per-user recorded aggregates for the current organization.
Supported filters are optional RFC3339 since/until andlimit (default 50, cap 500). Ordering is by last activity, not a selectable cost ranking. The response has users and returned count. Each user has user_id, request_count, total_tokens, nullable total_cost, unpriced_rows, session_count,avg_latency_ms and last_seen.
curl --fail-with-body "$INGATE_URL/api/v1/users/summary?limit=20" \
-H "X-Ingate-Key: $INGATE_KEY"Missing, failed and partial reads
For routed setup see the Quickstart; for other aggregates see Usage Analytics.