> ## Documentation Index
> Fetch the complete documentation index at: https://humain.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin

> Native Android SDK for Humain Kiosk — text sessions, Kotlin Flow streaming, and WebRTC voice.

The Kotlin SDK wraps the Humain Device API with coroutine-native suspend functions and Kotlin
`Flow` for streaming. It is the only server-side SDK that includes WebRTC voice — audio
capture, WebRTC negotiation, and VAD are all handled inside the SDK.

For a complete integration walkthrough — including Gradle setup, Compose ViewModel examples,
runtime permission handling, and AudioManager configuration — see the
[Android guide](https://humain.mintlify.site/mobile/android-kotlin.md).

> [!TIP]
>
> During development, initialise the client with an `hk_test_…` sandbox credential instead of
> `hk_live_…`. There is no separate sandbox mode or URL — sandbox behavior comes entirely from
> the credential prefix. No AI credits are consumed and no usage is billed. See
> [Sandbox mode](https://humain.mintlify.site/concepts/sandbox-mode.md).

***

## Install

```kotlin theme={null}
// build.gradle.kts
dependencies {
    implementation("ai.humain:kiosk-android:1.0.0")
}
```

Add permissions to `AndroidManifest.xml`:

```xml theme={null}
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
```

***

## Quick example

```kotlin theme={null}
val client = KioskClient(KioskConfig(
    credential = BuildConfig.HUMAIN_CREDENTIAL
))

val session = client.openSession()
val response = session.sendMessage("What are your opening hours?")
println(response.text)
session.close()
```

***

## `KioskConfig` fields

**credential** `String` *required*

Your device credential token in `hk_live_…` format. Store in `BuildConfig` (injected from
`local.properties`) — never commit to source control.

**mode** `KioskConfig.Mode` (default: Mode.LIVE)

`Mode.SANDBOX` returns instant stub responses without consuming AI credits. Use `Mode.LIVE`
for production.

**timeoutSeconds** `Long` (default: 30)

OkHttp call timeout in seconds. Applied to the session open call and each `sendMessage()`
call.

**maxRetries** `Int` (default: 2)

Number of automatic retries on provider errors (`503`). Uses exponential back-off starting
at 1 second.

**baseUrl** `String` (default: "[https://api.humain.ai](https://api.humain.ai)")

Override the API base URL. Useful for testing against a local proxy or staging environment.

***

## Exception types

**KioskException.AuthenticationException** `KioskException`

`401` — invalid or revoked credential.

**KioskException.RateLimitException** `KioskException`

`429` — too many requests. Check `retryAfterSeconds` for the minimum wait time.

**KioskException.ProviderException** `KioskException`

`503` — LLM temporarily unavailable. Check `isRetryable` before retrying.

**KioskException.MicrophonePermissionException** `KioskException`

`RECORD_AUDIO` permission was not granted before calling `openVoiceSession()`. Request the
permission in your Activity or Composable before starting a voice session.

**KioskException.SessionEndedException** `KioskException`

Thrown when calling `sendMessage()` or `stream()` on a session that has been closed.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.