Durable Streams
DocsDurable streams save generated output as it is written, then keep the finished result available by URL. This demo starts an AI summary, polls until content exists, and adds the completed stream to a history list. Use durable streams when generated output needs to outlive the request. For live browser output that doesn't need a saved URL, see SSE streaming.
History (0)
No summaries yet. Click "Generate Summary" to create one.
Reference Code
import { StreamClient } from "@agentuity/stream";
import { AIGatewayClient } from "@agentuity/aigateway";
const streams = new StreamClient();
const gateway = new AIGatewayClient();
const durable = await streams.create("ai-summaries", {
contentType: "text/plain",
metadata: { source: "nightly-report" },
// Seconds; 30 days is the platform default. Pass null to never expire.
ttl: 60 * 60 * 24 * 30,
});
const result = await gateway.completeText({
model: "openai/gpt-5.4-mini",
messages: [
{
role: "user",
content: "Write a short summary of today's customer feedback.",
},
],
});
await durable.write(result.text);
await durable.close();
const info = await streams.get(durable.id);
const body = await new Response(await streams.download(durable.id)).text();
const page = await streams.list({
namespace: "ai-summaries",
limit: 10,
});
// Delete the stream after its public URL no longer needs to work:
// await streams.delete(durable.id);
export const published = {
streamId: info.id,
url: info.url,
bytesWritten: durable.bytesWritten,
downloaded: body,
listed: page.streams.some((stream) => stream.id === durable.id),
};Ready
Output will appear here...