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.
| 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":"..."}. |
npm install
neonctl link --project-name streaming --region-id aws-us-east-2 # add --agent to skip prompts
neonctl deployneon 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.
# 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).