Serving over HTTP
@intellibrix/express wraps an Express app in a Brick and ships two ready-made routes.
import ExpressBrick from '@intellibrix/express'import { Intelligence } from 'intellibrix'
const api = new ExpressBrick({ name: 'api', port: 10100, host: '0.0.0.0', // the default is localhost; use 0.0.0.0 inside a container intelligence: new Intelligence({ provider, model, memory }),})
api.askEndpoint() // POST /askapi.askStreamEndpoint() // GET /ask/streamPOST /ask
Section titled “POST /ask”curl -s localhost:10100/ask -H 'content-type: application/json' \ -d '{"prompt":"What is 2+2?","threadId":"demo"}'# {"reply":"4"}A missing prompt returns 400; a failure returns 500 with { error }. threadId selects the
conversation when the Intelligence has memory. If the client disconnects, the run is aborted so
you do not pay for an answer nobody is waiting for.
GET /ask/stream
Section titled “GET /ask/stream”curl -N 'localhost:10100/ask/stream?prompt=Tell+me+a+story'The response is Server-Sent Events, one event: <type> and data: <json> frame per stream
event (text deltas, tool calls, the finish), followed by event: done. In the browser use
EventSource. Disconnecting aborts the run here too.
Using the routes yourself
Section titled “Using the routes yourself”askRoute(target) and askStreamRoute(target) are plain Express handlers, and target can be a
Brick or an Intelligence, so you can add them to an app you already have:
import { askRoute } from '@intellibrix/express'
app.post('/chat', express.json(), authenticate, askRoute(brick))Before you expose it
Section titled “Before you expose it”- Authenticate. An open
/asklets anyone spend your tokens and use your tools. Add middleware (middleware: [authenticate]in the options runs before every route). - Gate tools. There is no human in an HTTP request, so a tool that
needsApprovalis denied unless you provide anonToolApprovalpolicy. Do not give a public endpoint tools that write. - Limit cost. Put rate limits in front and keep
maxStepsmodest. - Mind the body parser.
ExpressBrickparses JSON by default; for signed webhooks see Working with GitHub.