MultiVibe Cloud

Developers

← Back to dashboard

SDK GUIDE / SOURCE PREVIEW

Swift API client

Cloud + optional Apple system adapter

Looking for sign-in and a ready-made chat interface? Use the iOS chat SDK guide. This page covers the lower-level Cloud API client.

1. Set up your project

Start from sdk/swift in the Cloud repository. These commands use the local source package, not a registry release.

swift test
# Add sdk/swift as a local Swift package in Xcode.
# Link MultiVibe and optionally MultiVibeLocal.

2. Prepare authentication

Server examples read MULTIVIBE_BASE_URL and MULTIVIBE_TOKEN from the environment. Use an origin without /v1. Never ship a project key in a browser or mobile bundle.

For client applications, use a user-authorized OAuth access-token provider and OS-secure storage. Browser refresh and exchange require a backend. Backendless publisher-funded sessions are not implemented.

Follow the OAuth + PKCE guide →

3. Make your first request

This example discovers models and demonstrates optional local execution after an availability check. Mobile snippets belong in your authenticated application; they are not standalone app projects.

Examples/Example.swift
// Embed in your application's authenticated flow; sessionToken must not be a project key.
import Foundation
import MultiVibe
import MultiVibeLocal
func example(baseURL: URL, sessionToken: @escaping @Sendable () async throws -> String) async throws {
 let client = try MultiVibe(baseURL: baseURL, token: sessionToken)
 _ = try await client.models()
 let local = AppleLocalEngine()
 if await local.availability().available {
  _ = try await Router(cloud: client, local: local).generate(prompt: "Bonjour", execution: .local)
 }
}

Next steps

Choose a compatible model from the catalog before inference. Handle expired access, insufficient scope and unavailable models separately. Never retry a billable inference blindly after a timeout or partial stream.

Operations, streaming and usage →

Local execution and fallback policy →