Introduction
The Better Skills API is built with tRPC, providing end-to-end type safety from the server to your TypeScript/JavaScript clients. All API procedures are defined in the centralized AppRouter and exposed through a Hono server.Architecture
Core Packages
@better-skills/api- Shared tRPC router and contextapps/server- Hono backend that hosts the tRPC endpoints@better-skills/auth- Better Auth integration
Transport Layer
The tRPC API is served via Hono at the/trpc/* endpoint:
AppRouter Structure
The main application router is defined inpackages/api/src/routers/index.ts:
Procedure Types
The API defines three types of procedures:Public Procedures
Public procedures are accessible without authentication:Protected Procedures
Protected procedures require a valid session:Admin API Procedures
Admin procedures require a token via thex-better-skills-admin-token header:
Client Setup
TypeScript Client
Import theAppRouter type for full type safety:
JavaScript Client
For JavaScript projects without TypeScript:Base URL Configuration
The API base URL varies by environment:- Development:
http://localhost:3000 - Production: Set via
SERVER_URLenv variable
apps/web) uses:
apps/cli) uses:
Main Routers
The AppRouter is organized into feature-based sub-routers:skills- Skills CRUD, search, graph, and mention managementvaults- Vault memberships, invitations, and enterprise vault management
Error Handling
tRPC uses typed error codes. Common errors:UNAUTHORIZED- Missing or invalid session/tokenFORBIDDEN- Insufficient permissionsNOT_FOUND- Resource does not existBAD_REQUEST- Invalid input or requestINTERNAL_SERVER_ERROR- Unexpected server error
CORS Configuration
The server uses credential-based CORS:CORS_ORIGIN environment variable.