iOS SwiftUI video call in three steps (no backend needed)

Get your App Key, install the SDK, then TitliVideo.initialize() and start or join a call. This guide follows the iOS quickstart for the native Swift SDK and adds the billing and error details you will want before shipping. Server tokens are an optional hardening step at the end.

What you will build

A SwiftUI button that opens a full-screen 1:1 video call, using only the App Key. TitliCallView asks for microphone and camera permission, joins, and shows the video (or the audio layout for audio calls), the timer, the reconnecting state and the end screen. You do not need a server; the App Key is publishable, and a project key secret, if you add a server later, never goes into the app.

The iOS SDK is in beta (version 0.2.0 adds Quick mode). Requirements: iOS 15 or later, Swift 5.9 or later and Xcode 15 or later. It wraps the open-source LiveKit Swift SDK (Apache-2.0). It installs with Swift Package Manager or CocoaPods from github.com/titli-video-sdk/titli-video-sdk-ios.

We do not promise a number of minutes: the path is three steps, and the first call usually takes longer because of account setup and signing. Product details: iOS video call SDK.

Prerequisites

  • A console account. Sign-up is self-serve. A new account starts with a welcome credit of ₹100 (INR accounts) or $1.20 (USD accounts), once per person or company, so your first test calls need no recharge.
  • No backend. Quick mode needs only the App Key in your app. A server of your own is optional, for production hardening.
  • Xcode 15 or later and an app target for iOS 15 or later. Test on a real iPhone: the camera needs a device.
  • Nothing to download: Xcode fetches the package from GitHub.

Quick mode: add your App Key, make a call in 5 minutes

No backend needed: add your App Key in the app and start calling. A server is optional, for production hardening.

  1. Get your App Key. In the console, open Projects → Quick mode and add your app's bundle ID. Your App Key is shown there.
  2. Install the package from Swift Package Manager (the console download is only a fallback).
    Package dependency
    // Xcode → File → Add Package Dependencies… → https://github.com/titli-video-sdk/titli-video-sdk-ios (from 0.2.0)
    // CocoaPods: pod 'TitliVideoSDK', :git => 'https://github.com/titli-video-sdk/titli-video-sdk-ios.git', :tag => '0.2.0'
    import TitliVideoSDK
  3. Init with the App Key, then start or join a call. That is all: no server, no tokens.
    App.swift
    import TitliVideoSDK
    
    // 1. Once, at launch: your App Key and your own user id
    TitliVideo.initialize(appKey: "tak_…", userId: "user-42", userName: "Asha")
    
    // 2. Start a video call
    let call = try await TitliVideo.startCall(type: .video)
    // share call.callId with the other person
    
    // 3. On the other phone
    try await TitliVideo.joinCall(callId)

