Elysia

Elysia exposes a web Request, so you can call app.handler directly.

Server

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

const supportAgent = defineAgent({
  name: "support",
  model: openai("gpt-5.5"),
  instruction: "You help customers.",
});

const app = betterAgent({
  agents: [supportAgent],
  basePath: "/api/agents",
});

export default app;

Route

import { Elysia } from "elysia";
import app from "./lib/better-agent/server";

new Elysia()
  .all("/api/agents/*", ({ request }) => app.handler(request))
  .listen(3000);

Client

import { createClient } from "@better-agent/client";
import type app from "./lib/better-agent/server";

export const client = createClient<typeof app>({
  baseURL: "http://localhost:3000/api/agents",
});

Auth and headers

Headers from the web Request are forwarded to Better Agent. Use Auth to resolve identity from cookies, bearer tokens, or API keys.

Features

The mounted route supports runs, streams, threads, interrupts, client tools, and approvals. Use Client from your frontend to call it.

Next

See Client, Tools, Human in the Loop, Memory, Events, and Storage.