carlos / platform Public

docs: live streams on your own LiveKit Cloud project

Adds a docs page on running a live stream with chat on an app's own
LiveKit Cloud project: viewer and streamer tokens, an Egress recording
into the app's store, the egress_ended webhook, and media conversion for
playback, plus what the platform needs from the app. Adds the page to
the docs nav under media conversion, with the Luna copy brief whose pass
was applied. Docs only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from docs-live-byo-livekit into main.
claude agent, operated by paul@keymail.dev edaed8360ab2dd9e093f78b1558029ebecc40beb parent 65951fb
3 files changed, +273 −0
  • docs/site/live-streams-bring-your-own-livekit.md +235 −0
  • docs/site/nav.json +5 −0
  • docs/superpowers/notes/LUNA-DOCS-BRIEF-live-byo-livekit.md +33 −0

CI cancelled โ€” superseded by a newer push — run details

CI log
=== gate ===
go: downloading go1.26.10 (linux/arm64)
go version go1.26.10 linux/arm64
opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1
  tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz
  tofu: downloaded, digest verified
  aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip
  aws: downloaded, digest verified
  archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip
  archive: downloaded, digest verified
  installed in /tmp/carlos-opentofu-QufOu9
.amadan/test-gate.sh
go: downloading github.com/aws/aws-sdk-go-v2 v1.44.0
go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0
go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5
go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0
go: downloading github.com/aws/smithy-go v1.28.1
go: downloading github.com/benbjohnson/litestream v0.5.14
go: downloading github.com/superfly/ltx v0.5.1
go: downloading golang.org/x/net v0.62.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sns v1.43.0
go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0
go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2
go: downloading github.com/aws/aws-sdk-go-v2/service/route53 v1.64.1
go: downloading github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.37.0
go: downloading golang.org/x/sys v0.49.0
go: downloading golang.org/x/crypto v0.58.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sesv2 v1.66.6
go: downloading github.com/pion/logging v0.2.4
go: downloading github.com/pion/stun/v3 v3.1.5
go: downloading github.com/pion/turn/v4 v4.1.4
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.40
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.40
go: downloading github.com/klauspost/compress v1.20.2
go: downloading golang.org/x/text v0.43.0
go: downloading golang.org/x/sync v0.24.0
go: downloading github.com/prometheus/client_golang v1.17.0
go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18
go: downloading github.com/lmittmann/tint v1.1.3
go: downloading github.com/pion/transport/v4 v4.0.2
go: downloading github.com/pion/randutil v0.1.0
go: downloading github.com/pion/dtls/v3 v3.1.4
go: downloading github.com/prometheus/client_model v0.5.0
go: downloading github.com/prometheus/procfs v0.12.0
go: downloading google.golang.org/protobuf v1.36.10
go: downloading github.com/cespare/xxhash/v2 v2.3.0
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/prometheus/common v0.45.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/libc v1.74.1
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading github.com/google/uuid v1.6.0
go: downloading modernc.org/memory v1.11.0
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading github.com/google/uuid v1.6.0
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec

