Skip to main content

Overview

Resonance uses tRPC to provide a type-safe API for building text-to-speech applications. The API is organized into three main routers:
  • Voices - Manage custom and system voices
  • Generations - Create and retrieve TTS generations
  • Billing - Handle subscriptions and usage tracking

Architecture

tRPC Setup

Resonance uses tRPC with the following configuration:
import { initTRPC, TRPCError } from '@trpc/server';
import { auth } from '@clerk/nextjs/server';
import superjson from "superjson";

const t = initTRPC.create({
  transformer: superjson,
});

export const createTRPCRouter = t.router;
export const baseProcedure = t.procedure;

Data Transformation

The API uses SuperJSON for serialization, which allows for:
  • Date objects to be preserved across the wire
  • BigInt support for large numbers
  • Map and Set objects
  • Undefined values in objects

Error Handling

All endpoints use tRPC’s standardized error codes:
CodeDescriptionHTTP Status
UNAUTHORIZEDUser not authenticated401
FORBIDDENMissing permissions or subscription403
NOT_FOUNDResource not found404
PRECONDITION_FAILEDRequired condition not met412
INTERNAL_SERVER_ERRORServer-side error500

Next Steps

Authentication

Learn about Clerk-based authentication

Voices API

Manage voice clones

Generations API

Generate speech audio

Billing API

Handle subscriptions

Build docs developers (and LLMs) love