Workflow·API Development

tRPC OpenAPI

Generate an OpenAPI 3.1 spec from a tRPC router with @trpc/openapi (CLI or programmatic) and a typed REST client with @hey-api/openapi-ts.

You say
Buy it · $39 Read it before you buy $39 Written by trpc · unverified publisher
Context cost
2.2k tokensestimated from the bundle, loaded when it triggers
Bundle
1 file · 8.9 kBtext throughout, nothing executable
Licence
MITpaid listing
Last change
no release on file
Servers it uses
Noneruns standalone

What it does

Generate OpenAPI 3.1 spec from a tRPC router with @trpc/openapi CLI or programmatic API. Generate typed REST client with @hey-api/openapi-ts and configureTRPCHeyApiClient(). Configure transformers (superjson, EJSON) for generated clients. Alpha status.

Installed, it changes the agent in these ways.

What this skill changes about the agent is not written down here yet. The listing was collected from its source, and the description is in its own SKILL.md.

Workflow

Runs a procedure end to end.

openapitrpcrestcodegen
Filed under

API Development

The skill itself

This is the whole product. A skill is instructions the model reads, so there is nothing behind the listing you cannot see first — the front matter loads with every session, and the body below it loads when the skill triggers.

SKILL.md8.9 kB · 301 lines
--- name: openapi description: > Generate OpenAPI 3.1 spec from a tRPC router with @trpc/openapi CLI or programmatic API. Generate typed REST client with @hey-api/openapi-ts and configureTRPCHeyApiClient(). Configure transformers (superjson, EJSON) for generated clients. Alpha status. type: composition library: trpc library_version: '11.16.0-alpha' requires: - server-setup sources: - 'trpc/trpc:www/docs/client/openapi.md' - 'trpc/trpc:packages/openapi/test/heyapi.test.ts' - 'trpc/trpc:examples/openapi-codegen/' ---
19# tRPC -- OpenAPI
20
21> **Alpha**: @trpc/openapi is versioned as 11.x.x-alpha. APIs may change without notice.
22
23## Setup
24
25### 1. Install
26
27```bash
28pnpm add @trpc/openapi
29```
30
31For HeyAPI client generation:
32
33```bash
34pnpm add @hey-api/openapi-ts -D
35```
36
37### 2. Generate the OpenAPI spec
38
39The generator statically analyses your router's TypeScript types. It never executes your code.
40
41**CLI:**
42
43```bash
44pnpm exec trpc-openapi ./src/server/index.ts -e appRouter -o openapi.json --title "My API" --version 1.0.0
45```
46
47| Option | Default | Description |
48| --------------------- | -------------- | --------------------------- |
49| -e, --export <name> | AppRouter | Name of the exported router |
50| -o, --output <file> | openapi.json | Output file path |
51| --title <text> | tRPC API | OpenAPI info.title |
52| --version <ver> | 0.0.0 | OpenAPI info.version |
53
54**Programmatic:**
55
56```ts
57import { generateOpenAPIDocument } from '@trpc/openapi';
58
59const doc = await generateOpenAPIDocument('./src/server/index.ts', {
60 exportName: 'appRouter',
61 title: 'My API',
62 version: '1.0.0',
63});
64```
65
66### 3. Generate a HeyAPI client from the spec
67
68```ts
69// scripts/codegen.ts
70import { rmSync, writeFileSync } from 'node:fs';
71import * as path from 'node:path';
72import { fileURLToPath } from 'node:url';
73import { createClient } from '@hey-api/openapi-ts';
74import { generateOpenAPIDocument } from '@trpc/openapi';
75import { createTRPCHeyApiTypeResolvers } from '@trpc/openapi/heyapi';
76
77const __filename = fileURLToPath(import.meta.url);
78const __dirname = path.dirname(__filename);
79
80const routerPath = path.resolve(__dirname, '..', 'server', 'index.ts');
81const outputDir = path.resolve(__dirname, '..', 'client', 'generated');
82const specPath = path.resolve(__dirname, '..', '..', 'openapi.json');
83
84async function main() {
85 const doc = await generateOpenAPIDocument(routerPath, {
86 exportName: 'appRouter',
87 title: 'Example API',
88 version: '1.0.0',
89 });
90
91 writeFileSync(specPath, JSON.stringify(doc, null, 2) + '\n');
92
93 rmSync(outputDir, { recursive: true, force: true });
94
95 await createClient({
96 input: specPath,
97 output: outputDir,
98 plugins: [
99 {
100 name: '@hey-api/typescript',
101 '~resolvers': createTRPCHeyApiTypeResolvers(),
102 },
103 {
104 name: '@hey-api/sdk',
105 operations: { strategy: 'single' },
106 },
107 ],
108 });
109}
110
111main().catch((err) => {
112 console.error(err);
113 process.exit(1);
114});
115```
116
117Run it:
118
119```bash
120pnpm tsx scripts/codegen.ts
121```
122
123### 4. Configure and use the generated client at runtime
124
125```ts
126import { configureTRPCHeyApiClient } from '@trpc/openapi/heyapi';
127import { client } from './generated/client.gen';
128import { Sdk } from './generated/sdk.gen';
129
130configureTRPCHeyApiClient(client, {
131 baseUrl: 'http://localhost:3000',
132});
133const sdk = new Sdk({ client });
134
135// Queries -> GET, Mutations -> POST
136const result = await sdk.greeting({ query: { input: { name: 'World' } } });
137const user = await sdk.user.create({ body: { name: 'Bob', age: 30 } });
138```
139
140## Core Patterns
141
142### CLI quick spec generation
143
144```bash
145# Default export name "AppRouter", output "openapi.json"
146pnpm exec trpc-openapi ./src/server/router.ts
147
148# Custom export name and output
149pnpm exec trpc-openapi ./src/server/router.ts -e appRouter -o api.json --title "My API" --version 1.0.0
150```
151
152### HeyAPI codegen with type resolvers (transformer setup)
153
154When the server uses a transformer, pass createTRPCHeyApiTypeResolvers() to the @hey-api/typescript plugin so generated types use Date instead of string for date-time fields and bigint for bigint fields:
155
156```ts
157import { createClient } from '@hey-api/openapi-ts';
158import { createTRPCHeyApiTypeResolvers } from '@trpc/openapi/heyapi';
159
160await createClient({
161 input: './openapi.json',
162 output: './generated',
163 plugins: [
164 {
165 name: '@hey-api/typescript',
166 '~resolvers': createTRPCHeyApiTypeResolvers(),
167 },
168 {
169 name: '@hey-api/sdk',
170 operations: { strategy: 'single' },
171 },
172 ],
173});
174```
175
176### Runtime client with superjson transformer
177
178When the tRPC server uses superjson, the client must be configured with the same transformer:
179
180```ts
181// src/shared/transformer.ts
182import superjson from 'superjson';
183
184export const transformer = superjson;
185```
186
187```ts
188// src/server/trpc.ts
189import { initTRPC } from '@trpc/server';
190import { transformer } from '../shared/transformer';
191
192const t = initTRPC.create({ transformer });
193export const router = t.router;
194export const publicProcedure = t.procedure;
195```
196
197```ts
198// src/client/index.ts
199import { configureTRPCHeyApiClient } from '@trpc/openapi/heyapi';
200import superjson from 'superjson';
201import { client } from './generated/client.gen';
202import { Sdk } from './generated/sdk.gen';
203
204configureTRPCHeyApiClient(client, {
205 baseUrl: 'http://localhost:3000',
206 transformer: superjson,
207});
208const sdk = new Sdk({ client });
209
210const event = await sdk.getEvent({
211 query: { input: { id: 'evt_1', at: new Date('2025-06-15T10:00:00Z') } },
212});
213// event.data.result.data.at is a Date object
214```
215
216### MongoDB EJSON transformer (cross-language)
217
218For non-TypeScript clients, EJSON provides a language-agnostic serialization format:
219
220```ts
221import type { TRPCDataTransformer } from '@trpc/server';
222import type { Document } from 'bson';
223import { EJSON } from 'bson';
224
225export const ejsonTransformer: TRPCDataTransformer = {
226 serialize: (value) => EJSON.serialize(value),
227 deserialize: (value) => EJSON.deserialize(value as Document),
228};
229```
230
231```ts
232import { configureTRPCHeyApiClient } from '@trpc/openapi/heyapi';
233import { client } from './generated/client.gen';
234import { ejsonTransformer } from './transformer';
235
236configureTRPCHeyApiClient(client, {
237 baseUrl: 'http://localhost:3000',
238 transformer: ejsonTransformer,
239});
240```
241
242### Response shape
243
244All tRPC HTTP responses follow the envelope format. Access data through result.data:
245
246```ts
247const listResult = await sdk.user.list();
248const users = listResult.data?.result.data; // the actual return value
249
250const createResult = await sdk.user.create({ body: { name: 'nick' } });
251const user = createResult.data?.result.data;
252// user.createdAt instanceof Date === true (when transformer is configured)
253```
254
255### Descriptions in the spec
256
257Zod .describe() calls and JSDoc comments on types, routers, and procedures become description fields in the generated OpenAPI spec. No annotations or decorators required.
258
259## Common Mistakes
260
261### Missing transformer config in HeyAPI client
262
263When the tRPC server uses superjson or another transformer, the generated HeyAPI client must also be configured with the same transformer via configureTRPCHeyApiClient(client, { transformer }). Without this, Date, Map, Set, and other non-JSON types will be silently wrong at runtime -- they arrive as raw serialized objects instead of their native types.
264
265Wrong:
266
267```ts
268configureTRPCHeyApiClient(client, {
269 baseUrl: 'http://localhost:3000',
270 // missing transformer -- Dates will be broken
271});
272```
273
274Right:
275
276```ts
277configureTRPCHeyApiClient(client, {
278 baseUrl: 'http://localhost:3000',
279 transformer: superjson, // must match server's transformer
280});
281```
282
283### Expecting subscriptions in OpenAPI spec
284
285Subscriptions are currently excluded from OpenAPI spec generation. The generator silently skips any procedure with type: 'subscription'. SSE subscription support is planned but not yet available.
286
287### Forgetting createTRPCHeyApiTypeResolvers when using a transformer
288
289Without the type resolvers plugin, HeyAPI generates string types for date-time fields instead of Date. The createTRPCHeyApiTypeResolvers() function maps date/date-time format to Date and bigint format to bigint in the generated TypeScript SDK.
290
291### Using the wrong export name
292
293The CLI defaults to --export AppRouter (the type). If your file exports the router value as appRouter, pass -e appRouter. If the export is not found, the error message lists all available exports from the file.
294
295## See Also
296
297- **server-setup** -- Required. Define routers and procedures before generating the spec.
298- **superjson** -- Transformer configuration for server and client. OpenAPI clients need matching transformer config.
299- **validators** -- Zod .describe() calls propagate into OpenAPI description fields.
300- Full working example: examples/openapi-codegen/
301
In the file
SKILL.md1,092 words
Files1
LicenceMIT
Why you can read it

