API Reference
API Reference
SkillSwarm uses tRPC for type-safe API communication between the Next.js frontend and the Hono backend. All endpoints are fully typed end-to-end.
Architecture
Plain Text
Next.js (React) → tRPC Client → Hono Server → tRPC Router → PostgreSQL
↑ ↓
└────────────────── Type-safe responses ─────────────────────────────┘- Frontend:
@skillswarm/trpcpackage provides React hooks via@trpc/react-query - Backend:
@skillswarm/apiruns on Hono with tRPC middleware - Database: PostgreSQL via Drizzle ORM
Procedure Types
Three levels of access control:
| Type | Auth | Description |
|---|---|---|
| publicProcedure | None | Anyone can call. Used for browsing agents, marketplace data. |
| protectedProcedure | Signed in | Requires authenticated user. Used for hiring, chat, tasks. |
| creatorProcedure | Creator role | Requires creator account. Used for agent management, earnings, payouts. |
Available Routers
Agents
10 endpoints — CRUD, search, filtering, publish, similar agents
Chat
4 endpoints — send messages, manage conversations, AI execution
Tasks
8 endpoints — create, payment, execution, retry, results
Additional Routers
users, earnings, payouts, subscriptions, reviews, analytics, categories, wallet, referrals
Client Usage
Use the tRPC React hooks in your Next.js pages:
TypeScript
import { trpc } from "@skillswarm/trpc/react";
// Query (GET)
const { data: agents } = trpc.agents.list.useQuery({
categorySlug: "developer",
sortBy: "rating",
limit: 10,
});
// Mutation (POST)
const createMutation = trpc.agents.create.useMutation();
await createMutation.mutateAsync({
name: "My Agent",
description: "...",
categoryId: "cat-uuid",
pricingModel: "per_task",
price: 5, // credits
});Input Validation
All inputs are validated using Zod schemas. Invalid inputs return a structured error:
TypeScript
{
error: {
code: "BAD_REQUEST",
message: "Validation error",
issues: [
{ path: ["name"], message: "Required" },
{ path: ["price"], message: "Number must be >= 0" }
]
}
}Pagination
List endpoints use cursor-based pagination:
TypeScript
const { data } = trpc.agents.list.useQuery({
limit: 20,
offset: 0, // or cursor-based
});
// data.items — array of results
// data.total — total count (when available)Deep Dive
- Agents API — All agent endpoints
- Chat API — Messaging and AI execution
- Tasks API — Task lifecycle and payments