Skip to content

Node Express with streaming

This example is a slightly more realistic service: your app exposes its own HTTP API and calls LunarGate behind the scenes.

Best for

Use this example when you want to see how LunarGate fits inside an app server, not just a one-off script.

What it demonstrates

  • POST /api/ask for normal JSON request/response flow
  • GET /api/stream?prompt=... for SSE streaming through the gateway
  • X-LunarGate-User and X-LunarGate-SessionId request headers
  • model="lunargate/auto" as the client-side model choice

Run it

cp .env.example .env
npm install
npm run dev

The app starts on http://127.0.0.1:3001.

Test the endpoints

JSON endpoint

curl -X POST http://127.0.0.1:3001/api/ask \
  -H "Content-Type: application/json" \
  -d '{"prompt":"Explain why a gateway helps in a multi-team AI platform."}'

Streaming endpoint

curl -N "http://127.0.0.1:3001/api/stream?prompt=Write%20a%20short%20haiku%20about%20LunarGate"

What to inspect

  • src or server files for the app-side streaming endpoint
  • .env.example for gateway base URL and model defaults
  • config-observability.yaml.example if you want request inspection in the LunarGate Dashboard on app.lunargate.ai

Why this example matters

Many teams do not call the gateway directly from a browser or CLI. They call it from another backend service.

This example shows the separation clearly:

  • your app keeps its own API contract
  • LunarGate stays behind that app boundary
  • streaming can still pass through cleanly