This directory contains REST API examples for elizaOS using TypeScript web frameworks.
All examples use the canonical elizaOS implementation pattern:
runtime.messageService.handleMessage(runtime, messageMemory, callback)
Every example follows the same core pattern:
- Create an AgentRuntime with plugins (sql, openai, etc.)
- Initialize the runtime with
await runtime.initialize() - Ensure connection for the user session
- Create a message memory with the user's message
- Call
messageService.handleMessage()to process the message
import {
AgentRuntime,
ChannelType,
createCharacter,
createMessageMemory,
stringToUuid,
} from "@elizaos/core";
import { openaiPlugin } from "@elizaos/plugin-openai";
import sqlPlugin from "@elizaos/plugin-sql";
// Create runtime
const runtime = new AgentRuntime({
character: createCharacter({ name: "Eliza", bio: "A helpful AI assistant." }),
plugins: [sqlPlugin, openaiPlugin],
});
await runtime.initialize();
// Handle a message
const messageMemory = createMessageMemory({
id: uuidv4(),
entityId: userId,
roomId: stringToUuid("room"),
content: { text: "Hello!", source: "api", channelType: ChannelType.API },
});
await runtime.messageService?.handleMessage(runtime, messageMemory, async (content) => {
console.log("Response:", content.text);
return [];
});| Framework | Language | Directory | Full Runtime |
|---|---|---|---|
| Express | TypeScript | express/ |
Yes |
| Hono | TypeScript | hono/ |
Yes |
| Elysia | TypeScript | elysia/ |
Yes |
All examples expose the same REST API:
Returns information about the agent.
curl http://localhost:3000/Health check endpoint.
curl http://localhost:3000/healthSend a message to the agent.
curl -X POST http://localhost:3000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello, how are you?"}'Response:
{
"response": "Hello! I'm doing well. How can I help you today?",
"character": "Eliza",
"userId": "generated-uuid"
}Send a message and receive a streaming response via Server-Sent Events.
curl -X POST http://localhost:3000/chat/stream \
-H "Content-Type: application/json" \
-d '{"message": "Tell me a story"}'cd express # or hono, elysia
bun install
OPENAI_API_KEY=your-key bun run start| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key | Yes |
PORT |
Server port (default: 3000) | No |
CHARACTER_NAME |
Agent name | No |
CHARACTER_BIO |
Agent bio/description | No |
DO NOT do this:
// ❌ WRONG - Never call plugin functions directly
import { generateElizaResponse } from "@elizaos/plugin-eliza-classic";
const response = generateElizaResponse(message);DO this instead:
// ✅ CORRECT - Always use the runtime's message service
await runtime.messageService?.handleMessage(runtime, messageMemory, callback);The message service:
- Manages conversation context and memory
- Runs evaluators to check if the agent should respond
- Invokes providers to gather context
- Executes actions based on the conversation
- Handles all model calls through the plugin system