Understanding Sessions
A session represents a logical user interaction or instance of your application running. Think of it as a container that groups related completions together for analysis. Thesessions.create() method generates a session ID (UUID v4) and returns a Session object. You can also optionally set custom metadata at creation time. While you could generate your own UUID and let the session be created implicitly when recording your first completion, using sessions.create() is the recommended pattern.
Create a new session when:
- A user starts a new conversation
- A distinct workflow or task begins
- A new instance of your application starts handling requests
Methods Overview
| Method | Description | Python | TypeScript | Java/Kotlin |
|---|---|---|---|---|
| Create | Create a new session | sessions.create() | sessions.create({}) | sessions().create() |
| Delete | Delete a session | sessions.delete(project_id, session_id) | sessions.delete(projectId, sessionId) | sessions().delete(projectId, sessionId) |
Create a Session
Custom Metadata
Freeplay enables you to log Custom Metadata associated with any Session. This is fully customizable and can take any arbitrary key-value pairs. Thecustom_metadata parameter accepts a dictionary (Python) or object (TypeScript/JavaScript) with arbitrary key-value pairs. Use Custom Metadata to record things like customer ID, thread ID, RAG version, Git commit SHA, or any other information you want to track.
Delete a Session
Using Sessions with Completions
When you record a completion, pass thesession_info from your session to associate the completion with that session:

