# Client & Authentication

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

```kotlin
val client = StreamVideoBuilder(
     context = context,
     apiKey = apiKey,
     geo = GEO.GlobalEdgeNetwork,
     user = user,
     token = token,
).build()
```

- 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.

Typically, you'll want to initialize the client in your app's `Application` class or dedicated dependency injection module.

### Generating a token

- Tokens need to be generated server side. You can use our server side SDKs to quickly add support for this.
  Typically you integrate this into the part of your codebase where you login or register users.
  The tokens provide a way to authenticate a user or give access to a specific set of calls.

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

### Different types of users

- Authenticated users are users that have an account on your app.
- Guest users are temporary user accounts. You can use it to temporarily give someone a name and image when joining a call.
- Anonymous users are users that are not authenticated. It's common to use this for watching a livestream or similar where you aren't authenticated.

This example shows the client setup for a guest user:

```kotlin
val streamVideo = StreamVideoBuilder(
    context = context,
    apiKey = apiKey,
    geo = GEO.GlobalEdgeNetwork,
    user = User(id = "guest", type = UserType.Guest)
).build()
```

And here's an example for an anonymous user

```kotlin
val streamVideo = StreamVideoBuilder(
    context = context,
    apiKey = apiKey,
    geo = GEO.GlobalEdgeNetwork,
    user = User(id = "anonymous", type = UserType.Anonymous)
).build()
```

Anonymous users don't establish an active web socket connection, therefore they won't receive any events. They are just able to watch a livestream or join a call.

The token for an anonymous user should contain the `call_cids` field, which is an array of the call `cid`'s that the user is allowed to join.

Here's an example JWT token payload for an anonymous user:

```kotlin
{
  "iss": "@stream-io/dashboard",
  "iat": 1726406693,
  "exp": 1726493093,
  "user_id": "!anon",
  "role": "viewer",
  "call_cids": [
    "livestream:123"
  ]
}
```

### Client options

Here's a more complete example of the client options:

```kotlin
val streamVideo = StreamVideoBuilder(
    context = context,
    apiKey = apiKey,
    geo = GEO.GlobalEdgeNetwork,
    user = user,
    token = token,
    tokenProvider = { error ->
        // make an API call here to get a new token from your backend
    },
    loggingLevel = LoggingLevel(priority = Priority.DEBUG), // set the logging level
).build()
```

Once you invoke the `build()` method of `StreamVideoBuilder`, you can get the same instance of the `StreamVideo` with the `instance()` methods below:

```kotlin
val streamVideo = StreamVideo.instance()
```

If you don't need the user information, you can clear it by calling the `logout()` method like so:

```kotlin
val streamVideo = StreamVideo.instance()
streamVideo.logOut()
```

Lastly, if you don't need to use the `StreamVideo` instance anymore, you can uninstall it by calling `removeClient()` method:

```kotlin
StreamVideo.removeClient()
```

### Logging Stream SDK

Stream SDK allows you to trace log messages and debug what's going on and what problems you're facing. By setting the logging level on `StreamVideoBuilder`, you can filter the log messages depending on the priority:

```kotlin
val streamVideo = StreamVideoBuilder(
  loggingLevel = LoggingLevel(priority = Priority.DEBUG),
  ..
)
```

We provide the following 6 different logging levels: Verbose, Debug, Info, Warn, Error, and Assert. The default logging level is Error.

### Call Configurations

Stream SDK allows you to configure specific behavior for different types of calls (e.g., default call, livestream call, audio call) by using `CallServiceConfigRegistry`

**Key Call Configurations:**

- **Foreground Notifications:** Control the visibility of foreground notifications during calls.
- **Audio Usage:** Set the type of audio usage for the call
  - `AudioAttributes.USAGE_VOICE_COMMUNICATION`
  - `AudioAttributes.USAGE_MEDIA`
- **Foreground Service Class:** Customize the behavior of the foreground service for specific call types.

For full details and advanced configuration options, please refer to our [Call Configurations guide](/video/docs/android/guides/call-service-configurations/)

### Builder parameters

The following table lists all supported `StreamVideoBuilder` constructor parameters.

| Option                      | Description                                                                                                       | Default                       |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------- |
| `apiKey`                    | The API key to use. Found in the dashboard                                                                        | -                             |
| `geo`                       | The GEO routing policy. Defaults to the global edge network. Configure this if you need specific geofencing rules | GEO.GlobalEdgeNetwork         |
| `user`                      | The user object. You can store custom data on the user                                                            | -                             |
| `token`                     | The JWT token to use for authentication                                                                           | -                             |
| `tokenProvider`             | A function to call if the token is expired or invalid                                                             | null                          |
| `loggingLevel`              | The logging level. Recommend to set it to debug while in development                                              | LoggingLevel.BASIC            |
| `enablePush`                | If push notifications should be enabled                                                                           | false                         |
| `pushDeviceGenerators`      | Support Firebase and other push providers                                                                         | false                         |
| `encryptPreferences`        | If our data store should encrypt the api key, user token etc.                                                     | true                          |
| `ensureSingleInstance`      | Verify that only 1 version of the video client exists, prevents integration mistakes.                             | true                          |
| `ringNotification`          | A function to create your own notification when there's an incoming "ringing" call                                | null                          |
| `audioFilters`              | Run audio through a filter before sending it                                                                      | -                             |
| `videoFilters`              | Run video through a filter before sending it                                                                      | -                             |
| `sounds`                    | Customize the sounds used by the SDK                                                                              | `Sounds()`                    |
| `callServiceConfigRegistry` | A registry for managing call configurations related to different call types like default, livestream, audio, etc. | `CallServiceConfigRegistry()` |


---

This page was last updated at 2026-03-13T13:17:46.699Z.

For the most recent version of this documentation, visit [https://getstream.io/video/docs/android/guides/client-auth/](https://getstream.io/video/docs/android/guides/client-auth/).