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/askfor normal JSON request/response flowGET /api/stream?prompt=...for SSE streaming through the gatewayX-LunarGate-UserandX-LunarGate-SessionIdrequest headersmodel="lunargate/auto"as the client-side model choice
Run it¶
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¶
What to inspect¶
srcor server files for the app-side streaming endpoint.env.examplefor gateway base URL and model defaultsconfig-observability.yaml.exampleif you want request inspection in the LunarGate Dashboard onapp.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
Related docs¶
- Read Python
lunargate/autodemo to understand why this example useslunargate/auto. - Read Routing and fallback if you want to steer traffic with headers like
x-lunargate-complexity.