---
title: "Sessions API: rebuild an engagement step by step"
description: "List recent sessions with request counts, tokens, cost and errors, then open one to walk its steps in start order with model, outcome and latency."
canonical: https://pentestllm.ai/docs/sessions
generated: 2026-11-27T06:25:48.746Z
source: https://pentestllm.ai/docs/sessions
base_url: https://api.pentestllm.ai/v1
---

[Docs](https://pentestllm.ai/docs) / API reference

# Sessions and timelines API

Updated 2026-11-22. Published by PentestLLM.

An engagement spans many calls: planning, triage, the write-up. Tag them with one session id and two routes under `https://api.pentestllm.ai/v1` rebuild the run afterwards, a list of recent sessions and a step-by-step timeline of any one of them.

## Routes

| Route | Statuses |
| --- | --- |
| `GET /v1/sessions` | 200, 401 |
| `GET /v1/sessions/{session_id}` | 200, 401, 404 |

Both declare the admin key. The list’s 401 reads “no admin key and no console sign-in”, so a signed-in console works there; for the timeline, and for how the sign-in is carried, the OpenAPI document does not say.

## How a request joins a session

Send a session id in the session request header, or put `session_id` or `user` in the body. Turns of a hosted agent are grouped as `<agent id>:<session>`.

## List sessions

`GET /v1/sessions` puts the most recently active first and takes these query parameters:

| Parameter | Type | Notes |
| --- | --- | --- |
| `key_id` | string | Only sessions with requests from this key. |
| `days` | integer, 1 to 90 | How far back to look; 30 when omitted. |
| `limit` | integer, 1 to 200 | Rows per page; 50 when omitted. |
| `before` | integer | The next_before value from the page you just read. |

The answer holds `data`, `days`, `has_more` and `next_before`, which is null on the final page. Each row of `data`:

| Field | Meaning |
| --- | --- |
| `id` | The session id. |
| `requests` | How many requests it holds. |
| `first_at` | When its first request started, Unix milliseconds. |
| `last_at` | When its last request ended, Unix milliseconds. |
| `duration_ms` | The span between those two. |
| `charge_micro` | What it was charged, in micro-dollars. |
| `cost_usd` | The same charge in dollars. |
| `input_tokens` | Billed prompt tokens, cached reads and writes included. |
| `output_tokens` | Generated tokens. |
| `errors` | Requests a model failed or refused. They are never charged. |
| `models` | Every model the session used. |
| `key_ids` | Every key that sent part of it. |

## One session’s timeline

`GET /v1/sessions/{session_id}` takes the id URL-encoded, 1 to 128 printable ASCII characters. Its `data` carries `id`, `first_at`, `last_at`, `duration_ms`, `models`, `totals` (requests, input and output tokens, charge, errors and latency), `truncated` and `steps` in the order they started. Past 1,000 requests only the newest 1,000 appear and truncated is true. Each step:

| Field | Meaning |
| --- | --- |
| `request_id` | The request, readable on its own through the requests route. |
| `started_at` | Start, Unix milliseconds. |
| `ended_at` | End, Unix milliseconds. |
| `key_id` | Which key made the call. |
| `model` | Model that produced the answer. |
| `outcome` | completed, client_disconnected, upstream_error or upstream_rejected. |
| `status` | The HTTP status. |
| `input_tokens` | Prompt tokens; cache_read_tokens, cache_write_tokens and output_tokens sit beside it. |
| `charge_micro` | Charge in micro-dollars, with cost_usd beside it. |
| `latency_ms` | Milliseconds the step took. |
| `refund_reason` | Why the step went unbilled, when it did. |
| `tool_calls` | Server tool calls whose results it carried, or null. |

The 90-day reach of the list is a query limit, not a promise of how long records are kept.

## Errors

No valid admin key and no sign-in is `401 unauthorized`. An id no request of your organization carried is `404 not_found`.

## Example

```bash
curl "https://api.pentestllm.ai/v1/sessions?days=7&limit=50" \
  -H "Authorization: Bearer sk-ptl-live-…"
```

## Questions

### Must I use the key that made the session to read it?

No. These routes read the whole organization with an admin key, and the key_id filter narrows the list to one key when you want that.

### Why do the first steps of a long run not appear?

A timeline holds the latest 1,000 requests and sets truncated when there were more. For the full history, export the usage log as CSV for the same window.

### How do I page through the session list?

Pass the next_before you received as before on the next call, and stop once has_more turns false.

## Read next

- [MCP servers](https://pentestllm.ai/docs/mcp-servers)
- [Log export](https://pentestllm.ai/docs/exports)
- [Invoices](https://pentestllm.ai/docs/invoices)
- [Billing details](https://pentestllm.ai/docs/billing-details)
- [Statement signing key](https://pentestllm.ai/docs/statements-public-key)
- [Keys and scopes](https://pentestllm.ai/docs/keys)
- [Usage and signed receipts](https://pentestllm.ai/docs/usage-and-receipts)
- [Spend limits and balance](https://pentestllm.ai/docs/spend-limits)
- [Redaction and guardrails](https://pentestllm.ai/docs/redaction-and-guardrails)
- [Embeddings, rerank and moderation](https://pentestllm.ai/docs/retrieval-and-moderation)
- [Batch files](https://pentestllm.ai/docs/files)
- [Batches](https://pentestllm.ai/docs/batches)
- [Status and proof feeds](https://pentestllm.ai/docs/status-and-proof)
- [Count tokens](https://pentestllm.ai/docs/count-tokens)
- [Usage by app](https://pentestllm.ai/docs/stats-apps)
- [App sign-in keys](https://pentestllm.ai/docs/auth-keys)
- [Webhook deliveries](https://pentestllm.ai/docs/webhooks-deliveries)
- [Docs: connect in two minutes](https://pentestllm.ai/docs)
- [Sessions, usage export and log streaming](https://pentestllm.ai/features/observability)
