@ai_kit/server ships a pre-configured Hono application that turns agents and workflows into HTTP endpoints. It handles synchronous calls, streaming (SSE), human-in-the-loop resumes and can publish an OpenAPI spec with Swagger UI.
Installation
@ai_kit/core so you can reuse the agents and workflows you already defined.
Minimal example
HOST (default 0.0.0.0) and PORT (default 8787). Agents and workflows are stored in memory and reused across requests.
Exposed endpoints
| Route | Description |
|---|---|
GET /api/agents | Lists every agent registered in the server configuration. |
POST /api/agents/:id/generate | Executes Agent.generate once and returns the full result. |
POST /api/agents/:id/stream | Streams Agent.stream via SSE or DataStreamResponse. |
GET /api/workflows | Lists every workflow registered in the server configuration. |
POST /api/workflows/:id/run | Starts a workflow run and returns { runId, ...result }. |
POST /api/workflows/:id/stream | Streams every WorkflowEvent plus the final status via SSE. |
POST /api/workflows/:id/runs/:runId/resume | Resumes a suspended run with human input. |
inputData (optional metadata). Agent payloads must include either prompt or messages, matching the AI SDK contract.
Streaming & resume flow
/streamendpoints emit a firstrunevent containing therunId, then forward each workflowevent.typeas a dedicated SSE event.- When a workflow ends with
waiting_human, the stream closes after emitting the final payload. Resume the run later by POSTing{ stepId, data }to/runs/:runId/resume. - If the client disconnects, the server cancels the run and frees resources.
Swagger / OpenAPI
Swagger is on by default outside production. Configure it via theswagger option:
- UI served from
route(e.g./docs). - JSON spec available from
route + ".json". - Pass
falseto disable it, ortrueto force-enable it even in production.
CLI entry point
The package bundles aserver-kit binary (accessible via npx @ai_kit/server) that starts a bare ServerKit instance:
PORT(default8787).HOST(default0.0.0.0).NODE_ENVtoggles the default Swagger behaviour.
ServerKit inside your own API server (e.g. apps/api/server.ts) where you can pass the proper configuration object.
Configuration options
| Option | Type | Purpose |
|---|---|---|
agents | Record<string, Agent> | Registers agents exposed under /api/agents/:id/*. |
workflows | Record<string, Workflow> | Declares workflows exposed under /api/workflows/:id/*. |
swagger | boolean | SwaggerOptions | Enables Swagger or customizes route, title, version, description. |
telemetry | boolean | ServerTelemetryOptions | Enables Langfuse export and forwards options to ensureLangfuseTelemetry. |
listen({ port, hostname, signal }) also accepts an AbortSignal so you can shut the server down gracefully.
See packages/server/src/ServerKit.ts for the full implementation.
Langfuse telemetry
Toggle Langfuse directly from theServerKit config — no extra bootstrap file is required:
telemetryaccepts eithertrue/falseor the fullensureLangfuseTelemetryoptions.- Provide
LANGFUSE_PUBLIC_KEY,LANGFUSE_SECRET_KEY, and optionallyLANGFUSE_BASE_URLin the environment. - The CLI exposes matching
--telemetry/--no-telemetryflags for quick toggles.