Configuration
Initialize the SDK with your credentials: your company name, a unique user ID, and either your API key or a short-lived session minted by your backend. Regional deployments and warm-up are covered below.
1import KinesteXAIKit
2
3@State var showKinesteX = false // Controls KinesteX SDK visibility
4@State var isLoading = false // Optional: Controls custom loading screen
5
6// Initialize with your API key, company name, and unique user ID
7let kinestex = KinesteXAIKit(
8 apiKey: "YOUR_API_KEY",
9 companyName: "YOUR_COMPANY",
10 userId: "unique-user-id"
11)
12
13// Optional: UserDetails to customize workout intensity
14let user = UserDetails(
15 age: 20,
16 height: 170,
17 weight: 70,
18 gender: .Male,
19 lifestyle: .Active
20)Session auth (API key stays on your server)
Instead of shipping your API key inside the app, your backend mints a short-lived session with it (POST https://data.kinestex.com/api/sessions, see Session Auth & Managed Subscriptions) and the app launches KinesteX with the session id. Leave the API key out and pass session instead. When both are sent, the session wins. userId and company are still required.
| Platform | How to pass the session |
| Swift | Create KinesteXAIKit without apiKey and add "session" to customParams on every view |
| Kotlin | KinesteXSDK.initialize without apiKey (2.2.0+) and "session" in customParams |
| Flutter | KinesteXAIFramework.initialize without apiKey (1.5.0+) and 'session' in customParams |
| React Native | data.session instead of data.key (1.5.0+). customParameters.session works too |
| React TS | Not supported. kinestex-sdk-react-ts 0.0.3 requires key and renders nothing without it. Use the API key, or the HTML/JS iframe with session |
| HTML/JS | session instead of key in postData |
The SDK Content API helpers (Swift fetchContent, Kotlin KinesteXSDK.api, Flutter apiService) still need an API key. With session auth, call the Content API from your backend instead.
1// No apiKey: the session your backend minted authenticates the launch
2let kinestex = KinesteXAIKit(
3 companyName: "YOUR_COMPANY",
4 userId: "unique-user-id"
5)
6
7kinestex.createTrainerChatView(
8 user: nil,
9 style: nil,
10 isLoading: $isLoading,
11 customParams: ["session": sessionId],
12 onMessageReceived: handleMessage
13)Regional deployments
If KinesteX runs your company in a regional deployment, point the SDK at the host your KinesteX contact gives you (the examples use https://ksa-ai.kinestex.com). The default host is https://ai.kinestex.com.
| Platform | Setting |
| Swift | KinesteXAIKit(baseURL:). It moves the views only: the Content API helpers and the admin editor stay on admin.kinestex.com |
| Kotlin | KinesteXSDK.initialize(baseUrl = ..., apiBaseUrl = ...) (2.5.0+). apiBaseUrl moves the Content API (KinesteXSDK.api) and the admin editor. Both must be https URLs, otherwise initialize throws IllegalArgumentException |
| Flutter | Not supported. kinestex_sdk_flutter 1.5.1 always loads ai.kinestex.com |
| React Native | baseUrl prop on KinestexSDK (and KinestexWarmup). Messages from other hosts are ignored |
| React TS | baseUrl prop on KinesteXSDK |
| HTML/JS | Load the iframe from the regional host and use that origin for postMessage and your event.origin check |
1let kinestex = KinesteXAIKit(
2 baseURL: URL(string: "https://ksa-ai.kinestex.com"),
3 apiKey: "YOUR_API_KEY",
4 companyName: "YOUR_COMPANY",
5 userId: "unique-user-id"
6)Warm-up
Warming up loads the KinesteX app, your theme and the pose model before the user opens a view, so the first view starts faster.
- Kotlin and Flutter: automatic.
initializeloads the/warmuppage in a hidden WebView, so call it once, early (Application class,main()).KinesteXSDK.dispose()/KinesteXAIFramework.dispose()release it. - React Native (1.4.0+): render
<KinestexWarmup data={postData} />(for example after login) and unmount it before you show KinesteX, or renderKinestexSDKwithvisible={false}and setvisibletotruewhen the user opens it.onWarmupStateChangereports"loading","ready"or"failed". - Swift, React TS, HTML/JS: no built-in warm-up.
Step 2: Register Application Class
Register your custom Application class in AndroidManifest.xml:
AndroidManifest.xml
<application
android:name=".MyApplication"
...>
</application>Step 3: Request Camera Permission
Before a user starts a workout, request camera permission at the app level. Your activity or fragment must implement the PermissionHandler interface:
MainActivity with PermissionHandler
class MainActivity : AppCompatActivity(), PermissionHandler {
// Initialize the webview
private var kinesteXWebView: GenericWebView? = null
// Optional: Pass user details to adjust exercises and estimate calories
// Note: User details are only used on the device for customization during the session
private var userDetails = UserDetails(
age = 20,
height = 170,
weight = 180,
gender = Gender.MALE,
lifestyle = Lifestyle.ACTIVE
)
// Register permission launcher
private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
// Pass permission result to KinesteX webview
kinesteXWebView?.handlePermissionResult(isGranted)
}
// Override to display system dialog for camera access
override fun requestCameraPermission() {
requestPermissionLauncher.launch(Manifest.permission.CAMERA)
}
}Step 4: Handle SDK Messages
Implement a callback function to handle messages from the SDK:
Message Handler
private fun handleWebViewMessage(message: WebViewMessage) {
when (message) {
is WebViewMessage.ExitKinestex -> {
// Dismiss KinesteX view when user clicks exit button
}
// Handle other messages
else -> {
Log.d("KinesteX", message.toString())
}
}
}Step 2: Request Camera Permission
Request camera permission before launching KinesteX. Ensure you've added the necessary permissions in AndroidManifest.xml and Info.plist. Add the following to your iOS Podfile:
2.1: ios/Podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.camera
'PERMISSION_CAMERA=1',
]
end
end
end2.2: Request Permission in Dart
void _checkCameraPermission() async {
if (await Permission.camera.request() != PermissionStatus.granted) {
_showCameraAccessDeniedAlert();
}
}
void _showCameraAccessDeniedAlert() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Camera Permission Denied"),
content: const Text("Camera access is required for this app to function properly."),
actions: <Widget>[
TextButton(
child: const Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}Step 3: Initialize on App Launch
Initialize KinesteX in your main function for WebView warmup:
main.dart
Future<void> main() async {
await KinesteXAIFramework.initialize(
apiKey: YOUR_API_KEY,
companyName: YOUR_COMPANY_NAME,
userId: YOUR_USER_ID,
);
runApp(
const MaterialApp(
home: MyHomePage(),
),
);
}Step 4: Deinitialize on App Closure
Call dispose when closing the app:
Dispose Method
@override
void dispose() {
KinesteXAIFramework.dispose();
super.dispose();
}Step 5: Setup Recommendations
Use a ValueNotifier to manage KinesteX presentation and handle callback messages:
State Management & Message Handler
import 'package:kinestex_sdk_flutter/kinestex_sdk.dart';
// Add a ValueNotifier to manage presentation
ValueNotifier<bool> showKinesteX = ValueNotifier<bool>(false);
// Handle callback messages from KinesteX
void handleWebViewMessage(WebViewMessage message) {
if (message is ExitKinestex) {
setState(() {
showKinesteX.value = false;
});
} else {
print("Message received: ${message.data}");
}
}