Configuring the API
The Agent Press API is the backbone of your agent infrastructure. This guide covers starting and configuring the API server.
Starting the API Server
The API server is extremely simple to start:
// apps/api/src/index.ts
import { startServer } from "@agentpress/api";
import path from "path";
const paths = {
agents: path.resolve("../../packages/custom/src/agents"),
tools: path.resolve("../../packages/custom/src/tools"),
};
startServer({
agentsPath: paths.agents,
toolsPath: paths.tools,
seedAdminUser: true,
});Configuration Options
agentsPath- Path to your custom agents directorytoolsPath- Path to your custom tools directoryseedAdminUser- Creates an admin user on first startup
Running the Server
# Development (from project root)
bun dev
# Production
cd apps/api && bun startThe server automatically discovers and loads your custom agents and tools from the specified paths.
Custom Authentication
You can provide custom authentication handlers when starting the server:
startServer({
agentsPath: paths.agents,
toolsPath: paths.tools,
customLogin: async (params) => {
// Validate credentials against your system
const { username, password } = params;
// Return user data or Error
return { username, password };
},
customRegister: async (params) => {
// Handle user registration
const { username, password, firstName, lastName } = params;
return { username, password, firstName, lastName, role: EUserRole.USER };
},
customPasswordValidator: (password) => {
// Custom password validation rules
return { isValid: password.length >= 8, errors: ["Too short"] };
},
});Function Parameters
customLogin(params)- Receives the request body with user credentialscustomRegister(params)- Receives the request body with registration datacustomPasswordValidator(password)- Receives the password string to validate
Return Types
customLogin- Returns{ username, password }orErrorcustomRegister- Returns user object withrole: EUserRoleorErrorcustomPasswordValidator- Returns{ isValid: boolean, errors: string[] }
Last updated on