|
| 1 | +<div align="center"> |
| 2 | +<a href="https://voltagent.dev/"> |
| 3 | +<img width="1500" height="276" alt="voltagent" src="https://github.com/user-attachments/assets/d9ad69bd-b905-42a3-81af-99a0581348c0" /> |
| 4 | +</a> |
| 5 | + |
| 6 | +<h3 align="center"> |
| 7 | +AI Agent Engineering Platform |
| 8 | +</h3> |
| 9 | + |
| 10 | +<div align="center"> |
| 11 | + <a href="https://voltagent.dev">Home Page</a> | |
| 12 | + <a href="https://voltagent.dev/docs/">Documentation</a> | |
| 13 | + <a href="https://github.com/voltagent/voltagent/tree/main/examples">Examples</a> |
| 14 | +</div> |
| 15 | +</div> |
| 16 | + |
| 17 | +<br/> |
| 18 | + |
| 19 | +<div align="center"> |
| 20 | + |
| 21 | +[](https://github.com/voltagent/voltagent/issues) |
| 22 | +[](https://github.com/voltagent/voltagent/pulls) |
| 23 | +[](https://opensource.org/licenses/MIT) |
| 24 | +[](https://www.npmjs.com/package/@voltagent/server-hono) |
| 25 | +[](https://www.npmjs.com/package/@voltagent/server-hono) |
| 26 | +[](https://s.voltagent.dev/discord) |
| 27 | + |
| 28 | +</div> |
| 29 | + |
| 30 | +## @voltagent/server-hono |
| 31 | + |
| 32 | +The default VoltAgent server adapter, built on [Hono](https://hono.dev/). It wires up the routes, handlers, WebSocket support, and OpenAPI/Swagger UI provided by [`@voltagent/server-core`](https://github.com/VoltAgent/voltagent/tree/main/packages/server-core) into a runnable HTTP server. |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Install |
| 37 | + |
| 38 | +```bash |
| 39 | +npm install @voltagent/server-hono |
| 40 | +# or |
| 41 | +yarn add @voltagent/server-hono |
| 42 | +# or |
| 43 | +pnpm add @voltagent/server-hono |
| 44 | +``` |
| 45 | + |
| 46 | +## Usage |
| 47 | + |
| 48 | +```typescript |
| 49 | +import { VoltAgent, Agent } from "@voltagent/core"; |
| 50 | +import { honoServer } from "@voltagent/server-hono"; |
| 51 | +import { openai } from "@ai-sdk/openai"; |
| 52 | + |
| 53 | +const agent = new Agent({ |
| 54 | + name: "my-agent", |
| 55 | + instructions: "A helpful assistant", |
| 56 | + model: openai("gpt-4o-mini"), |
| 57 | +}); |
| 58 | + |
| 59 | +new VoltAgent({ |
| 60 | + agents: { agent }, |
| 61 | + server: honoServer(), |
| 62 | +}); |
| 63 | +``` |
| 64 | + |
| 65 | +This starts an HTTP server exposing the agent/workflow/tool/memory/observability routes defined in `@voltagent/server-core`, along with a Swagger UI for exploring the API. |
| 66 | + |
| 67 | +## Configuration |
| 68 | + |
| 69 | +`honoServer(config)` accepts a `HonoServerConfig`: |
| 70 | + |
| 71 | +| Option | Type | Default | Description | |
| 72 | +| ----------------- | ------------------------------ | --------------------- | --------------------------------------------------------------------------------------------------------------------------------- | |
| 73 | +| `port` | `number` | `3141` | Port to listen on | |
| 74 | +| `hostname` | `string` | `"0.0.0.0"` | Hostname to bind the server to | |
| 75 | +| `cors` | `CORSOptions \| false` | allows all origins | CORS configuration, or `false` to disable default CORS | |
| 76 | +| `enableSwaggerUI` | `boolean` | `true` in development | Enable the `/ui` Swagger UI route | |
| 77 | +| `resumableStream` | `{ adapter, defaultEnabled? }` | — | Configure a [`@voltagent/resumable-streams`](https://github.com/VoltAgent/voltagent/tree/main/packages/resumable-streams) adapter | |
| 78 | +| `configureApp` | `(app: Hono) => void` | — | Register custom routes/middleware directly on the Hono app | |
| 79 | + |
| 80 | +```typescript |
| 81 | +new VoltAgent({ |
| 82 | + agents: { agent }, |
| 83 | + server: honoServer({ |
| 84 | + port: 8080, |
| 85 | + cors: { |
| 86 | + origin: "https://example.com", |
| 87 | + allowMethods: ["GET", "POST", "OPTIONS"], |
| 88 | + }, |
| 89 | + configureApp: (app) => { |
| 90 | + app.get("/healthz", (c) => c.text("ok")); |
| 91 | + }, |
| 92 | + }), |
| 93 | +}); |
| 94 | +``` |
| 95 | + |
| 96 | +## Authentication |
| 97 | + |
| 98 | +`jwtAuth` provides a ready-to-use JWT `AuthProvider`: |
| 99 | + |
| 100 | +```typescript |
| 101 | +import { jwtAuth } from "@voltagent/server-hono"; |
| 102 | + |
| 103 | +const auth = jwtAuth({ |
| 104 | + secret: process.env.JWT_SECRET, |
| 105 | +}); |
| 106 | + |
| 107 | +new VoltAgent({ |
| 108 | + agents: { agent }, |
| 109 | + server: honoServer({ auth }), |
| 110 | +}); |
| 111 | +``` |
| 112 | + |
| 113 | +## Custom Endpoints & App Factory |
| 114 | + |
| 115 | +- `extractCustomEndpoints`, `getEnhancedOpenApiDoc` — helpers for registering custom routes and extending the generated OpenAPI document. |
| 116 | +- `createVoltAgentApp` — builds the underlying Hono app instance for embedding into existing Node.js servers (e.g. NestJS, Express) instead of using `honoServer` directly. |
| 117 | + |
| 118 | +```typescript |
| 119 | +import { createVoltAgentApp } from "@voltagent/server-hono"; |
| 120 | + |
| 121 | +const app = createVoltAgentApp(deps, config); |
| 122 | +``` |
| 123 | + |
| 124 | +## Documentation |
| 125 | + |
| 126 | +- [VoltAgent Documentation](https://voltagent.dev/docs/) |
| 127 | +- [`@voltagent/server-core`](https://github.com/VoltAgent/voltagent/tree/main/packages/server-core) — the framework-agnostic server core this adapter builds on |
| 128 | +- [Agent Overview](https://voltagent.dev/docs/agents/overview/) |
| 129 | + |
| 130 | +## License |
| 131 | + |
| 132 | +Licensed under the MIT License, Copyright © 2026-present VoltAgent. |
0 commit comments