Skip to Content
Getting startedInitialization

Initialization

Before starting the video measurement, you’ll need to initialize the SDK.

Under the hood that step verifies the license and prepares the selected input pipeline. This also connects to a platform camera device, so the app must have camera permissions before this step.

You’ll need to provide an API key - see Authorization for more information.

Security tip: In production applications, short-lived tokens should be issued from a backend instead of embedding permanent API keys in client-side code. This reduces exposure of long-lived credentials while preserving standard SDK initialization flows for web and mobile applications.

lib/main.dart
import 'package:shenai_sdk/shenai_sdk.dart'; var API_KEY = "" var USER_ID = "" final _initResult = await ShenaiSdk.initialize(API_KEY, USER_ID);

Error handling

You should check if the initialization was successful before proceeding further.

Possible errors at this stage include:

  • INVALID_API_KEY - the provided API key is malformed or inactive
  • CONNECTION_ERROR - there is a problem with network connection to the licensing server
  • INTERNAL_ERROR - other errors such as missing camera permissions
enum InitializationResult { success, failInvalidApiKey, failConnectionError, failInternalError } if (_initResult != InitializationResult.success) { // handle error }

If the SDK has been successfully initialized, repeated calls to initialize will immediately return success - to start a new session first deinitialize the SDK.

Custom initialization options

Shen.AI (CE) uses the standard initialization flow and supports SDK events.

Supported Shen.AI (CE) initialization settings

Shen.AI (CE) accepts the standard API key/user ID inputs and keeps the standard event-callback integration. During the preview phase, use the same API key as for the standard SDK. It also accepts language where the platform exposes it during initialization, limited to en, de, es, fr, and pl. Unsupported language values are normalized to en.

The only supported initialization flow is:

  • MEASUREMENT: standard measurement without calibration data.

Calibration-related enum values remain present for cross-product wrapper compatibility, but Shen.AI (CE) normalizes them to MEASUREMENT.

SDK events

SDK events notify your app about important changes in the SDK flow. They are most useful when your app state, navigation, or analytics need to stay aligned with the embedded SDK flow.

Available events:

  • START_BUTTON_CLICKED: the user clicked START in the SDK UI.
  • STOP_BUTTON_CLICKED: the user clicked STOP in the SDK UI.
  • MEASUREMENT_FINISHED: a measurement completed and results are ready to read.
  • USER_FLOW_FINISHED: the user completed the current SDK flow.
  • SCREEN_CHANGED: the SDK changed the currently displayed screen.

Platform access differs by SDK:

  • Web, Android, and iOS expose eventCallback in initialization settings.
  • Flutter uses ShenaiSdk.setEventCallback(...).
  • React Native emits the native ShenAIEvent event.
  • Capacitor emits the ShenAIEvent plugin event.
  • MAUI exposes ShenaiSdk.Events.

Use these events for app state, navigation, analytics, and host-app updates. Keep event handlers lightweight and read detailed measurement data through the regular result APIs.

Providing the user interface

You’ll need to embed the SDK’s UI in your app. The SDK uses OpenGL/WebGL for rendering, embedded in a platform-specific native view component.

You can use the ShenaiView widget to embed the SDK’s UI in your Flutter app.

lib/main.dart
import 'package:shenai_sdk/shenai_view.dart'; ... @override Widget build(BuildContext context) { return Center( child: ShenaiView(), ); }

Deinitialization

After finishing using the SDK you should deinitialize it - that will free up any allocated resources and disconnect from the camera.

ShenaiSdk.deinitialize();