Nothing in a skill executes. The client loads the text and the model follows it, so a skill can be audited the way a runbook is — by reading it.

What it costs in context

Skills are not billed by the call. They are paid for in context: every token the instructions occupy is a token your code, your diff and your conversation cannot use. Here is what this one takes and when it takes it.

≈130
always loaded
The name and description, so the model knows the skill exists and when to reach for it.
2,095
on trigger
The instruction body, read only when the skill fires.
1.1%
of a 200k window
Ten skills this size would take about 11% of the window before you open a file.
050k100k150k200k context window

2.2k tokens, estimated from the bundle at four bytes to the token, held for the rest of the session once it triggers. Middling. Fine to keep on in a project where you use it weekly, worth unloading in one where you never do.

Servers bill, skills cost

A server charges by the month. A skill charges once per session, in context, and then keeps charging it for as long as the session lives.

Before and after

The same question, put to the same model twice: once as it comes, and once with these instructions loaded.

No worked example has been published for this skill yet.

Adoption
Installsnone yet
Ratingno reviews yet

The procedure it runs

The procedure has not been published here. It is in the skill’s own SKILL.md, which its author has not sent to the marketplace yet.

Prose, not code

These steps are written for a model to follow, not executed by a runtime. It can still be told to skip one, and it will say so when it does.

