LatteStream®

Quick Start

Getting Started

Building Custom SDKs

SDKs & Libraries

JavaScript/TypeScript

Node.js / Bun / Deno

Python

In Development

Go

In Development

PHP

In Development

API Reference

WebSocket API

REST API

Webhooks

Authentication

API Reference

Complete reference for all LatteStream APIs and protocols

This section provides comprehensive documentation for all LatteStream APIs, protocols, and interfaces. Whether you're building with our SDKs or integrating directly with our APIs, you'll find everything you need here.

API Overview

LatteStream provides multiple API surfaces for different use cases:

WebSocket API

The WebSocket API enables real-time communication between clients and the LatteStream service.

Connection Endpoint

wss://ws-{cluster}.lattestream.com/app/{app-key}

Basic Connection Flow

  1. Connect to WebSocket endpoint with app key
  2. Subscribe to channels for receiving events
  3. Bind event handlers to process incoming messages
  4. Authenticate for private/presence channel access

View WebSocket API Documentation →

REST API

The REST API allows server-side applications to trigger events, manage channels, and retrieve information.

Base URL

https://api-{cluster}.lattestream.com

Authentication

All REST API requests require authentication using your Master Key:

Authorization: Bearer {master-key} Content-Type: application/json

Core Endpoints

  • POST /apps/{app-id}/events - Trigger events
  • GET /apps/{app-id}/channels - List channels
  • GET /apps/{app-id}/channels/{channel} - Get channel info
  • GET /apps/{app-id}/channels/{channel}/users - Get presence users

View REST API Documentation →

Webhooks

Webhooks provide server-side notifications for connection events, channel lifecycle, and user presence changes.

Supported Events

  • Connection Events - connection_established, connection_disconnected
  • Channel Events - channel_occupied, channel_vacated
  • Presence Events - member_added, member_removed
  • Client Events - client_event (for presence channels)

Webhook Security

All webhooks are signed with HMAC-SHA256 for authenticity verification.

View Webhooks Documentation →

Authentication

LatteStream uses a multi-layered authentication system to secure your applications.

Authentication Layers

  1. App Keys - Public keys for client connection
  2. Master Keys - Private keys for server operations
  3. Channel Auth - Authorization for private/presence channels
  4. User Auth - Optional user identification and data

Channel Types & Security

  • Public Channels - No authentication required
  • Private Channels - Require server-side authorization
  • Presence Channels - Require authorization + user identification

View Authentication Documentation →

Rate Limits

LatteStream implements rate limiting to ensure fair usage and system stability.

Connection Limits

PlanConcurrent ConnectionsChannels per Connection
Free10010
Pro1,00050
Business10,000100
EnterpriseCustomCustom

API Rate Limits

Endpoint CategoryRate LimitBurst Limit
Event Triggering1,000/min100/sec
Channel Info500/min50/sec
Authentication2,000/min200/sec

Message Size Limits

  • Event Data: 32KB per message
  • Channel Name: 164 characters
  • Event Name: 200 characters
  • Batch Events: 100 events per batch

Regional Clusters

LatteStream operates in multiple regions for optimal performance:

Available Clusters

  • us-east-1 - US East (Virginia) - Default
  • us-west-2 - US West (Oregon)
  • eu-west-1 - Europe (Ireland)
  • ap-southeast-1 - Asia Pacific (Singapore)
  • ap-northeast-1 - Asia Pacific (Tokyo)

Cluster Selection

Choose the cluster closest to your users for best performance:

// Client SDK const lattestream = new LatteStream('your-app-key', { cluster: 'eu-west-1', }); // Server SDK const lattestream = new LatteStreamServer('app-key', 'master-key', { cluster: 'eu-west-1', });

SDKs & Client Libraries

Official SDKs are available for multiple languages and frameworks:

Client-Side SDKs

Server-Side SDKs

Error Codes

WebSocket Error Codes

CodeNameDescription
4001Application does not existInvalid app key
4004Application over quotaConnection limit exceeded
4005Path not foundInvalid WebSocket path
4006Invalid version stringUnsupported protocol version
4007Unsupported protocol versionUse supported version
4008No protocol version suppliedMissing version in connection

HTTP Status Codes

CodeDescriptionCommon Causes
400Bad RequestInvalid JSON, missing parameters
401UnauthorizedInvalid or missing Master Key
403ForbiddenInsufficient permissions
404Not FoundInvalid app ID or channel
413Payload Too LargeMessage exceeds size limit
429Too Many RequestsRate limit exceeded
500Internal Server ErrorService issue

Protocol Specifications

Message Format

All WebSocket messages follow a standardized JSON format:

{ "event": "event_name", "channel": "channel_name", "data": "json_string" }

Connection States

WebSocket connections progress through these states:

  1. connecting - Establishing connection
  2. connected - Successfully connected
  3. disconnected - Connection lost
  4. reconnecting - Attempting to reconnect
  5. failed - Connection failed permanently

Event Types

  • Channel Events - User-defined events on specific channels
  • Connection Events - System events for connection lifecycle
  • Presence Events - User join/leave events for presence channels
  • Client Events - Events triggered by other clients

Quick Reference

Common Patterns

Subscribe to Channel

const channel = lattestream.subscribe('my-channel'); channel.bind('my-event', (data) => console.log(data));

Trigger Event from Server

await lattestream.trigger('my-channel', 'my-event', { message: 'Hello' });

Authenticate Private Channel

app.post('/lattestream/auth', (req, res) => { const auth = lattestream.authenticate( req.body.socket_id, req.body.channel_name ); res.json(auth); });

Environment Variables

# Required LATTESTREAM_APP_KEY=app_1234567890abcdef LATTESTREAM_MASTER_KEY=master_1234567890abcdef # Optional LATTESTREAM_CLUSTER=us-east-1 LATTESTREAM_WEBHOOK_SECRET=webhook_secret_key LATTESTREAM_ENABLE_LOGGING=true

Related Documentation

Support


Need help? Start with our Getting Started guide or explore specific API documentation above.