Skip to main content
Sessions group related traces under one session ID, so you can view an entire conversation or multi-step workflow as a single unit and see total cost, tokens, and latency across it.

What are sessions?

A session represents a logical grouping of traces. Common examples:
  • A conversation with a user
  • A batch processing job
  • A multi-step workflow
  • A user’s session on your application

Creating sessions

There are two ways to create sessions: via span() / span_context() with session options (recommended), or via telemetry metadata on the model call.

Using span() with session options

Using telemetry metadata

For cases where you don’t need explicit spans, pass session info through the telemetry metadata on the model call:
In telemetry metadata, the session/user keys must be snake_case: session_id, session_name, user_id. The gateway only promotes these snake_case keys to session fields; it stores camelCase keys (sessionId, …) as ordinary metadata, which do not group traces into a session.
On the Vercel AI SDK v7, the telemetry.metadata option no longer reaches spans, so the metadata pattern above doesn’t group v7 traces. Use @agentmark-ai/otel to group sessions, users, and metadata on v7.
The telemetry option on prompt.format() applies only to prompts executed by the WebhookRunner (deployed webhooks), where the runner makes the model call and authors the telemetry for you. In direct usage the render is neutral and that option has no effect, so set telemetry on the model call as shown above.

Viewing sessions

Sessions page with search, filters, and sortable columns The Sessions page lists each session with columns for ID, name, user, duration, cost, tokens, and trace count. Search by session ID or name, pick a date range, and sort by any column. The Filters button opens the same filter builder as the Traces page, with session fields: User ID (string operators), Cost ($), Tokens, and Latency (ms) (numeric operators), and Tags (equals, not equals, contains). Access sessions under the Sessions tab in the Dashboard or at http://localhost:3000 locally.

Sessions API

You can list sessions and retrieve a session’s traces programmatically using the CLI or REST API. Both the local dev server and the AgentMark Cloud gateway expose /v1/sessions and /v1/sessions/{sessionId}/traces.
Both endpoints support pagination with limit and offset. The list endpoint also supports free-text filtering with search, date-range filtering with start_date and end_date, and sorting with sort_by and sort_order. See the Sessions API reference for full request and response details.

Best practices

  • Use consistent session IDs: session-${userId}-${Date.now()}, not ${Math.random()}
  • Provide descriptive names: "Customer Support: Billing Issue #4532", not "Session 1"
  • Limit session scope: one ticket, one conversation, one batch job
  • Create new sessions for new interactions: don’t reuse sessions across unrelated workflows

Tracing setup

Full span() API reference

Filtering and search

Find sessions across dimensions

Have questions?

Reach out any time: