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

User and session IDs are your own identifiers. Ingate stores them as opaque strings. Use whatever format your application already has: UUIDs, email hashes, database IDs, or another stable identifier supported by your input path. IDs group records; they do not authenticate or authorize a reader.

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:

HeaderDescription
X-Ingate-User-IdYour application's user identifier
X-Ingate-Session-IdConversation 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:

jsonIngestion payload with tags
{
  "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 AttributeIngate Field
gen_ai.user.iduser_id
gen_ai.session.idsession_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

A shared ID does not merge or deduplicate records arriving through different channels. Preserve source and request identifiers when investigating proxy, API or OTel observations.

Sending User & Session IDs

The most common approach is setting proxy headers. Here's how to do it in each language:

cURL

bash
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

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

ts
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

Avoid using email addresses, full names, or other personally identifiable information as user IDs. Use opaque identifiers (database IDs, UUIDs, or hashed values) so session data doesn't become a PII liability.

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

GET
/api/v1/sessions

Bounded 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.

bash
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"
jsonIllustrative unknown-cost response
{
  "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 coststotal_costunpriced_rowsMeaning
unknown, unknownnull2No known cost, not free usage
known zero00Known zero for this recorded observation
0.1, unknown0.11Known subtotal; incomplete cost

Bounded session timeline

GET
/api/v1/sessions/timeline

Chronological 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.

bash
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

GET
/api/v1/users/summary

Bounded 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.

bash
curl --fail-with-body "$INGATE_URL/api/v1/users/summary?limit=20" \
  -H "X-Ingate-Key: $INGATE_KEY"

Missing, failed and partial reads

A missing timeline identifier is rejected with 400; an unmatched identifier can return an empty entries array. Authentication or query failures are errors, not proof of zero activity. Keep organization, identifier and filters unchanged for a read-only retry. Retry the read, not inference or ingestion. Late persistence, capture policy and limits can leave evidence partial.

For routed setup see the Quickstart; for other aggregates see Usage Analytics.