Neon Durable Streams: Power-User Guide to Setup, Resumable Chat and Limits

Last updated: December 5, 2026

Neon Durable Streams, announced December 4, 2026, runs an open-protocol Durable Streams server inside your own Neon Function. Each AI or agent stream gets a URL and is stored in Postgres and Object Storage, so a refreshed tab, a phone or a worker can resume from a saved offset.

Contents

What Neon released

Neon’s December 4 changelog introduced Durable Streams on Neon (Neon changelog). It targets a common gap: one HTTP response carries the output, so a refresh loses it.

Durable Streams is an open HTTP protocol built by the Electric team (Neon blog). Writers append to a stream URL, the server stores the data, and readers replay history and follow new output from wherever they left off (Neon docs). The new @neon/durable-streams library implements that server on four Neon services:

  • Neon Functions serve the HTTP API and hold long-poll and SSE connections open.
  • Postgres commits each append in a transaction, so writes are ordered and durable before the writer is acknowledged.
  • Neon Realtime pushes committed appends to the function so live readers do not poll.
  • Object Storage holds sealed, immutable history moved out of Postgres by a maintenance job.

Neon’s engineering post adds the sealing thresholds: a stream’s hot tail is moved to Object Storage once it reaches 4 MiB, 8,192 appends or one hour old. Sealed objects are split into 64 KiB blocks with SHA-256 checksums, so reads fetch only the blocks they need (Neon blog).

Plain SSE vs. Durable Streams on Neon

Capability Single SSE response Durable Streams on Neon
Survives refresh or network switch No, output in the open response is lost Yes, reader resumes from its saved offset
Where in-progress output lives Only in the open connection Postgres rows, then sealed objects in your bucket
Multiple readers (tab, phone, worker) One connection, one reader Any authorized reader can open the stream URL
Retry safety Re-asking reruns the request Producer ID and sequence number prevent duplicate appends
Live delivery Direct from the model call Realtime fast path, with replay from storage as fallback
Access control Your API route Your own authenticate and authorize hooks

The protocol also covers JSON mode, closure and expiry, forks and Ed25519-signed webhook subscriptions (Neon blog).

How to set up the server

You need a Neon project on Postgres 18 in a Functions region, Node.js 24 and the latest Neon CLI (npm install -g neon@latest). Neon warns that enabling Realtime turns on logical replication and restarts the branch’s computes, so schedule it on existing projects (Neon docs).

  1. Run neon login, neon link and neon realtime enable, then neon env pull --service postgres --service realtime to write NEON_REALTIME_URL and NEON_REALTIME_SECRET to .env.local.
  2. Add the template: neon functions new durable-streams --slug durablestreams --install.
  3. Create a token with openssl rand -hex 32 and append it as DURABLE_STREAMS_TOKEN in .env.local. It must be 32 to 1,024 characters and grants every stream operation, so keep it on the backend.
  4. In neon.ts, add preview: { realtime: true } and a private durable-streams bucket. Confirm the every-minute durable-streams-maintenance schedule trigger exists, since some CLI releases do not scaffold it.
  5. Deploy with neon deploy --env .env.local, then run neon env pull.
  6. Initialize the durable_streams schema once with the library’s migrate() helper over the direct (unpooled) connection. The function rejects stream requests until this is done.
  7. Test with neon dev: PUT to create /v1/stream/example, POST to append, and GET with ?offset=-1 to replay the whole stream.

Save each read’s opaque Stream-Next-Offset header and keep paging until a response includes Stream-Up-To-Date: true. Add live=sse or live=long-poll to follow new output, and use offset=now to start at the current end (Neon docs).

Make a useChat session survive refreshes

For chat apps, the Durable Streams project publishes @durable-streams/aisdk-transport. On the client, pass createDurableChatTransport({ api: "/api/chat" }) to useChat with resume: true. On the server, wrap result.toUIMessageStream() with toDurableStreamResponse, which writes AI SDK chunks into the stream and returns the read URL (Durable Streams docs).

The resume flow has four parts:

  • Persist the active stream ID for the chat while generation runs.
  • Add a reconnect endpoint such as GET /api/chat/:id/stream.
  • Return 204 when no generation is active, or 200 with Location and { streamUrl } when one is.
  • Keep resume: true in useChat.

Neon’s Durable Chat demo uses Claude Haiku through Neon AI Gateway. Each reply is its own stream, and generation runs under waitUntil so closing the tab does not stop it (Neon blog). The same gateway now offers Gemini 4 Neon and Gemini 4 Hydrogen, both with 1M-token context windows (Neon changelog).

Power-user patterns and settings

  • One stream per agent run. Use paths like runs/run-42/events so others can follow the run from another device.
  • Idempotent producers. Tag appends with a producer ID and sequence number so retries after a lost response never duplicate output.
  • Let a coding agent wire it up. Neon publishes an eight-step prompt that points the agent to the library README and template, asks before enabling Realtime, and ends with a refresh test that checks for duplicates (Neon docs).

If you already persist agent state in a framework, compare this with durable agents in Mastra 1.86 or conversation stores in Pydantic AI 2.77. Those keep agent state; Durable Streams keeps streamed output.

Limitations and production checklist

  • Single shared token. The template’s token grants access to every stream. Replace both the authenticate and authorize hooks with your app’s identity and per-stream checks before real users arrive.
  • Browser access. Set allowedOrigins, use short-lived credentials and keep secrets server-side.
  • No automatic reruns. Committed output survives, but a crashed agent or model call is not restarted.
  • Branches need care. A branch created from one with an existing installation needs the library’s adoption and recovery procedure first.
  • Regions. Functions run only in aws-us-east-2, aws-us-east-1, aws-eu-central-1 and aws-ap-southeast-1 for now. They are available on any plan, subject to usage limits (Neon Functions docs).

Neon’s announcement lists no separate Durable Streams price; costs come from the underlying Functions, Postgres, Realtime and storage usage. The same changelog cut paid-plan egress to $0.09/GB from $0.10/GB above the included 500 GB per project each month, effective December 1 (Neon changelog).

Frequently asked questions

What is Neon Durable Streams?

It is a Durable Streams server, shipped as the @neon/durable-streams library, that runs inside your own Neon Function. Each stream gets its own URL, output is stored in your project’s Postgres and Object Storage, and readers can replay it from a saved offset after a refresh or disconnect.

How do I start a Durable Streams server on Neon?

Enable Realtime, then run neon functions new durable-streams –slug durablestreams –install. Add a bearer token of 32 to 1,024 characters, declare Realtime and a private bucket in neon.ts, deploy with neon deploy –env .env.local, and run the library’s migration once.

Does Durable Streams work with the Vercel AI SDK?

Yes. Install @durable-streams/aisdk-transport, pass createDurableChatTransport to useChat with resume: true, and wrap the server’s UI message stream with toDurableStreamResponse. A TanStack AI transport is also available.

Which Neon regions and plans support it?

The server needs Postgres 18 and Neon Functions, which run in aws-us-east-2, aws-us-east-1, aws-eu-central-1 and aws-ap-southeast-1. Neon says Functions are available on any plan, subject to usage limits.

Will Durable Streams restart a failed model call?

No. Neon says Durable Streams keeps committed output but does not restart a crashed agent or model call. Keep generation running on the server when a reader disconnects, and handle reruns in your own code.

Sources

Related answers

Leave a Comment