This directory contains example applications demonstrating Streamkeeper (DurableStreams) functionality.
- Elixir 1.19+
- Erlang/OTP 27+
A command-line demonstration of the core DurableStreams API showing:
- Stream creation
- Appending data
- Reading data
- Long-polling for updates
- JSON mode
- Stream cleanup
Run:
cd /path/to/streamkeeper
elixir examples/simple_demo.exsExpected output:
============================================================
DurableStreams Simple Demo
============================================================
--- 1. Creating a Stream ---
Created stream: demo-stream
Content-Type: text/plain
...
--- 2. Appending Data ---
Appended: "Hello, World!"
...
The flagship example demonstrating the primary use case from the Durable Streams announcement: resumable AI token streaming.
Features demonstrated:
- Resumable streaming - Disconnect mid-AI-response and resume without losing tokens
- Multi-client broadcast - Multiple tabs watch the same AI response in real-time
- Replay capability - Re-watch the entire response from the beginning
- DurableStreams.LiveView helper - Shows how to use the DSLive module for easy integration
- Multi-provider support - Works with Claude (Anthropic), GPT (OpenAI), or Demo mode
Run:
cd /path/to/streamkeeper
iex examples/llm_streaming.exsThen open http://localhost:4000 in your browser.
API Keys (Optional):
The example works without any API keys using Demo mode, which simulates streaming with pre-defined text. For real AI responses, set one or both:
export ANTHROPIC_API_KEY=your-anthropic-key-here
export OPENAI_API_KEY=your-openai-key-hereIf both are set, one is randomly chosen for each generation.
Try this:
- Enter a prompt and click "Generate Response"
- Mid-stream, click "Disconnect", then "Resume" → no tokens lost!
- Open another browser tab and click "Replay from Start" to watch the full response
- Open multiple tabs before generating → all tabs see tokens stream in real-time
These examples use Phoenix Playground to create single-file Phoenix applications without needing a full project setup.
The examples automatically install their dependencies via Mix.install/1 - no manual setup required.