Authentication
How PlayKit SDK authenticates the editor and players in Unity
Authentication
PlayKit has one identity model — a single account, with no developer/player wall. In the editor, the SDK runs on one of your API keys (AI usage is billed to your account). In a shipped build, each player authenticates themselves via device auth (usage is billed to that player). The SDK handles both automatically — you write no authentication code for the common case.
Editor Setup
Before running your game in the editor, configure the SDK once via the Settings window:
- In Unity, open Tools > PlayKit SDK > Settings
- Click Login — a browser window opens
- Sign in with your PlayKit account
- An API key is provisioned and stored automatically in EditorPrefs (never committed to source control)
- Select your game from the Game Selection dropdown
- Choose default AI models in the AI Model Defaults section
From this point on, the SDK uses your API key automatically whenever you run in the editor. No code changes are required.
Alternatively, if you have an API key from the dashboard, paste it directly in the Direct Key Input section of the Settings window instead of logging in.
An API key bills all API usage to your account, so it is for the editor only. The SDK displays a red warning indicator when running with an API key. Never ship an API key inside a build.
SDK Initialization (Runtime)
The SDK auto-initializes before any scene loads — you do not need to call any initialization code for basic usage:
// The SDK is already initializing before this runs.
// Just start using it:
var chatClient = PlayKitSDK.Factory.CreateChatClient();If you need to explicitly wait for initialization to complete (for example, before showing your main menu):
using Cysharp.Threading.Tasks;
using PlayKit_SDK;
using UnityEngine;
public class GameStartup : MonoBehaviour
{
async void Start()
{
await PlayKitSDK.InitializeAsync();
// SDK is now initialized and authenticated
ShowMainMenu();
}
}Authentication Order
At runtime, the SDK authenticates in this order:
- Editor API key — if configured in Settings, use it (editor only; not present in a build)
- Cross-game shared credential — if the player previously signed in to any PlayKit game on this device, reuse that credential
- Local credential — if the player previously signed in to this game, use the saved credential
- Login UI — if no valid credential is found, display the built-in device auth interface (
LoginWeb.prefab) for the player to sign in
Players only ever need to sign in once per device across all PlayKit games.
Player Client
Get Player Information
using PlayKit_SDK;
using UnityEngine;
public class PlayerInfoDisplay : MonoBehaviour
{
void Start()
{
var playerClient = PlayKitSDK.GetPlayerClient();
var playerInfo = playerClient.GetCachedPlayerInfo();
if (playerInfo != null)
{
Debug.Log($"Player ID: {playerInfo.UserId}");
Debug.Log($"Remaining credits: {playerInfo.Credits}");
}
}
}Refresh Player Information
using Cysharp.Threading.Tasks;
using PlayKit_SDK;
public async UniTask RefreshPlayerInfo()
{
var playerClient = PlayKitSDK.GetPlayerClient();
var result = await playerClient.GetPlayerInfoAsync(
this.GetCancellationTokenOnDestroy()
);
if (result.Success && result.Response != null)
{
Debug.Log($"Player ID: {result.Response.UserId}");
Debug.Log($"Current credits: {result.Response.Credits}");
}
else
{
Debug.LogError($"Failed to get player info: {result.ErrorMessage}");
}
}Listen for Player Info Updates
using PlayKit_SDK;
using UnityEngine;
public class PlayerInfoMonitor : MonoBehaviour
{
private PlayKit_PlayerClient playerClient;
void Start()
{
playerClient = PlayKitSDK.GetPlayerClient();
playerClient.OnPlayerInfoUpdated += HandlePlayerInfoUpdated;
playerClient.OnPlayerTokenReceived += HandleTokenReceived;
playerClient.OnError += HandleError;
}
void OnDestroy()
{
if (playerClient != null)
{
playerClient.OnPlayerInfoUpdated -= HandlePlayerInfoUpdated;
playerClient.OnPlayerTokenReceived -= HandleTokenReceived;
playerClient.OnError -= HandleError;
}
}
void HandlePlayerInfoUpdated(PlayerInfo info)
{
Debug.Log($"Credits updated: {info.Credits}");
}
void HandleTokenReceived(string token)
{
Debug.Log("Player credential refreshed");
}
void HandleError(string error)
{
Debug.LogError($"Player client error: {error}");
}
}FAQ
Prepare for Release
The editor API key is stored in the editor's EditorPrefs and is never bundled into a build, so a distribution build automatically uses device auth. See Prepare for Release for the full checklist.
Next Steps
- Getting Started — SDK installation and first run
- Payment — configure player billing and credit management
- API Reference — complete authentication API reference