Skip to main content

Endpoint

Authentication

Apps authenticate using a JWT token in the Authorization header, along with session information in custom headers.

Headers

JWT Token Structure

The appJwt must contain:
  • packageName: The app’s package identifier
  • apiKey: The app’s API key

Connection Flow

1

Webhook Notification

App receives webhook when user starts the app
2

WebSocket Connection

App connects to WebSocket with JWT and session headers
3

Authentication

Server validates JWT token and verifies API key
4

Session Binding

App is bound to the user’s active session
5

Connection Init

App sends CONNECTION_INIT to complete handshake

Message Types

App → Cloud Messages

All message types are defined in packages/sdk/src/types/messages/app-to-cloud.ts:

CONNECTION_INIT

SUBSCRIPTION_UPDATE

DISPLAY_REQUEST

PHOTO_REQUEST

AUDIO_PLAY_REQUEST

Cloud → App Messages

All message types are defined in packages/sdk/src/types/messages/cloud-to-app.ts:

CONNECTION_ACK

DATA_STREAM

SETTINGS_UPDATE

APP_STOPPED

Subscription System

Apps must subscribe to the data streams they want to receive. Available stream types are defined in packages/sdk/src/types/streams.ts:

Hardware Streams

  • button_press - Button press events
  • head_position - Head position changes
  • location_update - GPS location updates
  • vps_coordinates - Visual positioning system

Audio Streams

  • transcription - Speech-to-text results
  • translation - Real-time translation
  • VAD - Voice activity detection
  • audio_chunk - Raw audio data

Phone Streams

  • phone_notification - Incoming notifications
  • phone_notification_dismissed - Dismissal events
  • calendar_event - Calendar updates

System Streams

  • start_app - App start requests
  • stop_app - App stop requests
  • core_status_update - System status

Media Streams

  • photo_taken - Photo capture events
  • rtmp_stream_status - RTMP streaming status
  • managed_stream_status - Managed streaming

Error Handling

Authentication Errors

Subscription Errors

Heartbeat

Apps must send heartbeat messages to maintain their connection:
If no heartbeat is received for 20 seconds, the app enters a grace period before being disconnected.

Implementation Details

  • Service: AppWebSocketService (packages/cloud/src/services/websocket/websocket-app.service.ts)
  • Manager: AppManager handles app lifecycle and state
  • Authentication: API key validation against app database
  • Subscriptions: SubscriptionService manages data stream routing

SDK Usage

The MentraOS SDK handles all WebSocket communication automatically: