Skip to content

Session Tokens

Session tokens are one-time-use tokens that grant a single play of a game or stream. They prevent abuse by ensuring each token can only be consumed once.

A session token goes through the following states:

active → consumed (user played the game)
→ expired (token passed its expiration time)
→ revoked (manually invalidated)

Call the session creation endpoint from your server with your API key:

Terminal window
curl -X POST https://app.dailyplay.ai/api/org-api-keys?action=create-session \
-H "Content-Type: application/json" \
-H "x-api-key: dpk_YOUR_API_KEY" \
-d '{
"game_id": 42,
"external_ref": "user-12345",
"metadata": { "campaign": "summer-promo" },
"expires_in_minutes": 60
}'
ParameterTypeRequiredDescription
game_idnumberOne of game_id or stream_idThe game to grant access to
stream_idnumberOne of game_id or stream_idThe stream to grant access to
external_refstringNoYour reference ID for tracking (e.g., user ID, order ID)
metadataobjectNoArbitrary JSON data for your own tracking
expires_in_minutesnumberNoToken expiry in minutes (default: 1440 = 24 hours)
{
"success": true,
"data": {
"token": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"stream_id": null,
"game_id": 42,
"expires_at": "2026-02-17T12:00:00.000Z",
"external_ref": "user-12345"
}
}

Build a URL with the session token and redirect the end user to it:

https://app.dailyplay.ai/play/game/42?session_token=a1b2c3d4-e5f6-7890-abcd-ef1234567890

For streams:

https://app.dailyplay.ai/play/stream/10?session_token=a1b2c3d4-e5f6-7890-abcd-ef1234567890

Before allowing play, the token is validated to ensure it is still active and not expired:

Terminal window
curl https://app.dailyplay.ai/api/org-api-keys?action=validate-session&token=a1b2c3d4-e5f6-7890-abcd-ef1234567890
{
"success": true,
"data": {
"valid": true,
"status": "active",
"stream_id": null,
"game_id": 42,
"expires_at": "2026-02-17T12:00:00.000Z",
"external_ref": "user-12345",
"metadata": { "campaign": "summer-promo" }
}
}

When the user starts playing, the token is consumed so it cannot be reused:

Terminal window
curl -X POST https://app.dailyplay.ai/api/org-api-keys?action=consume-session \
-H "Content-Type: application/json" \
-d '{
"token": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"player_uuid": "player-uuid-here"
}'
{
"success": true,
"data": {
"session_id": 1,
"org_id": 5,
"stream_id": null,
"game_id": 42,
"external_ref": "user-12345",
"metadata": { "campaign": "summer-promo" }
}
}

If the token has already been used or has expired, the API returns a 410 Gone status:

{
"success": false,
"error": "Session is invalid, already consumed, or expired"
}
PropertyDescription
tokenUUID v4 identifier — passed in the game URL
stream_id / game_idThe target resource (at least one is required)
external_refYour reference ID for correlating with your system
metadataArbitrary JSON payload you attached at creation
statusCurrent state: active, consumed, expired, or revoked
expires_atWhen the token will automatically expire
  • Tokens default to a 24-hour expiry if expires_in_minutes is not specified
  • Expired tokens are automatically cleaned up by a background process
  • You can set expiry as short as 1 minute for time-sensitive use cases
Status CodeMeaning
200Token is valid / operation succeeded
400Missing or invalid parameters
401Invalid or revoked API key
403API key does not have access to the requested resource
410Token is already consumed or expired
429Rate limit exceeded