SDKs/Swift
phone_iphone Official SDK · iOS · watchOS · macOS · API v2
Coming Soon

WorkoutX Swift SDK

The official Swift package for the WorkoutX API. Build fitness apps for iOS, watchOS, iPadOS, and macOS with native async/await: API v2's 1,900+ exercises as 2,700+ 720p MP4 loops with male and female models, instructions, form tips and anatomical muscle names, plus the AI Workout Generator, supplements, and the Body Scan API. Built on URLSession, no third-party dependencies.

.package(url: "https://github.com/furkanuruk/workoutx-sdk-swift", from: "0.1.0")

📦 Publishing to GitHub shortly — not yet available. Get your key now and you'll be ready the moment it lands.

Quick start

Create one client with your API key and use wx.v2. The SDK sends the key in the X-WorkoutX-Key header, the only place v2 accepts it. The same client also covers the v1 resources and the Body Scan API (user JWT).

import WorkoutX let wx = WorkoutX(apiKey: "wx_your_key_here", scan: .token("eyJ...")) // Body Scan token is optional let page = try await wx.v2.list(["bodyPart": "chest", "limit": 10]) for ex in page.results { print(ex.name, ex.model) // Barbell Bench Press male print(ex.media?.mp4 ?? "no media") // signed 720p MP4 link for AVPlayer }
bolt

Native async/await

Modern concurrency built on URLSession. Strongly-typed ExerciseV2, MediaLinks and V2RankedPage models, and a flexible JSON type for workouts and supplements.

autorenew

Media links, handled

freshMedia(id) reuses the signed links from earlier calls until about 5 minutes before they expire, then fetches new ones. You store exercise ids; the SDK keeps the links valid.

shield

Resilient by default

Automatic retries with backoff on 429 and 5xx, honoring Retry-After. A used-up quota is not retried. Structured WorkoutXError with status, code and tips.

Play the animation with AVPlayer

Every v2 exercise has media.mp4, a 600×720 loop at 30 fps (usually 100–300 KB), and media.poster, a JPEG still frame. Loop the MP4 muted with AVQueuePlayer and AVPlayerLooper. Media links are signed and expire after about 24 hours, so store exercise ids, never media URLs, and call freshMedia(id) when the view appears: it reuses the links the SDK already has and asks the API again only when they're close to expiry.

