Swift client library for Inworld APIs.
- LLM chat completion (
/llm/v1alpha/completions:completeChat) - Voice read endpoints (
/voices/v1/voices,/voices/v1/voices/{id}) - TTS REST synthesis (
/tts/v1/voice) - TTS bidirectional WebSocket session support (
/tts/v1/voice:streamBidirectional)
- Swift 6.2+
- Platforms:
- iOS 15+
- macOS 12+
- tvOS 15+
- watchOS 8+
Add this package in Xcode with your repository URL, or use Package.swift:
.package(url: "https://github.com/morozRed/InworldAiKit.git", from: "0.1.0")Then add "InworldAiKit" to your target dependencies.
Inworld supports Basic and JWT Bearer authentication.
- Server-side: Basic auth is supported.
- Client-side apps: use backend-issued JWT bearer tokens; do not ship long-lived Basic credentials.
import InworldAiKit
let client = InworldClient(
configuration: InworldConfiguration(
authProvider: BearerAuthProvider(token: "<JWT>")
)
)let response = try await client.llm.completeChat(
ChatCompletionRequest(
model: "inworld-model",
messages: [
ChatMessage(role: .system, content: "You are concise."),
ChatMessage(role: .user, content: "Give me one sentence about space.")
],
temperature: 0.2
)
)
print(response.text ?? "")let voices = try await client.voice.listVoices(pageSize: 20)
print(voices.voices.map(\.name))
if let first = voices.voices.first {
let voice = try await client.voice.getVoice(id: first.id)
print(voice)
}let tts = try await client.tts.synthesizeSpeech(
TTSSynthesizeSpeechRequest(
text: "Hello from InworldAiKit",
voiceID: "voice_123",
model: "inworld-tts",
audioConfig: TTSAudioConfig(audioEncoding: "MP3", sampleRateHertz: 44100)
)
)
let audioData = tts.decodedAudioDatalet session = try await client.tts.openWebSocketSession()
try await session.createContext(.init(model: "inworld-tts", voice: "voice_123"), contextId: "ctx1")
try await session.sendText("Streaming synthesis text", contextId: "ctx1", flush: true)
let stream = await session.events()
for try await event in stream {
switch event {
case .audioChunk(let chunk):
_ = chunk.decodedAudioData
case .status(let status):
print("status:", status)
default:
break
}
}API and transport errors are normalized into InworldError.
do {
_ = try await client.voice.listVoices()
} catch let error as InworldError {
print(error.kind, error.httpStatus ?? -1, error.message)
}swift testIncluded in current implementation:
- LLM completion
- Voice list/get
- TTS REST and streaming session primitives
Not included:
- STT endpoints