Skip to content

Repository files navigation

Neon Logo fallback

Neon Functions Streaming Demo

Companion code for Streaming an AI Agent Without a Function Timeout on DevOps Daily. Two endpoints that show a Neon Function holding a long-lived streaming connection: one ticks for as long as you ask, the other streams an AI agent's tokens through the Neon AI Gateway.

A Hono function deployed on Neon Functions, with no database tables — just streaming.

Endpoints

Route What it does
GET /long-stream?seconds=90 Server-sent events, one tick per second, for up to 600s. Proves the function holds the connection open well past short serverless caps.
POST /agent Streams an AI agent's tokens through the Neon AI Gateway (gpt-5-nano) as they are generated. Body: {"prompt":"..."}.

Run it

npm install
neonctl link --project-name streaming --region-id aws-us-east-2   # add --agent to skip prompts
neonctl deploy

neon link pulls branch-scoped env into .env.local, including the AI Gateway credentials (because neon.ts sets aiGateway: true). neon deploy provisions the function and prints its URL.

Try it

# Hold a stream open for 90 seconds, one tick/second
curl -N "https://<your-branch>-stream.compute.<region>.aws.neon.tech/long-stream?seconds=90"

# Stream an agent's tokens
curl -N -X POST "https://<your-branch>-stream.compute.<region>.aws.neon.tech/agent" \
  -H 'content-type: application/json' \
  -d '{"prompt":"In 3 short sentences, what is Neon database branching?"}'

The whole backend is declared in neon.ts, and the streaming logic is in src/index.ts (about 80 lines).

About

A Neon Function that holds long-lived streaming connections: long SSE + AI agent token streaming. Companion to a DevOps Daily post.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages