A minimal Node.js HTTP server demonstrating how to use the AI SDK to stream text and custom UI message data over HTTP.
| Method | Path | Description |
|---|---|---|
POST |
/ |
Streams a text response generated with streamText. |
POST |
/stream-data |
Streams a UI message stream that mixes custom data parts with streamText output. |
From the root of the AI SDK repo, install dependencies:
pnpm install
Create a .env file in examples/node-http-server/ (copy from .env.example) and add your OpenAI API key:
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
Start the server from this directory:
pnpm dev
The server listens on http://localhost:8080.
Stream a text response:
curl -X POST http://localhost:8080/
Stream custom data alongside generated text:
curl -X POST http://localhost:8080/stream-data