Skip to content
Intent
Libraries
Loading libraries…
Blog
Blog & Release Notes
About
YouTube
The official TanStack channel.
Workshops
Live sessions from the maintainers.
Release Notes
The latest releases and changelog.
Community
Channels
Discord
Real-time community support.
GitHub
Source, issues, discussions, and releases.
People & Work
Maintainers
Meet the people maintaining the stack.
Showcase
Projects selected by the TanStack team.
Community projects
TanChat
NEW
Tools
Tools
Application Starter
Alpha
Generate TanStack app starters.
Stats
NPM and ecosystem usage data.
Merch
Support
Support
Support Overview
Find the right support path.
Partners
Companies supporting TanStack.
OSS Sponsors
Sponsors keeping TanStack open source.
Enterprise Support
Private consulting and expert support.
Contact
Get in touch with the TanStack team.
About
Ethos
How we approach open source.
Tenets
The values that shape TanStack libraries.
Design System
Logos, tokens, and UI components.
Search
Ask AI
Libraries
Blog
Community
TanChat
NEW
Tools
Merch
Support
Search
Ask AI
Sign In
Back
TanStack Intent
/
Registry
/
@trpc/server
Fetching package from npm...
TanStack Intent
/
Registry
/
@trpc/server
@trpc/server
11.23.0 (latest) — 16 skills
11.22.2-canary.42.d3cd94bdd — 16 skills
11.22.2-canary.37.6d6969c7c — 16 skills
11.22.2-canary.19.b9321728b — 0 skills
11.22.2-canary.16.ea96ec538 — 0 skills
11.22.2-canary.15.a81bba207 — 0 skills
11.22.2-canary.14.9880a8bf9 — 0 skills
11.22.2-canary.11.4427f0bea — 0 skills
11.22.2-canary.9.85bcf328a — 16 skills
11.22.2-canary.7.c01346ec8 — 16 skills
11.22.2-canary.6.9959a177b — 16 skills
11.22.2-canary.1.0c622a522 — 16 skills
11.21.1-canary.65.e2b808347 — 16 skills
11.22.1 — 16 skills
11.21.1-canary.20.10e2ef98f — 16 skills
11.19.1-canary.0.sha-8b649ad87 — 16 skills
11.19.0 — 16 skills
11.18.1-canary.13 — 16 skills
11.18.1-canary.30 — 16 skills
11.18.1-canary.9 — 16 skills
11.18.1-canary.19 — 16 skills
11.18.1-canary.18 — 16 skills
11.18.1-canary.35.sha-573d4f33e — 16 skills
11.18.1-canary.34.sha-3a77dc4d6 — 16 skills
11.18.1-canary.17 — 16 skills
11.18.1-canary.11 — 16 skills
11.18.1-canary.15 — 16 skills
11.18.1-canary.6 — 16 skills
11.18.1-canary.5 — 16 skills
11.18.1-canary.2 — 16 skills
11.18.1-canary.1 — 16 skills
11.18.0 — 16 skills
11.17.1-canary.3 — 16 skills
11.17.1-canary.2 — 16 skills
11.17.0 — 16 skills
11.16.1-canary.20 — 16 skills
11.16.1-canary.17 — 16 skills
11.16.1-canary.6 — 16 skills
11.16.1-canary.5 — 16 skills
11.16.1-canary.4 — 16 skills
11.16.1-canary.3 — 16 skills
11.16.1-canary.2 — 16 skills
11.16.1-canary.1 — 16 skills
11.16.0 — 16 skills
11.15.2 — 16 skills
11.15.2-canary.3 — 16 skills
11.15.2-canary.2 — 16 skills
11.15.1 — 16 skills
11.15.1-canary.2 — 16 skills
11.15.0 — 16 skills
11.14.2-canary.5 — 16 skills
11.14.1 — 16 skills
Copy install prompt
The tRPC server library
Skills
(16)
Skills
All Skills
16
adapter-aws-lambda
adapter-express
adapter-fastify
adapter-fetch
adapter-standalone
auth
caching
error-handling
middlewares
non-json-content-types
server-setup
server-side-calls
service-oriented-architecture
subscriptions
trpc-router
validators
Skills
16
History
adapter-aws-lambda
Deploy tRPC on AWS Lambda with awsLambdaRequestHandler() from @trpc/server/adapters/aws-lambda for API Gateway v1 (REST, APIGatewayProxyEvent) and v2 (HTTP, APIGatewayProxyEventV2), and Lambda Function URLs. Enable response streaming with awsLambdaStreamingRequestHandler() wrapped in awslambda.streamifyResponse(). CreateAWSLambdaContextOptions provides event and context for context creation. Use one {proxy+} resource for httpBatchLink, or httpLink for a resource per procedure.
222 lines
adapter-express
Mount tRPC as Express middleware with createExpressMiddleware() from @trpc/server/adapters/express. Access Express req/res in createContext via CreateExpressContextOptions. Mount at a path prefix like app.use('/trpc', ...). Adapter options: onError, maxBatchSize, maxBodySize, middleware. Body parsers registered before tRPC (Express 4's express.json(), or express.raw()) break FormData and binary inputs, so scope them to non-tRPC routes.
191 lines
adapter-fastify
Mount tRPC as a Fastify plugin with fastifyTRPCPlugin from @trpc/server/adapters/fastify. Configure prefix, trpcOptions (router, createContext, onError). Enable WebSocket subscriptions with useWSS and @fastify/websocket. Set routerOptions.maxParamLength for batch requests. Requires Fastify v5+. FastifyTRPCPluginOptions for type-safe onError. CreateFastifyContextOptions provides req, res. Register @fastify/websocket before the tRPC plugin.
314 lines
adapter-fetch
Deploy tRPC on WinterCG-compliant edge runtimes with fetchRequestHandler() from @trpc/server/adapters/fetch. Supports Cloudflare Workers, Deno Deploy, Vercel Edge Runtime, Astro, Remix, SolidStart. FetchCreateContextFnOptions provides req (Request) and resHeaders (Headers) for context creation. The endpoint option must match the URL path prefix where the handler is mounted.
477 lines
adapter-standalone
Mount tRPC on Node.js built-in HTTP server with createHTTPServer() from @trpc/server/adapters/standalone, createHTTPHandler() for custom http.createServer, createHTTP2Handler() for HTTP/2 with TLS. Configure basePath to slice URL prefix, CORS via the cors npm package passed as middleware option. CreateHTTPContextOptions provides req and res for context creation. Pass the common adapter options (onError, maxBatchSize, maxBodySize) to createHTTPServer.
289 lines
auth
Implement JWT/cookie authentication and authorization in tRPC using createContext for user extraction, t.middleware with opts.next({ ctx }) for context narrowing to non-null user, protectedProcedure base pattern, client-side Authorization headers via httpBatchLink headers(), WebSocket connectionParams, and SSE auth via cookies or EventSource polyfill custom headers. UNAUTHORIZED vs FORBIDDEN, role checks stacked on protectedProcedure, and why createContext shouldn't throw for a bad token.
468 lines
caching
Set HTTP cache headers on tRPC query responses via the adapter's responseMeta callback (info, ctx, type, errors, eagerGeneration) for CDN and browser caching. Configure Cache-Control, s-maxage, stale-while-revalidate. Handle caching with batching, streaming and authenticated requests. Avoid caching mutations, errors, and authenticated responses.
116 lines
error-handling
Throw typed errors with TRPCError and error codes (NOT_FOUND, UNAUTHORIZED, FORBIDDEN, BAD_REQUEST, INTERNAL_SERVER_ERROR), configure errorFormatter for client-side Zod error display or to hide internal error messages, format errors per procedure with .errors(), handle errors globally with the adapter's onError callback, map tRPC errors to HTTP status codes with getHTTPStatusCodeFromError(), control stack traces with isDev.
360 lines
middlewares
Create and compose tRPC middleware with t.procedure.use(), extend context via opts.next({ ctx }), build reusable middleware with .concat() and .unstable_pipe(), define base procedures like adminProcedure and protectedProcedure. Read unvalidated input with opts.getRawInput() before .input(), check result.ok from opts.next(). Authorization, logging and timing patterns.
442 lines
non-json-content-types
Handle FormData, file uploads, Blob, Uint8Array, and ReadableStream inputs in tRPC mutations. Use octetInputParser from @trpc/server/http for binary data. Route non-JSON requests with splitLink and isNonJsonSerializable() from @trpc/client, since batching links send them as `{}`. FormData and binary inputs only work with mutations (POST) and skip the transformer. Keep Express or Next.js body parsers off tRPC routes.
247 lines
server-setup
Set up a tRPC server. Initialize tRPC once with initTRPC.context<Context>().create(), define routers with t.router() and procedures with .query()/.mutation(), build reusable base procedures such as publicProcedure and authedProcedure, type and create the request context with createContext() (inner/outer context for tests and server-side calls), export the AppRouter type, nest child routers or merge them with t.mergeRouters(), lazy-load routers with lazy().
481 lines
server-side-calls
Call tRPC procedures directly from server code using t.createCallerFactory(router) and router.createCaller(ctx) for integration testing, internal server logic, and custom API endpoints. Pass the context as an object or a function, e.g. an inner context without a request. Catch TRPCError and extract HTTP status with getHTTPStatusCodeFromError(), report errors with createCaller's onError option. Don't use a caller inside another procedure; share a plain function instead.
345 lines
service-oriented-architecture
Break a tRPC backend into multiple services with custom routing links that split on the first path segment (op.path.split('.')) to route to different backend service URLs. Define a faux gateway router that merges service routers for the AppRouter type without running them in the same process. Share procedure and router definitions via a server-lib package with a single initTRPC instance. Each service runs its own standalone/Express/Fastify server.
152 lines
subscriptions
Set up real-time event streams with async generator subscriptions using .subscription(async function*() { yield }). SSE via httpSubscriptionLink is recommended over WebSocket. Use tracked(id, data) from @trpc/server for reconnection recovery with lastEventId. WebSocket via wsLink and createWSClient from @trpc/client, applyWSSHandler from @trpc/server/adapters/ws. Configure SSE ping with initTRPC.create({ sse: { ping: { enabled, intervalMs } } }). AbortSignal via opts.signal for cleanup. splitLink to route subscriptions. Consume them with the client's .subscribe(input, { onData, onError }) and .unsubscribe().
451 lines
trpc-router
Entry point for all tRPC skills. Decision tree routing by task: initTRPC.create(), t.router(), t.procedure, createTRPCClient, adapters, subscriptions, React Query, Next.js, links, middleware, validators, error handling, caching, FormData, OpenAPI, multiple services. Includes a minimal working server and client.
222 lines
validators
Configure input and output validation with .input() and .output() using Zod, Yup, Superstruct, ArkType, Valibot, Effect, any Standard Schema library, or custom validator functions. Chain multiple .input() calls to merge object schemas. Invalid input fails with BAD_REQUEST (the validator's error is the cause); invalid output fails with INTERNAL_SERVER_ERROR.
485 lines