guides

SDK quickstart: Swift (iOS / macOS)

Generate a typed Swift client for the /v1 Developer API from its OpenAPI spec and make your first call.

No hand-written Swift SDK is published yet — you generate one from the live spec. An official SDK is a roadmap item.

Which credential? A shared API key (sk_live_…) is right for your own automation and server-side jobs. A first-party iOS app a user logs into should authenticate as that user with OAuth 2.0 + PKCE and send the user's token — see Build a client. The steps below use an API key; swap in the user's bearer token for a logged-in app.

1. Get the spec

https://api-dev.traxstreaming.live/v1/openapi.json

2. Generate a typed client

Use openapi-generator:

brew install openapi-generator      # or: npm i -g @openapitools/openapi-generator-cli
openapi-generator generate \
  -i https://api-dev.traxstreaming.live/v1/openapi.json \
  -g swift5 \
  --additional-properties=responseAs=AsyncAwait,projectName=TraxAPI \
  -o ./TraxAPI

Add the generated TraxAPI package to your Xcode project (drag it in, or add it as a local Swift Package).

Prefer Apple's toolchain? The Swift OpenAPI Generator is a first-party alternative (add it as an SPM plugin and point it at the same spec).

3. Authenticate

Create an API key from your account's Developer / API Keys screen and copy the sk_live_… secret once. Store it in the Keychain, never in source or Info.plist. For a user-login app, store the user's OAuth access token in the Keychain instead.

4. First call

import TraxAPI
import Foundation

// The generated client exposes the base path; set the auth header globally.
TraxAPIAPI.basePath = "https://api-dev.traxstreaming.live"
TraxAPIAPI.customHeaders = [
    "Authorization": "Bearer \(apiKeyFromKeychain)"   // or the user's OAuth token
]

// List your studios (requires the studios:read scope)
do {
    let page = try await StudiosAPI.listStudios(limit: 50)
    for studio in page.data {
        print(studio.id, studio.name)
    }
    if let cursor = page.nextCursor {
        // pass `cursor:` to fetch the next page — see /reference/pagination
        _ = cursor
    }
} catch {
    // Errors share one envelope: { error: { code, message, requestId } }.
    // Decode the response body to read error.code and branch on it.
    print("request failed:", error)
}

Generated method and model names (listStudios, StudiosAPI, nextCursor) come straight from the spec's operationIds and schemas, so they'll match what you see in the API reference.

Next

  • Errors — decode error.code; retry only transient codes.
  • Pagination · Rate limits.
  • Build a client — OAuth (PKCE) login, plus WebSocket control and WebRTC (WHIP/WHEP) media for a full producing app on iOS.