Skip to content

Core Concepts

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

Architecture Overview

How It Works

StepComponentAction
1Your BackendCall API with ls-api-key to create livestream
2Lunar StreamReturns streamKey, pushToken, rtmpUrl, hlsSources
3BroadcasterConnects to RTMP URL with pushToken
4Lunar StreamProcesses and delivers to CDN network
5Viewer AppPlays HLS stream from CDN URLs

Integration Flow

Integration Steps:

PhaseYour ActionLunar Stream Response
SetupCall POST /livestream with API KeyReturns streamKey, pushToken, rtmpUrl
BroadcastSend RTMP URL to broadcaster appAccepts connection, processes stream
PlaybackSend HLS URLs to viewer appDelivers video via global CDN

Stream Lifecycle

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 Flow

Authentication Tokens

API Key

Your server-to-server authentication credential:

  • Purpose: Authenticate API requests from your backend
  • Lifetime: Never expires (until regenerated)
  • Header: ls-api-key: <your_api_key>
  • Scope: All operations within your project
bash
curl -X GET "https://api.xxxxxx.xxx/api/v1/livestream" \
  -H "ls-api-key: ls_proj_v1_aBcDeFgHiJkLmNoPqRsTuVwXyZ..."

Security

Keep your API Key secret. Never expose it in client-side code or public repositories.

Push Token

One-time use token for RTMP stream authentication:

  • Purpose: Authorize broadcaster to push RTMP stream
  • Lifetime: Default 1 hour (configurable via expiresIn parameter)
  • Format: JWT token
  • Usage: Appended to stream key as query parameter
rtmp://ingest.lunarstream.kozow.com/live/streamKey?pushToken=eyJhbGciOiJSUzI1NiIs...

Token Refresh

Generate a new push token before the current one expires to ensure uninterrupted streaming.

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) through our global CDN network:

URL Structure

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

Multi-CDN URLs

Each stream has multiple CDN endpoints for redundancy and optimal performance:

CDNURL PatternCoverage
Primaryhttps://stream.lunarstream.kozow.com/live/{streamKey}/hls.m3u8Global
BunnyCDNhttps://zlmediakit-cdn.b-cdn.net/live/{streamKey}/hls.m3u8Global
Gcorehttps://gcore-zlmediakit.lunarstream.kozow.com/live/{streamKey}/hls.m3u8Global

Best Practice

Implement CDN failover in your player to automatically switch between CDN endpoints if one becomes unavailable.

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.