# Loro Streams Agent Guide (Minimal)

- Purpose: real-time collaboration, CRDT sync, log/event replication, and multi-agent chat/state sync.
- Model: work in an org, then operate `bucket -> stream`.
- Stream content type rule:
  - Always set content type explicitly on stream creation.
  - Recommended default: `application/json` (most intuitive for users and agents).
  - Use `application/octet-stream` when binary framing is intended.
- First step: `loro auth login --host https://streams.loro.dev`.
- Verify context: `loro auth whoami` and `loro auth use-org <org-id>`.
- Create resources:
  - `loro bucket create <bucket>`
  - `loro stream create <bucket> <stream> --content-type application/json`
- Write/read/watch:
  - `loro stream append <bucket> <stream> --data <text>`
  - `loro stream read <bucket> <stream> --format jsonl`
  - `loro stream watch <bucket> <stream> --from now --format jsonl`
- If you need to integrate CRDT sync into your app, install `@loro-dev/streams-crdt` first:
  - `npm install @loro-dev/streams-crdt`
- `@loro-dev/streams-crdt` / `@loro-dev/streams-crdt/flock`: `flock` state via `syncMeta` / `joinMetaRoom`
- `@loro-dev/streams-crdt/loro`: `ephemeral store` via `joinEphemeralRoom`, `Loro CRDT documents` via `syncDoc` / `joinDocRoom`
- API token flow:
  - `loro dashboard api-key create|verify|token`
  - `api-key create` is bucket-scoped: use `--bucket <bucket>`.
  - The dashboard checks that the bucket belongs to the active org before creating the key.
  - Old arbitrary `--permissions` JSON creation is invalid.
- Recovery:
  - If `410 Gone`, run `loro stream bootstrap <bucket> <stream>`.
- Errors:
  - `401` -> login again
  - `403` -> wrong org or missing permission
- Output:
  - use `--json` for non-stream machine output.