Servers it uses

None. This skill calls no MCP servers at all.

Everything it needs is in the instructions, so it works in a project with nothing connected — the model reads the file and changes how it works with what it can already reach.

It writes no files and reaches no network. All it changes is how the model reasons and writes.

What it asks for
Writes filesno
Network accessno

Read from the allowed-tools line of this skill’s own SKILL.md. A skill grants no permissions of its own — it can only ask for tools your client already has.

What it will not do

Every skill is narrow, and the useful ones say where they stop. These are the jobs this one is the wrong tool for.

What this skill is not for has not been published here. Nothing is implied by that: it is a section the author has not filled in.

What is in the bundle

1 file, 8.9 kB on disk. A bundle is text throughout: the instructions the model reads, plus the templates it fills in.

  • SKILL.md8.9 kB
What is not in it

No dependencies and nothing executable: a skill is text the agent reads, so the bundle is 1 file you can review in full before installing. The MIT licence covers the templates and examples as well as the instructions.

Install

Installing copies the bundle into your project. Nothing runs at install time — the files sit on disk until the model reads them.

$39 once
tRPC OpenAPI · MIT · trpc
one-time
Price$39 once
LicenceMIT — the author’s, unchanged by this purchase
Paid throughStripe, once, on the card you add at the checkout
Keeps workingfor good — the files are yours once they are on disk
Updatesevery update its author ships, delivered through this account