import SwiftUI import AVKit import WorkoutX struct ExerciseVideo: View { let exerciseId: String @State private var player = AVQueuePlayer() @State private var looper: AVPlayerLooper? // keep a reference, or the loop stops var body: some View { VideoPlayer(player: player) .aspectRatio(600.0 / 720.0, contentMode: .fit) .task { guard let media = try? await wx.v2.freshMedia(exerciseId), let url = URL(string: media.mp4) else { return } looper = AVPlayerLooper(player: player, templateItem: AVPlayerItem(url: url)) player.isMuted = true player.play() } } }

This SwiftUI view needs iOS 15+. For a loop without playback controls, attach the same player to an AVPlayerLayer in UIKit. In lists, show the poster instead of a video. On the Free plan both links are 300×360 watermarked previews (media.watermarked is true).

AsyncImage(url: ex.media.flatMap { URL(string: $0.poster) }) { image in image.resizable().scaledToFit() } placeholder: { Color.gray.opacity(0.2) }

Downloading the files or serving them from your own servers or CDN isn't permitted on any plan. See Media in v2 for formats and limits.

Male and female models, seven languages

Male and female versions are separate exercises. counterpartId points at the same movement with the other model, so you can offer a switch, and model filters a list to one of them. lang returns names, instructions, tips and muscles in Turkish (tr), German (de), Spanish (es), French (fr), Simplified Chinese (zh-SG) or Traditional Chinese (zh-HK). English is the default; filter values stay in English.

let bench = try await wx.v2.get("ex_SAWOOH") // Barbell Bench Press, male model if let otherId = bench.counterpartId { let female = try await wx.v2.get(otherId) // "ex_HYOSAB": the same movement, female model } let womenChest = try await wx.v2.list(["bodyPart": "chest", "model": "female"]) let germanChest = try await wx.v2.list(["bodyPart": "chest", "lang": "de"]) let spanish = try await wx.v2.get("ex_SAWOOH", lang: "es")

Smart endpoints

All plans

Similar exercises, alternatives with other equipment and calorie estimates, on v2 ids. Ranked results are full v2 exercises with media links plus a score (read exercise fields directly, e.g. r.name), and never include the exercise itself or its other-model clip. All three take lang.

let similar = try await wx.v2.similar("ex_SAWOOH", model: "any", limit: 5) let swaps = try await wx.v2.alternatives("ex_SAWOOH", equipment: "dumbbell", limit: 3) let burn = try await wx.v2.calories("ex_SAWOOH", weightKg: 80, minutes: 20) for r in swaps.results { print(r.name, r.score) } // Dumbbell Bench Press 150.0 print(burn.totalKcal) // 139.4

Workouts and programs

Growth · Scale

v2.workout.generate() returns one session from the rule-based workout engine as the flexible JSON type: a warm-up, exercises grouped into blocks (straight sets, supersets such as C1/C2, or one circuit) with sets, reps or a duration, rest, effort (rir) and swap alternatives, then a cool-down. Every exercise in it, warm-up and cool-down items included, is a full v2 exercise with media links, and model picks the male or female clips. avoidJoints (knee, shoulder, lumbar_spine, elbow, wrist, hip, ankle) leaves out movements that load those joints heavily; it is general guidance, not medical advice. format picks straight, superset or circuit (default auto). The response also carries estimatedDurationMinutes and the seed it used. v2.workout.program() returns a schedule, the week-by-week program and an exerciseLibrary that its exercises reference by exerciseId. The generator needs Growth or Scale (legacy Pro, Ultra); multi-week programs need Scale (legacy Ultra).

let workout = try await wx.v2.workout.generate([ "goal": "muscle_gain", // strength, fat_loss, endurance, mobility, general_fitness "duration": 45, // minutes, 15-120 "level": "intermediate", "equipment": ["dumbbell", "bench"], // sent comma-separated; or "home", "bodyweight", "gym" "avoidJoints": ["knee"], // general guidance, not medical advice "format": "auto", // straight, superset, circuit "model": "female", ]) for item in workout["warmup"]?["items"]?.arrayValue ?? [] { print("Warm-up:", item["exercise"]?["name"]?.stringValue ?? "", item["durationSeconds"]?.intValue ?? 0) } for item in workout["exercises"]?.arrayValue ?? [] { // block "C1" + "C2" = a superset let exercise = item["exercise"] let amount = item["reps"]?.stringValue ?? "\(item["durationSeconds"]?.intValue ?? 0)s" print(item["block"]?.stringValue ?? "", exercise?["name"]?.stringValue ?? "", item["sets"]?.intValue ?? 0, amount, exercise?["media"]?["mp4"]?.stringValue ?? "") } let program = try await wx.v2.workout.program(["goal": "strength", "weeks": 8, "daysPerWeek": 4]) // Scale var library: [String: JSON] = [:] for e in program["exerciseLibrary"]?.arrayValue ?? [] { library[e["id"]?.stringValue ?? ""] = e } let dayOne = program["program"]?[0]?["days"]?[0]?["exercises"]?.arrayValue ?? [] // week 1, day 1 for x in dayOne { let mp4 = library[x["exerciseId"]?.stringValue ?? ""]?["media"]?["mp4"]?.stringValue print(x["name"]?.stringValue ?? "", x["sets"]?.intValue ?? 0, mp4 ?? "") }

Supplements

Growth · Scale

The evidence-graded supplement database in the v2 page shape, { total, limit, offset, results, disclaimer }, as JSON. Growth and Scale (legacy Pro, Ultra); stacks need Scale (legacy Ultra). Informational content only, not medical advice. Supplement text is English.

let strong = try await wx.v2.supplements.list(["goal": "muscle_gain", "evidence": "strong"]) let filters = try await wx.v2.supplements.filters() let creatine = try await wx.v2.supplements.get("creatine-monohydrate") let forBench = try await wx.v2.supplements.forExercise("ex_SAWOOH", limit: 5) let stack = try await wx.v2.supplements.stack(["goal": "muscle_gain", "level": "essential"]) // Scale

Joint & Rehab filters

Growth · Scale

Narrow v2.list() by the joint a movement works through, an intensity band and descriptive tags, for physical therapy, mobility and senior-fitness apps. Growth and Scale (legacy Ultra). These are descriptive fields, not medical recommendations.

let gentleKnee = try await wx.v2.list([ "jointFocus": "knee", // shoulder, lumbar_spine, … "intensityLevel": "gentle", // gentle, moderate, vigorous "movementTag": "joint-friendly", // beginner-friendly, low-intensity, minimal-equipment, … "limit": 10, ])

Migrating from v1

v1 keeps working on the same key, and you'll get at least 30 days' notice before it's retired. The SDK's v1 resources (exercises, gifs, workout, supplements) are unchanged, so you can move one screen at a time. Map each v1 id you've stored once with v2.legacy() and save the v2 id: 1,324 of the 1,327 v1 exercises have a v2 match.

let lookup = try await wx.v2.legacy("0025") // match "exact": ex_SAWOOH, Barbell Bench Press switch lookup.match { case "exact", "equivalent": if let ex = lookup.exercise { saveExerciseId("0025", ex.id) } // the same movement: replace automatically case "alternative", "closest": if let ex = lookup.exercise { suggestToUser("0025", ex) } // a substitute: let the user confirm default: break // "none": keep the v1 exercise for now } let v1 = try await wx.exercises.get("0025") // v1 calls keep working meanwhile

Step by step, with code for each platform: the v2 migration guide.

Errors and plan limits

Every non-2xx response throws a WorkoutXError with status, code, message, tip and the raw body. A feature your plan doesn't include answers 403 and names the plan that has it. A 429 is either a rate limit, which the SDK retries with backoff, or a used-up request quota, which it doesn't retry. The Free plan's 500 requests are a one-time allowance.

do { _ = try await wx.v2.workout.generate(["goal": "strength"]) } catch let e as WorkoutXError where e.status == 403 { // { "error": "Plan Upgrade Required", "feature": "workoutGenerator", "requiredPlan": "growth" } let body = e.body.flatMap { try? JSONDecoder().decode(JSON.self, from: $0) } print("Upgrade to", body?["requiredPlan"]?.stringValue ?? "a higher plan") } catch let e as WorkoutXError where e.isRateLimited { print(e.code ?? "", e.message) // "Monthly Quota Exceeded", "You have used 500/500 requests…" }

Frequently asked questions

How do I install the WorkoutX Swift SDK?

Add the Swift Package https://github.com/furkanuruk/workoutx-sdk-swift in Xcode (File ▸ Add Package Dependencies) or to your Package.swift dependencies, then add the WorkoutX product to your target. API v2 lives under wx.v2.

Which platforms are supported?

iOS 13+, macOS 10.15+, watchOS 6+, and tvOS 13+. It uses native async/await and URLSession, with no third-party dependencies. The SwiftUI player example on this page needs iOS 15+.

How do I play an exercise animation in SwiftUI?

Get links with wx.v2.freshMedia(id), then loop media.mp4 muted with AVQueuePlayer and AVPlayerLooper in a VideoPlayer or an AVPlayerLayer. Use AsyncImage with media.poster in lists.

Can I store the media URLs?

No. Media links are signed and expire after about 24 hours. Store exercise ids and call freshMedia(id) when you show an exercise; it reuses links until they're close to expiry. Downloading or self-hosting the files isn't allowed on any plan.

Do my v1 calls keep working?

Yes. wx.exercises, wx.gifs, wx.workout and wx.supplements still call v1, which keeps working; you'll get at least 30 days' notice before it's retired. wx.v2.legacy(v1Id) maps the v1 ids you've stored to v2.

How does authentication work for the Body Scan API?

Body Scan uses a logged-in user's JWT. Pass scan: .token("..."), or scan: .credentials(email:password:) to let the SDK log in automatically.

Security & API keys

vpn_key

Keys are visible in apps

Anything bundled in an iOS app can be extracted. For production, route requests through your own backend, or ship a separate key for the app that you can rotate from the dashboard rather than your main key. v2 accepts the key only in the X-WorkoutX-Key header, which the SDK sets for you.

movie

Media links carry no key

media.mp4 and media.poster are signed links that expire after about 24 hours. They contain no API key, so AVPlayer and AsyncImage can load them directly. Store exercise ids, not links. (v1's gifURL() still puts the key in the URL.)

lock

Use tokens, not credentials

For Body Scan, fetch a short-lived JWT from your backend and pass scan: .token(...). Avoid shipping the email/password login flow inside the app.

Start building for iOS

Start free with 500 requests and watermarked previews. 1,900+ exercises as 720p video, workouts, and Body Scan in one Swift package.

Get your free API key