Skip to main content

Client & Authentication

Before joining a call, it is necessary to set up the video client. Here's a basic example:

  1. Create the IStreamVideoClient instance
    _client = StreamVideoClient.CreateDefaultClient();
  2. Connect user to the Stream API
    var authCredentials = new AuthCredentials("api-key", "user-id", "user-token");
    await _client.ConnectUserAsync(authCredentials);
  • The API Key can be found in your Stream dashboard.
  • The User can be either authenticated, anonymous or guest.
  • Note: You can store custom data on the user object, if required.

Here's a complete example of a MonoBehaviour that initiates the client and connects to the Stream API:

using System;
using StreamVideo.Core;
using StreamVideo.Libs.Auth;
using UnityEngine;

public class VideoClient : MonoBehaviour
async void Start()
_client = StreamVideoClient.CreateDefaultClient();

var authCredentials = new AuthCredentials("api-key", "user-id", "user-token");
await _client.ConnectUserAsync(authCredentials);

// After we awaited the ConnectUserAsync the client is connected
catch (Exception e)

private IStreamVideoClient _client;

Generating a token

Tokens provide a way to authenticate a user or give access to a specific set of calls. They're similar to passwords but offer more flexibility, allowing you to set the expiry date. For security reasons, tokens need to be generated server-side. Typically, you integrate this into the part of your codebase where you login or register users. You can use our server-side SDKs to easily add support for this. For detailed instruction, refer to our server-side docs on installation and creating-users-and-user-tokens.

Here's a valid user and token to help you get started on the client side before integrating with your backend API:

Here are credentials to try out the app with:

API KeyWaiting for an API key ...
Token Token is generated ...
User IDLoading ...
Call IDCreating random call ID ...

Client options

Here's an example showing how you can pass configuration options through the StreamClientConfig instance passed to the CreateDefaultClient method:

var config = new StreamClientConfig
// Enabling Debug level logging can be helpful during development
LogLevel = StreamLogLevel.Debug,
Audio =
// Increase audio quality in exchange for higher bandwidth
EnableRed = false,

// DTX encodes silence at lower bitrate. This can save bandwidth
EnableDtx = false
_client = StreamVideoClient.CreateDefaultClient(config);

Did you find this page helpful?