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

RouteStatuses
GET /v1/sessions200, 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:

ParameterTypeNotes
key_idstringOnly sessions with requests from this key.
daysinteger, 1 to 90How far back to look; 30 when omitted.
limitinteger, 1 to 200Rows per page; 50 when omitted.
beforeintegerThe 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:

FieldMeaning
idThe session id.
requestsHow many requests it holds.
first_atWhen its first request started, Unix milliseconds.
last_atWhen its last request ended, Unix milliseconds.
duration_msThe span between those two.
charge_microWhat it was charged, in micro-dollars.
cost_usdThe same charge in dollars.
input_tokensBilled prompt tokens, cached reads and writes included.
output_tokensGenerated tokens.
errorsRequests a model failed or refused. They are never charged.
modelsEvery model the session used.
key_idsEvery 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:

FieldMeaning
request_idThe request, readable on its own through the requests route.
started_atStart, Unix milliseconds.
ended_atEnd, Unix milliseconds.
key_idWhich key made the call.
modelModel that produced the answer.
outcomecompleted, client_disconnected, upstream_error or upstream_rejected.
statusThe HTTP status.
input_tokensPrompt tokens; cache_read_tokens, cache_write_tokens and output_tokens sit beside it.
charge_microCharge in micro-dollars, with cost_usd beside it.
latency_msMilliseconds the step took.
refund_reasonWhy the step went unbilled, when it did.
tool_callsServer 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

shell
1curl "https://api.pentestllm.ai/v1/sessions?days=7&limit=50" \
2 -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.

Join on TelegramHelp