The App Key is publishable, not a secret: it can only reach the app-facing routes, it is bound to your package name, bundle ID or website, and spend and usage caps fence it. The binding is a deterrent, not a lock (a determined attacker can copy an app's identity), so the caps are what limit the damage. For strict control, add server tokens (production hardening below). Quick mode: bindings, caps and error codes · Read the Client API (Quick mode).

Install details and Info.plist

Swift Package Manager (recommended): in Xcode choose File, then Add Package Dependencies, enter https://github.com/titli-video-sdk/titli-video-sdk-ios, pick version 0.2.0 (Up to Next Major) and add the TitliVideoSDK product to your app target. CocoaPods also works; LiveKit's dependencies live in LiveKit's own spec repository, so add it as a source.

Package.swift / Podfile
// Xcode: File > Add Package Dependencies > https://github.com/titli-video-sdk/titli-video-sdk-ios
.package(url: "https://github.com/titli-video-sdk/titli-video-sdk-ios", from: "0.2.0"),
.product(name: "TitliVideoSDK", package: "titli-video-sdk-ios"),

# CocoaPods
source 'https://cdn.cocoapods.org/'
source 'https://github.com/livekit/podspecs.git'
pod 'TitliVideoSDK', :git => 'https://github.com/titli-video-sdk/titli-video-sdk-ios.git', :tag => '0.2.0'

Then add the usage strings and the audio background mode to Info.plist:

Info.plist
<key>NSMicrophoneUsageDescription</key>
<string>We use the microphone so the other person can hear you on calls.</string>
<key>NSCameraUsageDescription</key>
<string>We use the camera so the other person can see you on video calls.</string>
<key>UIBackgroundModes</key>
<array><string>audio</string></array>

Initialize and present the call screen

MyApp.swift
import SwiftUI
import TitliVideoSDK

@main
struct MyApp: App {
    init() {
        // Once, at launch or after your own sign-in: the App Key and your own id for the user.
        TitliVideo.initialize(appKey: "tak_…", userId: "user-42", userName: "Asha")
    }
    var body: some Scene { WindowGroup { ContentView() } }
}
ContentView.swift
import SwiftUI
import TitliVideoSDK

struct ContentView: View {
    @State private var call: TitliCall?

    var body: some View {
        Button("Video call") {
            Task {
                // Caller: creates the call (this user is the payer) and joins it.
                call = try? await TitliVideo.startCall(type: .video)
                // Share call?.callId with the other person (your push, your chat, or Titli Chat calls).
                // The other person: call = try? await TitliVideo.joinCall(callId)
            }
        }
        .fullScreenCover(isPresented: Binding(get: { call != nil }, set: { if !$0 { call = nil } })) {
            if let c = call {
                TitliCallView(call: c, title: "Asha",
                              theme: TitliTheme(brandColor: Color(titliHex: 0x6D4AFF))) { _ in call = nil }
            }
        }
    }
}

startCall and joinCall return a connected TitliCall with callId set. joinCall(callId, role: .host) joins as the host. TitliVideo.setUser(_:userName:) switches the signed-in user. The closing closure receives the end reason; TitliTheme takes a brandColor and an appearance (system, light or dark).

Own the call object (optional)

To listen to events or build your own UI, keep the call and pass it in:

Call.swift
let call = try await TitliVideo.startCall(type: .video)
call.onEvent = { event in
    switch event {
    case .participantJoined(let p): print("\(p.name) joined")
    case .participantLeft(let p): print("\(p.name) left")
    case .reconnecting: print("reconnecting")
    case .callEnded(let reason, let serverReason): print("ended: \(reason) \(serverReason ?? "")")
    case .error(let e): print(e.localizedDescription)
    default: break
    }
}
TitliCallView(call: call, title: "Asha", theme: TitliTheme(brandColor: .pink, appearance: .dark))

TitliCall is an ObservableObject. Its published state includes state (connecting, connected, reconnecting, ended), participants, isMicrophoneEnabled, isCameraEnabled, isSpeakerOn, localVideoTrack, duration (display only), endReason and serverReason. Controls: setMicrophoneEnabled(_:), toggleMicrophone(), setCameraEnabled(_:), toggleCamera(), switchCamera(), setSpeakerOn(_:), toggleSpeaker() and leave(). Render your own video with TitliVideoView(track:). The system call UI through CallKit is optional (TitliCallKit).

Our servers write your account's maximum video resolution into every join token, and the SDK never captures or sends above it. Our video is capped at 720p.

Audio calls

Start the call with TitliVideo.startCall(type: .audio). Audio calls cannot publish a camera; the SDK switches to audio-only (isAudioOnly == true) and the prebuilt screen shows the audio layout.

End the call and keep the receipt

Either person hangs up from the call screen. To end the call for everyone from the app, a participant calls TitliVideo.calls.end(callId). A call also ends by itself 30 seconds after everyone has left (a quick reconnect inside that window continues the same call), when its maximum length is reached (in Quick mode the project's Quick-mode call limit applies), or when your balance reaches zero.

Every ended call has an Ed25519-signed receipt you can keep for disputes. Receipts, like balance and usage reports, are read with the project key, so they are server-only; you also see every call in the console. With a server (production hardening), your backend can end any call and fetch its receipt:

terminal
curl -s -u "$AUTH" -X POST $API/v1/calls/<call_id>/end
curl -s -u "$AUTH" $API/v1/calls/<call_id>/receipt

More in Webhooks and signed receipts.

How billing applies

  • Measured on our servers. Minutes come from the media server's own join and leave events. Nothing the app reports changes the bill.
  • Per participant-minute by default: ₹0.05 for audio and ₹0.20 for video (up to 720p). A 10-minute 1:1 video call is 2 × 10 = 20 participant-minutes, so 20 × ₹0.20 = ₹4.00.
  • Billed per second, and only while at least two people are connected. A person waiting alone is not billed.
  • Free seconds for your users (first call and daily), if you set them on your account, are used before your balance.
  • Prepaid balance. A new call or token is refused with 402 when the balance cannot cover it, and live calls end when the balance runs out. It never goes below zero.
  • Quick-mode caps. With the App Key, the project's Quick-mode daily spend cap and each user's daily minutes, both set in the console, fence what one app or one user can spend.

The arithmetic, including call-minute billing, is worked through in Per-minute pricing explained. The rules are in Billing and usage and the price list is on the pricing page.

Troubleshooting

When a call ends, the SDK tells you why:

End reasonWhen
hungUpThis device left the call.
endedByServerThe call was ended for everyone (by a participant, or by your backend if you use one), the balance reached zero, the maximum length was reached, a Quick-mode limit was hit, or an operator ended it. The exact end_reason is on the call (TitliVideo.calls.get) and in the call.ended webhook.
removedThe call's creator (or your backend) removed this participant.
joinedElsewhereThe same end_user_id joined from another device.
connectionLostThe network dropped and did not recover.
failedToConnectThe join token was invalid or expired, or there was no network.

In Quick mode, every failed request raises one error type (TitliVideoError) carrying errorCode, userCode, userMessage (and the Hindi userMessageHi), a developer message and httpStatus. Show userMessage to your user as it is. The Quick-mode codes:

Error codeShown asHTTPWhen
APP_KEY_INVALIDAK-401401The App Key is missing, wrong, rotated away or disabled.
QUICK_MODE_OFFQM-403403Quick mode is switched off for the project.
APP_NOT_ALLOWEDAB-403403This package name, bundle ID, website or signing certificate is not on the App Key's list. Add it under Projects → Quick mode.
QUICK_DAILY_CAP_REACHEDQC-402402The project's Quick-mode daily spend cap is reached.
END_USER_DAILY_LIMITUM-429429This user has used today's minutes.
FORBIDDENFB-403403Acting as another user, or on a call this user is not in.
RATE_LIMITEDRL-429429Too many requests from one device or network; wait for Retry-After.

Retry only 429 (after Retry-After) and server errors (back off 1, 2 and 4 seconds); never retry the others. With server tokens, the API answers your server with { "error": { "code", "message" } }. The codes you are most likely to meet there:

HTTPCodeWhat to do
401invalid_api_key, key_revoked, key_expiredThe key ID or secret is wrong, or the key was revoked or has expired. unauthorized means no Basic auth header was sent. Check the key ID and secret on your server.
402insufficient_balance, project_cap_reachedThe balance is too low and the payer has no free seconds, or the project reached the daily spending cap set in the console.
403calls_disabled, audio_disabled, video_disabledThe account, project or call type is switched off.
409call_endedYou asked for a token on a call that has ended. Create a new call.
429concurrency_limit, rate_limitedUp to 5 calls at once per account unless support raises it; 20 requests per second per key (burst 40).

The full list is in the REST API reference and on Errors.

The native SDKs report these errors: invalidToken, tokenExpired (checked before connecting), permissionDenied (microphone or camera), connectionFailed, audioOnly (the camera was requested in an audio call) and mediaFailed. In Quick mode the SDK fetches a fresh join token itself. With server tokens, a token that expired before the user tapped Join is the most common one: mint tokens right before joining.

In Quick mode, startCall and joinCall throw TitliVideoError; show its userMessage (or userMessage(for: "hi")). A token join with TitliCall.join throws TitliError.invalidToken, .tokenExpired and .connectionFailed.

Production hardening (optional): server tokens

You do not need a server to start: Quick mode works with the App Key alone. Add a server when you want strict control over every call (who joins which call, for how long, in which role): keep the project key on your server and mint a short-lived join token per person there. The app uses the same SDK and hands it a token instead of the App Key. Both ways can run side by side.

The app keeps the same SDK and TitliCallView; it joins with a token from your server instead of the App Key.

Create a project key

Server tokens use a project key, not the App Key. In the console, open Projects. Each project has these server values:

ValueWhere it goes
App ID (app_…)Identifies the project. Safe to log.
Key ID (tk_…) and key secret (ts_…)Your backend only. The secret is shown once.
Webhook secret (whsec_…)Your backend only, to verify webhooks.

A project can hold two active keys, so you can rotate without downtime: create the new key, deploy it, then revoke the old one. More in Authentication and tokens.

Get a token from your server

Your server keeps the API key and calls our REST API: POST /v1/calls, then POST /v1/calls/{call_id}/tokens. This complete Node endpoint has no dependencies (Node 20 or newer) and works for every platform. It returns the two values the app needs, token and livekit_url.

token-server.js
// token-server.js: POST /titli/token {"type":"video"} -> {token, livekit_url, call_id}
import http from 'node:http';
const API = 'https://api-videosdk.titliapp.com';
const AUTH = 'Basic ' + Buffer.from(`${process.env.TITLI_KEY_ID}:${process.env.TITLI_KEY_SECRET}`).toString('base64');
const titli = async (path, body) => {
  const r = await fetch(API + path, { method: 'POST', headers: { Authorization: AUTH, 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
  if (!r.ok) throw new Error(`${r.status} ${await r.text()}`);
  return r.json();
};
http.createServer(async (req, res) => {
  let raw = ''; for await (const c of req) raw += c;
  try {
    const { type = 'video' } = JSON.parse(raw || '{}');
    const me = 'user_1001'; // YOUR signed-in user's id (from your own session/auth), not from the request body
    const call = await titli('/v1/calls', { type, payer_end_user_id: me, max_duration_seconds: 1800 });
    const t = await titli(`/v1/calls/${call.id}/tokens`, { end_user_id: me, role: 'user', name: 'Ravi' });
    // Mint the other person's token the same way (role "host") and deliver it to them (push, socket, ...).
    res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({ token: t.token, livekit_url: t.livekit_url, call_id: call.id }));
  } catch (e) { res.writeHead(502).end(JSON.stringify({ error: String(e.message) })); }
}).listen(8080);

Take the user's identity from your own session, never from the request body, and mint the other person's token the same way with role: "host". end_user_id is your own stable, pseudonymous id (1 to 128 characters of letters, digits and _ . : @ -). Tokens expire after 10 minutes by default (ttl_seconds); that limits when a person can join, not how long they stay. Fields and limits are in the REST API reference and Authentication and tokens.

In the app, call that endpoint:

TitliJoin.swift
struct TitliJoin: Decodable { let token: String; let livekit_url: String }

func fetchToken(type: String) async throws -> TitliJoin {
    var req = URLRequest(url: URL(string: "https://your-server.example/titli/token")!)
    req.httpMethod = "POST"
    req.setValue("application/json", forHTTPHeaderField: "Content-Type")
    req.httpBody = try JSONEncoder().encode(["type": type])
    let (data, _) = try await URLSession.shared.data(for: req)
    return try JSONDecoder().decode(TitliJoin.self, from: data)
}

Present the call screen with the token

ContentView.swift
import SwiftUI
import TitliVideoSDK

struct ContentView: View {
    @State private var join: TitliJoin?

    var body: some View {
        Button("Video call") { Task { join = try? await fetchToken(type: "video") } }
            .fullScreenCover(isPresented: Binding(get: { join != nil }, set: { if !$0 { join = nil } })) {
                if let j = join {
                    TitliCallView(url: j.livekit_url, token: j.token, title: "Asha",
                                  theme: TitliTheme(brandColor: Color(titliHex: 0x6D4AFF))) { _ in join = nil }
                }
            }
    }
}

To own the call object, join with TitliCall.join(url:token:options:):

Call.swift
let call = try await TitliCall.join(url: url, token: token, options: .init(audioOnly: false))
call.onEvent = { event in
    switch event {
    case .participantJoined(let p): print("\(p.name) joined")
    case .participantLeft(let p): print("\(p.name) left")
    case .reconnecting: print("reconnecting")
    case .callEnded(let reason, let serverReason): print("ended: \(reason) \(serverReason ?? "")")
    case .error(let e): print(e.localizedDescription)
    default: break
    }
}
TitliCallView(call: call, title: "Asha", theme: TitliTheme(brandColor: .pink, appearance: .dark))

For an audio call, create it with "type": "audio" on your server (call fetchToken(type: "audio")).

FAQ

Do I need a backend to add video calls to a SwiftUI app?

No. Get your App Key from the console (Projects, then Quick mode), add your bundle ID, install the package, init with the App Key and start a call. A server is optional: add one later for production hardening with server tokens.

Is it safe to put the App Key in my app?

Yes, it is publishable, not a secret. It can only start and join calls and use the other app-facing features, it is bound to your package name, bundle ID or website, and the spend and usage caps you set in the console fence it. The binding is a deterrent, not a lock, so the caps are what limit any damage. For strict control, add server tokens.

What does a test call cost?

Nothing out of pocket at first: a new account gets a welcome credit of ₹100 or $1.20, once per person or company. After that, video is ₹0.20 and audio ₹0.05 per participant-minute, billed per second, only while two people are connected.

When should I add server tokens?

When you want strict control over who joins which call, for how long and in which role, or when your app charges its users per minute from a wallet. Wallet debits belong on a server you trust, not in the app. Calls themselves work with the App Key alone.

Next steps

Free SDK. Pay only for the minutes you use.

Create a free account: it starts with ₹100 welcome credit, about 250 minutes of 1:1 video, so your first call needs no recharge. Questions? Message us on WhatsApp and a person replies.

Start free