Hono

Integrate Better Agent with Hono.

Integrate Better Agent with Hono by creating your app and mounting its HTTP handler.

Create the app

Start with a normal Better Agent server module.

server.ts
import { betterAgent, defineAgent } from "@better-agent/core";
import { createOpenAI } from "@better-agent/providers/openai";

const openai = createOpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const assistant = defineAgent({
  name: "assistant",
  model: openai.text("gpt-5-mini"),
  instruction: "You are a concise assistant. Keep replies short and natural.",
});

const agentApp = betterAgent({
  agents: [assistant],
  baseURL: "/api",
  secret: "dev-secret",
});

export default agentApp;

Mount the handler

Create a Hono app and forward the raw web Request to Better Agent.

src/index.ts
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import agentApp from "./server";

const app = new Hono();

app.all("/api/*", (c) => {
  return agentApp.handler(c.req.raw);
});

serve(app);

Keep baseURL and the mounted route aligned. If the Better Agent app uses baseURL: "/api", mount it under /api.

CORS

If your client runs on a different origin, add Hono's CORS middleware before the Better Agent route.

src/index.ts
import { cors } from "hono/cors";

app.use(
  "/api/*",
  cors({
    origin: "http://localhost:3000",
    allowMethods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"],
    allowHeaders: ["Content-Type", "Authorization"],
  }),
);