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: viaspan() / span_context() with session options (recommended), or via telemetry metadata on the model call.
Using span() with session options
- TypeScript
- Python
Using telemetry metadata
For cases where you don’t need explicit spans, pass session info through the telemetry metadata on the model call:- TypeScript
- Python
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

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.
- REST API (Cloud)
- REST API (local)
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:
- Email the team at hello@agentmark.co for support
- Schedule an Enterprise Demo to learn about AgentMark’s business solutions