amadan: job cancelled โ€” a newer push superseded it
diff --git a/docs/site/live-streams-bring-your-own-livekit.md b/docs/site/live-streams-bring-your-own-livekit.md
new file mode 100644
index 000000000..943c1350e
--- /dev/null
+++ b/docs/site/live-streams-bring-your-own-livekit.md
@@ -0,0 +1,235 @@
+# Live streams with your own LiveKit
+
+Your app can run a live stream with chat on your own [LiveKit Cloud](https://livekit.io) project. One person streams, viewers watch and chat, and LiveKit records the stream into your app's own store. Then your app converts the recording with [media conversion](/docs/media-conversion) and plays it back like any other upload.
+
+The platform does not run LiveKit for you here. Your app holds its own LiveKit key, talks to LiveKit Cloud directly, and LiveKit bills your own LiveKit account.
+
+## Before you start
+
+You need:
+
+- A LiveKit Cloud project. Its settings page gives you the project URL, such as `wss://shop-a1b2c3.livekit.cloud`, and an API key and secret.
+- An object store for the app, made with `carlos store create --app shop`, on a deployment with media conversion turned on. The store must pass the check on the media conversion page. A store made with `carlos store create` and left alone passes.
+- A Service credential for media conversion, as in [the media conversion example](/docs/media-conversion#an-example).
+
+What the platform needs from your app:
+
+- **No egress setting.** Instances can already reach public addresses, and LiveKit Cloud's API and project hosts are public. `carlos apps set --egress-allow` is only for private addresses, and it takes IP addresses, not hostnames.
+- **A public route for LiveKit's webhook.** LiveKit calls your app when a recording is done. Any path on your app's own hostname works, such as `https://shop.example.com/livekit/webhook`. A host behind [carlos gate](/docs/cli#carlos-gate) can't receive it, because the gate asks every request for the password.
+- **The store's region in every recording request.** If you leave both the region and endpoint out, LiveKit asks S3 for the bucket's location, and the store's credential isn't allowed to ask.
+- **No tags on recordings.** LiveKit can tag the files it uploads. Leave that empty: the store's credential can't tag objects, so S3 refuses the upload.
+
+## How it fits together
+
+```text
+# once
+carlos env set --app shop LIVEKIT_URL=wss://shop-a1b2c3.livekit.cloud
+carlos secrets set --app shop LIVEKIT_API_KEY=APIa1b2c3d4
+carlos secrets set --app shop LIVEKIT_API_SECRET - < livekit-secret.txt
+add https://shop.example.com/livekit/webhook as a webhook in the LiveKit project
+
+# per stream, on the app's server
+1. mint a token for the streamer and one for each viewer -> the browsers join the room
+2. start an Egress to the app's store -> LiveKit records the room
+3. LiveKit POSTs egress_ended to /livekit/webhook -> the recording's key
+4. POST the key to media conversion, poll until done -> the files to play
+```
+
+The API key and secret are secrets, so they go in with `carlos secrets set`. The `-` reads the secret from the file, so it never appears on your command line. The project URL isn't secret. Your browser code needs it too.
+
+The examples below are in Go, with LiveKit's server SDK (`github.com/livekit/server-sdk-go/v2`) and its protocol package (`github.com/livekit/protocol`). LiveKit's other server SDKs have the same calls.
+
+## Tokens for the streamer and the viewers
+
+A browser joins a LiveKit room with a token your server signs. Every token names the room, a participant identity and what that participant may do. Use your own user ID as the identity, so each person appears once.
+
+```go
+import (
+ "os"
+ "time"
+
+ "github.com/livekit/protocol/auth"
+)
+
+// joinToken lets one person into a stream's room. The streamer may publish
+// a camera and microphone; viewers only watch. Everyone may chat.
+func joinToken(room, identity, name string, streamer bool) (string, error) {
+ grant := &auth.VideoGrant{RoomJoin: true, Room: room}
+ grant.SetCanSubscribe(true)
+ grant.SetCanPublish(streamer)
+ grant.SetCanPublishData(true)
+ return auth.NewAccessToken(os.Getenv("LIVEKIT_API_KEY"), os.Getenv("LIVEKIT_API_SECRET")).
+ SetVideoGrant(grant).
+ SetIdentity(identity).
+ SetName(name).
+ SetValidFor(10 * time.Minute).
+ ToJWT()
+}
+```
+
+Set the chat permission even for viewers. If you leave it out, LiveKit gives each participant the same chat permission as their publish permission, so viewers couldn't chat.
+
+Your server decides who is the streamer. Mint a streamer token only for the person who owns the stream, and viewer tokens for everyone else allowed to watch. The token only has to be valid when the browser connects. LiveKit keeps a connected browser's session going after that.
+
+## Chat
+
+Chat travels as LiveKit data messages inside the room. In the browser, the LiveKit client sends reliable data messages and receives them through the `RoomEvent.DataReceived` event. Send each message as a small JSON object, such as `{"text": "hello"}`. One reliable message can carry up to 15 KiB.
+
+LiveKit doesn't store data messages. A viewer who joins late sees only the messages sent after they joined. If you want chat history or a record for moderation, have the browser also send each message to your server, and keep it there.
+
+To stop someone chatting, your server calls `UpdateParticipant` on LiveKit's room service with `CanPublishData` set to false. To remove them from the stream, it calls `RemoveParticipant`. Both are on `lksdk.NewRoomServiceClient`.
+
+## Recording into your store
+
+Your server starts an Egress, LiveKit's recorder, and points it at the app's store with the store's own credentials. The platform delivers them to every instance as `CARLOS_STORE_BUCKET`, `CARLOS_STORE_REGION`, `CARLOS_STORE_ACCESS_KEY` and `CARLOS_STORE_SECRET_KEY`.
+
+A room composite Egress records the room as one MP4, laid out the way a viewer sees it:
+
+```go
+import (
+ "context"
+ "os"
+
+ "github.com/livekit/protocol/livekit"
+ lksdk "github.com/livekit/server-sdk-go/v2"
+)
+
+func storeUpload() *livekit.S3Upload {
+ return &livekit.S3Upload{
+ AccessKey: os.Getenv("CARLOS_STORE_ACCESS_KEY"),
+ Secret: os.Getenv("CARLOS_STORE_SECRET_KEY"),
+ Region: os.Getenv("CARLOS_STORE_REGION"), // required: see Before you start
+ Bucket: os.Getenv("CARLOS_STORE_BUCKET"),
+ // No Tagging. The store refuses tagged uploads.
+ }
+}
+
+// startRecording records the whole room under recordings/<id>/.
+func startRecording(ctx context.Context, room, id string) (string, error) {
+ egress := lksdk.NewEgressClient(os.Getenv("LIVEKIT_URL"), os.Getenv("LIVEKIT_API_KEY"), os.Getenv("LIVEKIT_API_SECRET"))
+ info, err := egress.StartRoomCompositeEgress(ctx, &livekit.RoomCompositeEgressRequest{
+ RoomName: room,
+ Layout: "speaker",
+ FileOutputs: []*livekit.EncodedFileOutput{{
+ FileType: livekit.EncodedFileType_MP4,
+ Filepath: "recordings/" + id + "/",
+ Output: &livekit.EncodedFileOutput_S3{S3: storeUpload()},
+ }},
+ })
+ if err != nil {
+ return "", err
+ }
+ return info.EgressId, nil
+}
+```
+
+`Filepath` ends in `/`, so LiveKit names the file itself inside that folder, as `<room>-<time>.mp4`. That also keeps a retried recording from overwriting the first try. Don't record under `derived/`: media conversion won't take a source there.
+
+A track Egress records one track as it arrives. Video is not re-encoded. Audio is re-encoded as stereo Opus. LiveKit picks the file type from the track: WebM or MP4 for video, and Ogg for audio. Media conversion reads all three. Use it when you only need the streamer's camera or microphone:
+
+```go
+info, err := egress.StartTrackEgress(ctx, &livekit.TrackEgressRequest{
+ RoomName: room,
+ TrackId: trackID,
+ Output: &livekit.TrackEgressRequest_File{File: &livekit.DirectFileOutput{
+ Filepath: "recordings/" + id + "/",
+ Output: &livekit.DirectFileOutput_S3{S3: storeUpload()},
+ }},
+})
+```
+
+LiveKit uploads the file when the recording stops. It also writes a small JSON manifest beside the file. Set `DisableManifest: true` on the output if you don't want it.
+
+If your app also gets `CARLOS_STORE_ENDPOINT`, use that S3-compatible endpoint as `Endpoint` and set `ForcePathStyle: true`. LiveKit has to be able to reach that endpoint over the internet.
+
+## When the recording is done
+
+LiveKit POSTs events to the webhook URL you set in the LiveKit project, with `Content-Type: application/webhook+json`. Each one carries an `Authorization` token signed with the webhook's configured signing key. Configure the webhook to use the API key above, so the SDK can verify it for you. The one you need is `egress_ended`:
+
+```go
+import (
+ "net/http"
+ "os"
+ "time"
+
+ "github.com/livekit/protocol/auth"
+ "github.com/livekit/protocol/livekit"
+ "github.com/livekit/protocol/webhook"
+)
+
+func livekitWebhook(w http.ResponseWriter, r *http.Request) {
+ keys := auth.NewSimpleKeyProvider(os.Getenv("LIVEKIT_API_KEY"), os.Getenv("LIVEKIT_API_SECRET"))
+ event, err := webhook.ReceiveWebhookEvent(r, keys)
+ if err != nil {
+ http.Error(w, "signature does not verify", http.StatusUnauthorized)
+ return
+ }
+ if event.GetEvent() == webhook.EventEgressEnded {
+ info := event.GetEgressInfo()
+ switch {
+ case info.GetBackupStorageUsed():
+ // The upload to your store failed. See "When an upload fails".
+ case info.GetStatus() == livekit.EgressStatus_EGRESS_COMPLETE,
+ info.GetStatus() == livekit.EgressStatus_EGRESS_LIMIT_REACHED:
+ for _, f := range info.GetFileResults() {
+ queueConversion(f.GetFilename(), time.Duration(f.GetDuration()))
+ }
+ default:
+ // EGRESS_FAILED: info.GetError() says why.
+ }
+ }
+ w.WriteHeader(http.StatusOK)
+}
+```
+
+`Filename` is the recording's key in your store, such as `recordings/a1b2/stream-a1b2-2026-11-25T101500.mp4`. `Duration` is in nanoseconds. `EGRESS_LIMIT_REACHED` means LiveKit stopped a long recording at its time limit, and the file up to that point is still in your store.
+
+LiveKit retries a webhook a few times and may send one more than once. Make the handler safe to run twice. Submitting the same key with the same preset and class to media conversion twice is already safe: the second `POST` returns the first job.
+
+## Converting and playing the recording
+
+Send the recording's key to media conversion, as on the [media conversion page](/docs/media-conversion#starting-a-conversion):
+
+```http
+POST /api/cli/apps/{account}/shop/media/conversions
+Authorization: Bearer <service token>
+{"key": "recordings/a1b2/stream-a1b2-2026-11-25T101500.mp4", "class": "long"}
+```
+
+Ask for `"class": "long"` when the recording is longer than 10 minutes. A short job converts up to 10 minutes and reports `needs_long_class` for anything longer. A video track above 1080p also needs the long class. A long job converts up to 2 hours of video up to 1080p. A room composite recording is 720p at 30 frames a second, with Opus sound, unless you ask for other encoding options. Media conversion reads that MP4.
+
+Poll the job until it is `done`, save the output keys with the stream, and serve them as the page's [Serving](/docs/media-conversion#serving) section describes: the playlist and the MP4 from your app's own origin, side by side.
+
+Conversion counts against your account's [media allowance](/docs/media-conversion#the-allowance) like any other video.
+
+## When an upload fails
+
+If LiveKit can't upload the recording to your store, the recording isn't in your store and there is nothing to convert. Two common causes:
+
+- **The store is full.** A store past its plan's storage allowance refuses new objects, recordings included.
+- **The credential changed while the stream ran.** LiveKit uses the credential it was given when the recording started, and uploads at the end. If you run `carlos store rotate --finish --app shop` during a stream, the old credential stops working and the upload fails. Finish a rotation only when no recording is running.
+
+Without a backup copy, the webhook reports `EGRESS_FAILED`, and its error says the upload failed. With backup storage, it reports `EGRESS_COMPLETE` with `backup_storage_used` set instead.
+
+LiveKit Cloud can keep a copy of a recording whose upload failed in its own backup storage for 7 days. LiveKit turns this on for a project when you ask. When it happens, `manifest_location` in the webhook points to a manifest for retrieving it, and its file URLs are valid for 7 days. The recording is at LiveKit, not in your store.
+
+## Virus scanning
+
+If your store has [virus scanning](/docs/cli#carlos-store-scan), a recording is scanned like any other new object. Most recordings are bigger than the scanner's size limit, 25 MiB unless your operator changed it, so they are counted as skipped, not scanned. Media conversion doesn't wait for a scan. It only refuses an object a scan has found infected while the store enforces scanning.
+
+## Privacy: a third party in the media path
+
+With this setup, LiveKit Cloud carries every stream. The video, the audio and the chat pass through LiveKit's servers, and LiveKit records the stream before it reaches your store. LiveKit also holds your store's credential while a recording runs. That credential can read, overwrite and delete every object in your app's store, not only recordings. It cannot change object tags or bucket settings.
+
+The platform doesn't tell your users any of this. Whether and how to tell them is your app's decision. If you do, say it where people decide to stream or watch: near the start of your app's description, and on anything the stream produces, such as the recording's page.
+
+## Billing
+
+LiveKit bills your own LiveKit account for everything LiveKit does: participant minutes, data sent out of LiveKit to viewers, and Egress recording time. Check LiveKit's pricing page for current prices and free allowances. A room composite recording is billed as transcoding minutes. A track recording is billed at the track-egress rate.
+
+The platform bills your account as usual for the instance, the recording's storage in your store, and the media minutes used for conversion.
+
+## Not yet supported
+
+- **A credential that can only write recordings.** LiveKit needs your store's one credential, which can also read, overwrite and delete every other object in the store. The platform can't yet give an app a narrower credential to hand to a third party.
+- **Converting recordings longer than 2 hours.** LiveKit Cloud limits a room-composite file to 3 hours, and media conversion converts up to 2 hours of video up to 1080p. To keep a longer stream playable, stop the recording and start a new one before it reaches 2 hours. Each part converts on its own.
diff --git a/docs/site/nav.json b/docs/site/nav.json
index ec8ce392c..9da2d31cd 100644
--- a/docs/site/nav.json
+++ b/docs/site/nav.json
@@ -48,6 +48,11 @@
"label": "Media conversion",
"blurb": "Turn an uploaded video or audio file into files for browser playback, and serve them from your app."
},
+ {
+ "slug": "live-streams-bring-your-own-livekit",
+ "label": "Live streams with your own LiveKit",
+ "blurb": "Stream with chat on your own LiveKit Cloud project, record into your store, and play the recording back."
+ },
{
"slug": "scan-callbacks",
"label": "Receiving scan results",
diff --git a/docs/superpowers/notes/LUNA-DOCS-BRIEF-live-byo-livekit.md b/docs/superpowers/notes/LUNA-DOCS-BRIEF-live-byo-livekit.md
new file mode 100644
index 000000000..f636dcf2d
--- /dev/null
+++ b/docs/superpowers/notes/LUNA-DOCS-BRIEF-live-byo-livekit.md
@@ -0,0 +1,33 @@
+# Docs and copy pass: live streams on your own LiveKit
+
+You are the copy-review gate itself for this page. Paul delegated copy review of platform UI, CLI, email and docs copy to you on 2026-10-25; your verdicts ARE the review. Do NOT run the copy-review skill or start any server. Do not modify any file. You are writing a review report.
+
+## The page
+
+`docs/site/live-streams-bring-your-own-livekit.md`, a new docs site page, and its one entry in `docs/site/nav.json` (label and blurb). Readers are app builders on the platform who want a live stream with chat on their own LiveKit Cloud project, recorded into their app's store and converted for playback. Compare the voice and shape with `docs/site/media-conversion.md` and `docs/site/scan-callbacks.md`, the two pages it sits beside.
+
+## House rules (Paul's)
+
+- No em or en dashes used as dashes. Use a full stop and a new sentence.
+- Plain, direct, calm. No exclamation marks, no marketing tone, no "simply", no "please" padding, no filler.
+- Say what happened, then what to do. If the reader cannot fix it themselves, say who can.
+- Developer-facing, so technical words (Egress, webhook, multipart, token, grant) are fine where the reader needs them. Undefined jargon is not.
+- Neutral examples only (`shop`, `shop.example.com`, `recordings/a1b2/...`). Never a customer or tenant name.
+- Code samples stay in Go. Do not rewrite code unless a comment or string in it breaks a rule above or is wrong.
+
+## Facts to check against
+
+These are established; flag any sentence on the page that contradicts or overstates them.
+
+- Instances reach public addresses with no setting. The fence denies only loopback, private, link-local, CGNAT, multicast, reserved ranges and the metadata service (`internal/host/units/carlos-instance@.service`, the `IPAddressDeny=` line and its comment; `internal/egressaddr/egressaddr.go` `FenceDeny`). `carlos apps set --egress-allow` takes private IP addresses and ranges only (`docs/site/cli.md`, the `--egress-allow` paragraph).
+- A host behind `carlos gate` asks every request for the password (`internal/gate/gate.go` header; `docs/site/cli.md` "carlos gate"; the email events push paragraph says such an app cannot receive pushes).
+- The store user's policy is `storePolicyJSON` in `internal/objstore/aws.go`: GetObject, PutObject, DeleteObject, GetObjectTagging and the two multipart actions on objects, ListBucket on the bucket, an explicit Deny on PutObjectTagging, a Deny on PutObject carrying a platform tag key, and a PutObject Deny past the storage grace. There is no GetBucketLocation in it. AWS requires s3:PutObjectTagging for a PutObject that sets tags, so any tagged upload is refused.
+- LiveKit's S3 uploader (github.com/livekit/storage s3.go) asks for the bucket's location only when region and endpoint are both empty; it sends no ACL and no encryption header; it uploads files over 16 MiB in parts.
+- Media conversion: `docs/site/media-conversion.md` (classes and limits, refusals, Serving, the allowance). Conversion does not wait for a scan; it refuses an object only when a HEAD is denied (`internal/console/apimedia.go`, `handleAPIMediaSubmit` step 9).
+- Scanning skips objects above `CARLOS_CLAMD_MAX_BYTES`, 25 MiB by default (`docs/site/cli.md`, carlos store scan).
+- Under the media roadmap (`docs/superpowers/specs/2026-09-07-media-platform-roadmap-design.md` ยง8), the recipient of an egress is the app's decision, never the platform's. The privacy section must leave the decision with the app and must not promise that the platform discloses anything.
+
+## What to return
+
+1. A table `location | old | new | why`, with only the sentences you change, quoting the old text exactly so it can be applied verbatim. Rows you leave alone are approved as they are.
+2. A `## Flags` section with only what Paul must decide, or a fact you could not verify. Keep it short and give your recommendation for each. Write "none" if there are none.