Introduction to Kubb: turn your API spec into code
Generate TypeScript types, Axios and Fetch clients, TanStack Query hooks, Zod schemas, and Faker and MSW mocks from an OpenAPI spec with Kubb.
Kubb turns an API spec into the code your app uses to call that API: types, clients, query hooks, validators, and mocks. You pick the outputs with plugins in one kubb.config.ts. When the spec changes, run Kubb again and the code follows.
Generate TypeScript types, Axios and Fetch clients, TanStack Query hooks, Zod schemas, and Faker and MSW mocks from an OpenAPI spec with Kubb.
What Kubb generates
| Output | Plugins |
|---|---|
| TypeScript types | plugin-ts |
| HTTP clients | plugin-axios, plugin-fetch |
| Query hooks | plugin-react-query, plugin-vue-query, plugin-swr |
| Validation schemas | plugin-zod |
| Mock data, request handlers, and tests | plugin-faker, plugin-msw, plugin-cypress |
| An MCP server for your API | plugin-mcp |
| API documentation | plugin-redoc |
The default OpenAPI adapter reads OpenAPI 2.0, 3.0, 3.1, and 3.2.
See it work
This config generates types and Zod schemas from petStore.yaml:
kubb.config.ts
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginZod } from '@kubb/plugin-zod'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
plugins: [pluginTs(), pluginZod()],
})The adapter turns the spec into AST nodes, and each plugin generates files from those nodes. How Kubb works explains each stage.
Start here
| You want to | Read |
|---|---|
| Learn by generating a client from a sample spec | Generate your first client |
| Add Kubb to your project | Installation |
| Set up a stack, such as React Query with Zod | Configure generation |
| Rename files or change generated code | Resolvers, macros, and printers |
| Generate during a build or in CI | Build tools and CI |
| Use Kubb from a browser or an AI assistant | Studio and AI assistants |
| Build a plugin | Create a plugin |
| Look up an option, command, or API | Configuration, commands, and Kit API |
| Understand the pipeline | How Kubb works |
| Compare Kubb with other generators | Comparison |
| Upgrade from v4 | Migration guide |
Community
Kubb is free and open source under the MIT license. Ask on Discord, report bugs on GitHub, or read the FAQ.
