openapi-ts-client

Generate typed TypeScript clients, TanStack Query hooks, and Zod schemas from OpenAPI 3.1 contracts.

1|1|Updated May 24, 2026
One-click install
npx skills add https://github.com/bm629/agent-skills --skill openapi-ts-client-bm629
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: openapi-ts-client
Source: https://github.com/bm629/agent-skills/tree/main/skills/openapi-ts-client
Command: npx skills add https://github.com/bm629/agent-skills --skill openapi-ts-client-bm629

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @hey-api/openapi-ts, and includes references (resource) components.

What problem does it solve? Hand-written API clients drift out of sync with the backend the moment the contract changes. This Skill generates a fully typed TypeScript client directly from an OpenAPI 3.1 spec (such as a FastAPI /openapi.json), so the frontend always matches the API without manual maintenance. ## Core Features & Use Cases - Typed SDK Generation: Produces typed models and one async function per operation using @hey-api/openapi-ts, with a { data, error } result style and optional throwOnError. - Plugin Ecosystem: Generates TanStack Query hooks (Options, QueryKey, Mutation helpers) and Zod request/response schemas from the same contract. - Regeneration Workflow: Covers the openapi-ts.config.ts setup, fetch/axios/Next.js client selection, the FastAPI operationId naming fix, and a CI drift check that fails when the committed client goes stale. - Use Case: You have a FastAPI backend and a React frontend. Point the generator at http://localhost:8000/openapi.json, run the gen:api script, and immediately call typed SDK functions and spread generated query options into useQuery. ## Quick Start Generate a typed TypeScript client from my FastAPI server's /openapi.json endpoint using @hey-api/openapi-ts with TanStack Query hooks and Zod schemas enabled.

Frequently Asked Questions about openapi-ts-client

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate a TypeScript client from an OpenAPI spec?

Install @hey-api/openapi-ts as a dev dependency, create an openapi-ts.config.ts with your spec URL or file path as input and an output directory, then run the openapi-ts command via a package.json script. It emits typed models and one typed function per operation.

How to generate TanStack Query hooks from an OpenAPI spec?

Add the framework-specific plugin string such as @tanstack/react-query to the plugins array in openapi-ts.config.ts. The generator emits Options, QueryKey, InfiniteOptions, and Mutation helpers per operation that you spread into useQuery or useMutation.

Does @hey-api/openapi-ts work with FastAPI?

Yes, FastAPI's own documentation recommends @hey-api/openapi-ts for TypeScript clients. FastAPI 0.99 and later emits OpenAPI 3.1, which is exactly what hey-api targets; point the input at the running app's /openapi.json endpoint.

Why do my generated FastAPI client methods have ugly names like createItemItemsPost?

FastAPI builds verbose default operationIds, which become method names. Fix it on the backend by setting generate_unique_id_function on the FastAPI app to produce tag-name style operationIds, so every regeneration yields clean names.

Should I commit the generated API client or gitignore it?

Both are valid. Committing makes API changes reviewable in diffs and removes the codegen build step, but requires a CI drift check (regenerate then git diff --exit-code) to prevent staleness. Gitignoring avoids churn but every environment must run codegen first.

When should I not use @hey-api/openapi-ts?

Avoid it when you only need TanStack Query usage patterns like caching and invalidation, when you are authoring the backend or OpenAPI spec itself, or when you are locked to an OpenAPI 3.0-only workflow requiring a 3.0-specialized tool.