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

# Sessions API

> Programmatically create investigations, send follow-up questions, and retrieve results from Traversal using the V1 Sessions API.

The Sessions API lets you start investigations, send follow-up questions, and fetch results from your own tools. A session is the API object for an investigation.

All endpoints require authentication. [Create an API key](https://docs.traversal.com/api/authentication.md) first. For the base URL, error envelope, and generic status codes, see the [API overview](https://docs.traversal.com/api/overview.md). The sidebar lists every endpoint, generated from the OpenAPI spec.

## Required roles

Personal API keys use their owner's current role. [Service-account keys](https://docs.traversal.com/setup/service-accounts.md) use the account's current role, not the role of the administrator who created the key. Most Sessions endpoints require **Member**, but `GET /v1/sessions` is Admin-only because it returns API sessions across the organization.

| Action | Endpoint | Minimum role |
| - | - | - |
| Create a session | `POST /v1/sessions` | `member` |
| List sessions | `GET /v1/sessions` | **`admin`** |
| Get a session | `GET /v1/sessions/{session_id}` | `member` |
| Stream session status | `GET /v1/sessions/{session_id}/events` | `member` |
| Send a follow-up | `POST /v1/sessions/{session_id}/messages` | `member` |

A request from an underprivileged key returns `403 Forbidden`. If `GET /v1/sessions` fails, check the role of the personal key's owner or the service account in **Settings → Account management**.

Follow-ups require the identity that owns the session. Keys belonging to the same service account share session ownership, so a replacement key can continue that account's investigations. A key for a different account cannot send follow-ups to those sessions, even if both accounts belong to the same organization.

## Investigation depth

Both `POST /v1/sessions` and `POST /v1/sessions/{session_id}/messages` accept an optional `thinking_mode` field that sets how deeply Traversal investigates. See [Investigation depth](https://docs.traversal.com/using-traversal/investigations.md#investigation-depth) for guidance on choosing a mode.

| Mode | Behavior |
| - | - |
| `auto` (default) | Traversal classifies the request and picks an appropriate depth. |
| `deep` | Forces a thorough root-cause analysis. |
| `fast` | Runs a quick, exploratory pass. |

Existing integrations that omit `thinking_mode` use `auto`.

```bash theme={null}
curl -X POST https://api.traversal.com/v1/sessions \
  -H "Authorization: Bearer $TRAVERSAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "Checkout latency spiked at 14:30 UTC",
    "idempotency_key": "pagerduty-incident-P12345",
    "thinking_mode": "deep"
  }'
```

## Session lifecycle

Investigations are asynchronous. Creating a session or sending a follow-up returns immediately, and Traversal investigates in the background. Connect to `GET /v1/sessions/{session_id}/events` to wait for a terminal status, then retrieve the result with `GET /v1/sessions/{session_id}`.

### Status values

| Status | Meaning |
| - | - |
| `running` | A new investigation is in progress. |
| `idle` | Investigation is complete and ready for follow-ups. |
| `follow_up_running` | A follow-up message is being processed. |
| `failed` | The investigation or follow-up errored or timed out. |
| `cancelled` | The investigation was cancelled. |

`idle`, `failed`, and `cancelled` are terminal statuses. When a session reaches one, no further work is in progress.

> [!WARNING]
>
> Investigations have a 1-hour server-side timeout. If an investigation hasn't completed within that window, the session status changes to `failed`.

### Status transitions

```mermaid theme={null}
stateDiagram-v2
    [*] --> running: POST /v1/sessions
    running --> idle: Investigation complete
    running --> failed: Investigation error
    running --> cancelled: Investigation cancelled
    idle --> follow_up_running: POST /v1/sessions/{id}/messages
    follow_up_running --> idle: Follow-up complete
    follow_up_running --> failed: Follow-up error
    follow_up_running --> cancelled: Follow-up cancelled
```

### Stream status updates

The session events endpoint uses [Server-Sent Events](https://html.spec.whatwg.org/multipage/server-sent-events.html) to report lifecycle changes without polling. Send the same bearer token you use for other API requests and request `text/event-stream`:

```bash theme={null}
curl --no-buffer \
  -H "Authorization: Bearer $TRAVERSAL_API_KEY" \
  -H "Accept: text/event-stream" \
  https://api.traversal.com/v1/sessions/$SESSION_ID/events
```

The stream sends a named `status` event when you connect and whenever the status changes:

```text theme={null}
event: status
data: {"id":"a1b2c3d4-e5f6-7890-abcd-ef1234567890","status":"running","title":"Elevated error rate in checkout service","input":"Checkout latency spiked at 14:30 UTC","created_at":"2026-08-10T14:35:00Z","updated_at":"2026-08-10T14:35:00Z","messages":null}

: keepalive

event: status
data: {"id":"a1b2c3d4-e5f6-7890-abcd-ef1234567890","status":"idle","title":"Elevated error rate in checkout service","input":"Checkout latency spiked at 14:30 UTC","created_at":"2026-08-10T14:35:00Z","updated_at":"2026-08-10T14:38:12Z","messages":null}
```

Each `data` value uses the same session shape as other Sessions endpoints, but `messages` is always `null`. Fetch `GET /v1/sessions/{session_id}` after the terminal event to retrieve the conversation and final result.

While the status remains `running` or `follow_up_running`, the server sends a `: keepalive` comment every 15 seconds when there is no status change. SSE clients ignore comment lines automatically. The stream closes after it sends an `idle`, `failed`, or `cancelled` status.

### Python example

The following example creates an investigation, waits on the event stream, and retrieves the final messages:

```python theme={null}
import json
import os

import requests

base_url = "https://api.traversal.com"
headers = {"Authorization": f"Bearer {os.environ['TRAVERSAL_API_KEY']}"}

create_response = requests.post(
    f"{base_url}/v1/sessions",
    headers=headers,
    json={
        "input": "Checkout latency spiked at 14:30 UTC",
        "idempotency_key": "pagerduty-incident-P12345",
    },
)
create_response.raise_for_status()
created = create_response.json()

with requests.get(
    f"{base_url}/v1/sessions/{created['id']}/events",
    headers={**headers, "Accept": "text/event-stream"},
    stream=True,
    timeout=(10, 30),
) as response:
    response.raise_for_status()
    for line in response.iter_lines(chunk_size=1, decode_unicode=True):
        if not line.startswith("data: "):
            continue
        session = json.loads(line.removeprefix("data: "))
        if session["status"] in {"idle", "failed", "cancelled"}:
            break

result_response = requests.get(
    f"{base_url}/v1/sessions/{created['id']}",
    headers=headers,
)
result_response.raise_for_status()
result = result_response.json()
```

> [!TIP]
>
> Set a read timeout longer than the 15-second keepalive interval. If your client times out or the connection closes before a terminal status, reconnect to the same endpoint. The first event contains the current status, so you don't need an event cursor or `Last-Event-ID` header.

### Polling fallback

If your HTTP client or network path does not support streaming responses, poll `GET /v1/sessions/{session_id}` at a steady interval until the session is no longer `running` or `follow_up_running`. A 5-second interval is a reasonable default.

## Session-specific errors

In addition to the [generic status codes](https://docs.traversal.com/api/overview.md#status-codes), the Sessions API returns these session-specific responses:

| Status code | Meaning | When it occurs |
| - | - | - |
| `404` | Not Found | Session does not exist or does not belong to your organization. This validation happens before the event stream opens. |
| `409` | Conflict | Session is not `idle` (e.g., still `running` or `follow_up_running`). Includes `retry_after`. |
| `429` | Too Many Requests | Organization has reached the limit of 15 concurrent running sessions. Both new investigations (`POST /v1/sessions`) and in-flight follow-ups (`POST /v1/sessions/{id}/messages`) count toward this limit. Includes `retry_after` (default 30s). |


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