Skip to main content
The Alakazam Portal Swift package (AlakazamPortal) gives you the whole /v1 surface from Swift — generate and manage worlds, create talk-to characters, mint runtime sessions — plus a drop-in AI Character component. Requires iOS 15+ (macOS 12+ also supported).

Install

Add the package in Xcode (File → Add Package Dependencies…), or declare it in your Package.swift:
Zero dependencies — Foundation + AVFoundation only.

Setup

1

Get a key

Start with an sk_test_… secret key (get one here) — it runs a free, mocked sandbox. Swap to sk_live_… when you ship.
2

Store it

For prototype/backend use, stash the key in the Keychain with AlakazamAuth.setApiKey(_:) and construct AlakazamClient() with no arguments — it reads the stored key automatically. Or just pass the key straight through: AlakazamClient(secretKey: "sk_test_…").
Secret keys are prototype/server-only. Your sk_ key can create worlds and mint sessions, so never ship it inside your app. At runtime, a player talks to a character through a short-lived session token minted by your backend — the two-token rule.

Programmable worlds & AI characters (/v1)

AlakazamClient is a thin async/await wrapper over the /v1 API. Construct it with your secret key, or pass nothing to reuse the key stored in the Keychain.
List, fork, edit, and import compiled worlds:
A sk_test_… key returns deterministic mocks — every response carries mock: true, and nothing spends GPU or quota. Build your whole integration for free, then swap to sk_live_…. See Testing.

Drop-in AI Character

AlakazamCharacter is a @MainActor ObservableObject that wraps the session → say → speak loop as an NPC you can drop into any SwiftUI view or UIKit screen.
1

Create it

Construct with the characterId from client.createCharacter(...) (below) and, in a shipped app, a sessionToken minted by your backend:
2

Wire it up

Bind onReply / onError, or observe the @Published var lastReply / isConnected directly from SwiftUI.
3

Prototype without a backend

Leave sessionToken nil and pass a secretKey instead — the component mints one itself for prototyping. In a shipped build, never do this — assign a backend-minted token.
With autoSpeak on (default) it plays the reply through AVAudioPlayer automatically:
To create the character the component talks to (an editor/server step — needs the secret key), and to mint the session token your backend would hand the client:
The component also exposes speak(_:) (synthesize + play a line) and showImage(_:) (returns a show_image src). For a public, token-free share link to a public world, use AlakazamClient.publicPlayUrl(slug).

AlakazamClient reference

Every method maps 1:1 to a /v1 endpoint. Typed methods decode into a Codable struct; the raw endpoints return a JSONValue tree.
Optional params: frameB64 on createWorld / createCharacter (seed creation from a base64 image), cursor on listWorlds / listCharacters (pagination — pass the prior nextCursor), and ttlSeconds on mintSession (60–3600, omitted when 0). Empty optionals are omitted from the request body (never sent as ""), so payloads match the Unity/Unreal/Android SDKs.

Next steps

Android SDK

The same worlds + AI characters in Kotlin.

Characters

Stances, memory, voice, and images in depth.

The two-token rule

Mint session tokens server-side; never ship a secret key.

Testing sandbox

Build the whole integration free with a test key.