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

# Swift

> Native iOS and macOS SDK for Humain Kiosk — text, streaming, and WebRTC voice.

The Swift SDK wraps the Humain Device API with native Swift async/await and `AsyncSequence`
patterns. It is the only server-side SDK that includes WebRTC voice — all the audio session
management is handled inside the SDK without external dependencies.

For a complete integration walkthrough — including Xcode setup, SwiftUI examples, microphone
permission handling, and AVAudioSession configuration — see the
[iOS guide](https://humain.mintlify.site/mobile/ios-swift.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

In Xcode: **File → Add Package Dependencies** and enter:

```text theme={null}
https://github.com/humain-ai/kiosk-swift
```

Or add to `Package.swift`:

```swift theme={null}
dependencies: [
    .package(url: "https://github.com/humain-ai/kiosk-swift", from: "1.0.0"),
],
targets: [
    .target(name: "MyApp", dependencies: ["HumainKiosk"]),
]
```

***

## Quick example

```swift theme={null}
import HumainKiosk

let client = KioskClient(credential: "hk_live_your_credential_here")

let session = try await client.openSession()
let response = try await session.sendMessage("What are your opening hours?")
print(response.text)
try await session.close()
```

***

## `KioskClient` options

```swift theme={null}
let client = KioskClient(
    credential: "hk_live_your_credential_here", // hk_test_ for sandbox
    timeout: 30,
    maxRetries: 2
)
```

**credential** `String` *required*

Your device credential token, `hk_live_…` (production) or `hk_test_…` (sandbox). Issue
credentials from the Humain admin panel under **Kiosk → Credentials → Issue new credential**.
There is no separate client mode or URL for sandbox — it's determined entirely by which
credential you pass. See [Sandbox mode](https://humain.mintlify.site/concepts/sandbox-mode.md).

**timeout** `TimeInterval` (default: 30)

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

***

## Error types

**KioskError.authentication(message:)** `Error`

`401` — invalid or revoked credential.

**KioskError.rateLimited(retryAfter:)** `Error`

`429` — too many requests. The `retryAfter` value is the minimum wait in seconds.

**KioskError.providerUnavailable(retryable:)** `Error`

`503` — LLM temporarily unavailable. `retryable: true` means safe to retry with back-off.

**KioskError.microphonePermissionDenied** `Error`

The user denied microphone access. The app should guide the user to Settings to re-enable.

**KioskError.sessionEnded** `Error`

Returned when calling `sendMessage()` or `stream()` on a closed session.


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