Skip to content
API Blog

Embed in Your App

Run Lobu inside your application as a library instead of a standalone server. Import @lobu/gateway, define your agents in code, and mount the HTTP handler into whatever framework you already use.

Terminal window
npm install @lobu/gateway
# or
bun add @lobu/gateway

You also need a running Redis instance. Any Redis-compatible server works (Redis, Upstash, Dragonfly, etc.).

import { Lobu } from "@lobu/gateway";
const lobu = new Lobu({
redis: process.env.REDIS_URL!,
agents: [
{
id: "support",
name: "Support Agent",
providers: [{ id: "openai", key: process.env.OPENAI_API_KEY! }],
},
],
});
// Option A: let Lobu start its own HTTP server
await lobu.start();
// Option B: initialize services without starting a server,
// then mount in your framework
await lobu.initialize();
const app = lobu.getApp(); // Hono app with .fetch(Request) → Response

getApp() returns a Hono application. Hono implements the Web Standard fetch(Request) → Response interface, so it mounts in any framework that speaks Web Standard Request/Response — or adapts to Node.js IncomingMessage/ServerResponse via @hono/node-server’s getRequestListener.


Web Standard Request/Response — direct app.fetch(req).

app/api/lobu/[...path]/route.ts
import { Lobu } from "@lobu/gateway";
const lobu = new Lobu({ /* ...config... */ });
const initialized = lobu.initialize();
async function handler(req: Request) {
await initialized;
return lobu.getApp().fetch(req);
}
export const GET = handler;
export const POST = handler;
export const PUT = handler;
export const DELETE = handler;

Node.js req/res — use @hono/node-server’s getRequestListener.

pages/api/lobu/[...path].ts
import type { NextApiRequest, NextApiResponse } from "next";
import { Lobu } from "@lobu/gateway";
import { getRequestListener } from "@hono/node-server";
const lobu = new Lobu({ /* ...config... */ });
const initialized = lobu.initialize();
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
await initialized;
getRequestListener(lobu.getApp().fetch)(req, res);
}

import express from "express";
import { Lobu } from "@lobu/gateway";
import { getRequestListener } from "@hono/node-server";
const app = express();
const lobu = new Lobu({ /* ...config... */ });
await lobu.initialize();
app.use("/lobu", getRequestListener(lobu.getApp().fetch));
app.listen(3000);

Lobu’s app is already a Hono instance — mount directly:

import { Hono } from "hono";
import { Lobu } from "@lobu/gateway";
const app = new Hono();
const lobu = new Lobu({ /* ...config... */ });
await lobu.initialize();
app.route("/lobu", lobu.getApp());
export default app;
import Fastify from "fastify";
import { Lobu } from "@lobu/gateway";
import { getRequestListener } from "@hono/node-server";
const fastify = Fastify();
const lobu = new Lobu({ /* ...config... */ });
await lobu.initialize();
const listener = getRequestListener(lobu.getApp().fetch);
fastify.all("/lobu/*", (req, reply) => listener(req.raw, reply.raw));
await fastify.listen({ port: 3000 });

Native fetch handler — no adapter needed:

import { Lobu } from "@lobu/gateway";
const lobu = new Lobu({ /* ...config... */ });
await lobu.initialize();
export default {
fetch: lobu.getApp().fetch,
port: 3000,
};

The LobuConfig object accepted by new Lobu():

FieldTypeDefaultDescription
redisstringrequiredRedis connection URL
agentsLobuAgentConfig[][]Agent definitions
portnumber8080HTTP port (only used with lobu.start())
deploymentMode"embedded" | "docker""embedded"How workers are spawned
publicUrlstringhttp://localhost:{port}Public URL for OAuth callbacks
adminPasswordstringauto-generatedAPI authentication password
memorystringMemory plugin URL

Each agent in the agents array:

FieldTypeDescription
idstringUnique agent identifier
namestringDisplay name
descriptionstringAgent description
identitystringIdentity prompt (markdown)
soulstringSoul prompt (markdown)
providersArray<{ id, model?, key? }>AI provider configs
connectionsArray<{ type, ... }>Platform connections (Slack, Telegram, etc.)
skillsstring[]Skill IDs to enable
network{ allowed?, denied? }Domain allowlist/denylist for workers
nixPackagesstring[]Nix packages available to workers

Embedding gives you the full gateway feature set:

  • Agent orchestration and worker lifecycle
  • MCP tool proxy
  • Provider credential management
  • Platform connections (Slack, Telegram, WhatsApp, Discord)
  • OpenAPI-documented REST API at /api/docs
  • Skills and memory support

The only difference from a standalone deployment: your application controls the HTTP server.