Server API Reference
The@ag-kit/server package exposes minimal helpers for serving agents over HTTP.
Quick start
run (recommended)
Framework‑agnostic HTTP handler
@whatwg-node/server and returns a Fetch-compatible handler with Node helpers. See the upstream adapter capabilities for more details: whatwg-node/server.
Exports
run(props)createExpressServer(props): ExpresscreateExpressRoutes(props): Expressagui.sendMessage.createServerAdapter(createAgent): (request) => Promise<Response>agui.sendMessage.handler(input, agent): AsyncIterable<SendMessageEvent>— low‑level generator used by the adapteragui.healthz.serverAdapter: (request) => Promise<Response>
API
run
Starts an Express server in one call.- Auto‑converts non‑abstract agents via
toAGUIAgent() - Registers
send-message,healthz,openai/chat/completionsroutes - Uses
/as defaultbasePath
createExpressServer
Creates and configures an Express app with agent routes.createExpressRoutes
Adds agent routes to an existing Express app.agui.sendMessage.createServerAdapter
Creates a Fetch‑compatible handler that validates input and streams SSE events.agui.sendMessage.handler
Low‑level function that drives the agent and yields events.agui.healthz.serverAdapter
Simple health probe endpoint returningOK.
Endpoints (Express helpers)
POST {basePath}send-message— body isSendMessageInput; response istext/event-streamGET {basePath}healthz— returnsOK
basePath defaults to /.
Request and events
These types come from@ag-kit/shared and are enforced at runtime with Zod:
CORS
CORS is enabled by default. Passcors: false to disable CORS or provide CorsOptions to configure it.