Skip to content

Core Concepts

Understanding the key concepts of Lunar Stream will help you build better integrations.

Stream Lifecycle

Every livestream goes through a defined lifecycle:

┌─────────────┐     Broadcaster      ┌─────────────┐
│ READY_FOR   │ ──── connects ────▶  │   STARTED   │
│    USE      │                      │             │
└─────────────┘                      └──────┬──────┘
       ▲                                    │
       │                                    │ Broadcaster
       │ Refresh token                      │ disconnects
       │                                    ▼
┌─────────────┐                      ┌─────────────┐
│   TOKEN     │ ◀── Token expires ── │   ENDED     │
│  EXPIRED    │                      │             │
└─────────────┘                      └─────────────┘

Stream States

StateDescription
READY_FOR_USEStream created, waiting for broadcaster to connect
STARTEDBroadcaster is actively streaming
ENDEDBroadcaster disconnected, stream ended
TOKEN_EXPIREDPush token expired, needs refresh

Authentication Tokens

API Key

  • Purpose: Server-to-server authentication
  • Lifetime: Never expires (until regenerated)
  • Header: ls-api-key: <your_api_key>
  • Scope: All operations within a project
bash
curl -X GET "https://api.lunarstream.kozow.com/api/v1/livestream" \
  -H "ls-api-key: ls_proj_v1_aBcDeFgHiJkLmNoPqRsTuVwXyZ..."

Push Token

  • Purpose: RTMP stream authentication
  • Lifetime: Default 1 hour (configurable)
  • Format: JWT (RS256 signed)
  • Usage: Appended to stream key as query parameter
rtmp://server/live/streamKey?pushToken=eyJhbGciOiJSUzI1NiIs...

Push Token Claims:

json
{
  "sub": "livestream-uuid",
  "projectId": "project-uuid",
  "mediaServerId": "media-server-uuid",
  "streamKey": "32-char-hex-string",
  "iat": 1704715200,
  "exp": 1704718800,
  "type": "push_token"
}

JWT Access Token

  • Purpose: User authentication (dashboard, setup)
  • Lifetime: 15 minutes
  • Header: Authorization: Bearer <token>
  • Refresh: Use refresh token to get new access token

Stream Key

A unique identifier for each livestream:

  • Format: 32-character hexadecimal string
  • Example: ee04affe2a669854052102fe762bd715
  • Generated: Automatically when creating a livestream
  • Immutable: Cannot be changed after creation

HLS Delivery

Streams are delivered via HLS (HTTP Live Streaming):

URL Structure

https://{cdn-host}/live/{streamKey}/hls.m3u8

Multi-CDN URLs

Each stream has multiple CDN endpoints for redundancy:

CDNURL Pattern
Originhttps://stream.lunarstream.kozow.com/live/{streamKey}/hls.m3u8
BunnyCDNhttps://zlmediakit-cdn.b-cdn.net/live/{streamKey}/hls.m3u8
Gcorehttps://gcore-zlmediakit.lunarstream.kozow.com/live/{streamKey}/hls.m3u8

Media Servers

Lunar Stream supports multiple media server types:

Server TypeDescription
ZLMediaKITHigh-performance C++ media server
MediaMTXLightweight Go-based media server

Choose based on your requirements:

  • ZLMediaKIT: Better for high-volume, production workloads
  • MediaMTX: Good for development and testing

Projects & Teams

Team

  • Container for projects
  • Has an owner (user who created it)
  • Can have multiple projects

Project

  • Container for livestreams
  • Has a unique API Key
  • Belongs to a team
  • Isolates resources and billing

Next Steps

Released under the MIT License.