> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-docs.mentra.glass/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

> MentraOS Cloud API endpoints and WebSocket connections

## Overview

MentraOS Cloud provides both WebSocket and REST APIs:

<CardGroup cols={2}>
  <Card title="WebSocket APIs" icon="plug">
    Real-time bidirectional communication for glasses and apps
  </Card>

  <Card title="REST APIs" icon="server">
    HTTP endpoints for authentication, management, and configuration
  </Card>
</CardGroup>

## Base URLs

<CodeGroup>
  ```bash Production theme={null}
  https://api.mentra.glass  # REST API
  wss://api.mentra.glass  # WebSocket
  ```

  ```bash Development theme={null}
  https://devapi.mentra.glass  # REST API
  wss://devapi.mentra.glass  # WebSocket
  ```

  ```bash local development theme={null}
  ws://localhost:8002   # WebSocket
  http://localhost:8002 # REST API
  ```
</CodeGroup>

## Authentication

### WebSocket Authentication

WebSocket connections authenticate using JWT tokens in the Authorization header:

```typescript theme={null}
const ws = new WebSocket('wss://cloud.mentraos.com/glasses-ws', {
  headers: {
    'Authorization': `Bearer ${jwtToken}`
  }
});
```

### REST API Authentication

REST endpoints use Bearer token authentication:

```bash theme={null}
curl -X GET https://api.mentraos.com/user/profile \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
```

## Rate Limits

<Note>
  API rate limits apply per user:

  * REST API: 100 requests per minute
  * WebSocket messages: 50 per second
  * Display updates: 1 per 200ms
</Note>

## Response Format

All REST API responses follow this format:

```json theme={null}
{
  "success": true,
  "data": {
    // Response data
  },
  "error": null
}
```

Error responses:

```json theme={null}
{
  "success": false,
  "data": null,
  "error": {
    "code": "INVALID_TOKEN",
    "message": "Authentication token is invalid"
  }
}
```

## WebSocket Message Format

All WebSocket messages are JSON with a `type` field:

```json theme={null}
{
  "type": "MESSAGE_TYPE",
  "data": {
    // Message-specific data
  }
}
```

## Available Endpoints

### WebSocket Endpoints

<CardGroup cols={2}>
  <Card title="Glasses Connection" icon="glasses" href="/api-reference/websocket/glasses-connection">
    `/glasses-ws` - Mobile app connections
  </Card>

  <Card title="App Connection" icon="plug" href="/api-reference/websocket/app-connection">
    `/app-ws` - Third-party app connections
  </Card>
</CardGroup>

### REST Endpoints

<CardGroup cols={2}>
  <Card title="Authentication" icon="key" href="/api-reference/rest/authentication">
    Login, token refresh, logout
  </Card>

  <Card title="User Management" icon="user" href="/api-reference/rest/user-management">
    Profile, settings, preferences
  </Card>

  <Card title="App Management" icon="cube" href="/api-reference/rest/app-management">
    Install, uninstall, configure apps
  </Card>
</CardGroup>

## SDK Integration

The MentraOS SDK handles all API communication for you:

```typescript theme={null}
import { AppServer } from '@mentraos/sdk';

// SDK manages all API calls internally
const server = new AppServer({
  packageName: 'com.example.app',
  apiKey: process.env.MENTRAOS_API_KEY
});
```

## Need Help?

* Check the [SDK documentation](/sdk/getting-started)
* Join our [Discord community](https://discord.gg/5ukNvkEAqT)
* View [example implementations](https://github.com/Mentra-Community/MentraOS/tree/main/examples)
