Skip to content
StatusSupportDashboard

Create session

client_sessions.create_session(**kwargs) -> ClientSessionCreateSessionResponse { token, account_id, client_token, 2 more }
POST/v1/sessions

Create a SafetyKit identity session from server-side code before rendering pages that load the browser SDK. The request must be authenticated with a valid Bearer token.

ParametersExpand Collapse
customer_session_id: String

Customer session identifier to bind to this identity session.

duration_in_minutes: Integer

Token validity duration in minutes (1-180). Defaults to 60 if omitted.

minimum1
maximum180
user_id: String

Customer user identifier to bind to this identity session.

ReturnsExpand Collapse
class ClientSessionCreateSessionResponse { token, account_id, client_token, 2 more }

Response containing the session token and expiration details

token: String

Short-lived session token to use as Bearer token for API calls

account_id: String

Public account identifier to pass to the browser SDK

client_token: String

Client session token to pass to the browser SDK

expires_at: String

ISO 8601 timestamp when the token expires

expires_in: Float

Seconds until the token expires

Create session

require "safety_kit"

safetykit = SafetyKit::Client.new(api_key: "My API Key")

response = safetykit.client_sessions.create_session

puts(response)
{
  "token": "sk_session_abc123...",
  "account_id": "acct_abc123",
  "client_token": "sk_session_abc123...",
  "expires_at": "2025-05-15T14:30:00.000Z",
  "expires_in": 3600
}
Returns Examples
{
  "token": "sk_session_abc123...",
  "account_id": "acct_abc123",
  "client_token": "sk_session_abc123...",
  "expires_at": "2025-05-15T14:30:00.000Z",
  "expires_in": 3600
}