You can read the whole bundle before paying — the SKILL.md above is the product, not a preview of it. What the money buys is the delivery: the folder packaged and handed to your machine by key, every update its author ships, and our support if it does not do what this listing says. The terms of use are MIT, set by the author and unchanged by buying it here.

Payment runs through Stripe, on a page like this one rather than a redirect. Once there is an account it joins the same mcprush invoice as everything else you run, so there is never a second card to enter.

Which clients pick it up on their own

A skill is a folder of text. A client with a skills folder reads it without being told; everywhere else the same text works, it is just handed to the model rather than found.

Claude Code.claude/skills/
Claude Desktop
ChatGPT
Cursor.cursor/skills/
VS Code.github/skills/
Codex CLI.agents/skills/
Gemini CLI.gemini/skills/
Grok.grok/skills/
Zed.agents/skills/
Windsurf.windsurf/skills/
Agent SDK.claude/skills/
HTTP / API
This release
Versionnot versioned
Publishedno release date on file
Price$39
Referencetrpc/trpc-openapi

Versions

Its author publishes no version number, so there is nothing here to pin to: what you install is the folder as it stands today. Instructions change more often than APIs do — a skill can be rewritten entirely without anything it depends on moving.

v
  • No earlier releases have been published to the marketplace.
Pinning

Nothing to pin to: this skill carries no version number of its own. What you install is what the folder holds on the day you install it.

Reviews

no reviews yet · no installs yet

Nobody has reviewed this skill yet. The rating is the mean of the reviews written here, so there is none until somebody writes the first.

Who can post

Only accounts that have had the skill installed for fourteen days, so a review is written after living with it rather than after reading it. Publishers may reply once.

Publisher
Servers0