Installation
Prerequisites
- Node.js 22 or higher (Download)
- TypeScript 4.7 or higher, if you use a
kubb.config.tsor import generated types
Quick start (recommended)
The kubb init wizard detects your package manager, asks where your spec lives and where generated files should go, lets you pick plugins, installs everything, and writes a kubb.config.ts.
npx kubb initThen run:
npx kubb generateManual installation
1. Install Kubb
bun add -d kubbpnpm add -D kubbnpm install --save-dev kubbyarn add -D kubbNOTE
The kubb package includes the CLI, the core runtime, the OpenAPI adapter, and the TypeScript parser by default. You only need to add plugins for the outputs you want.
2. Add plugins
Each output format is its own package. Install only what you need.
bun add -d @kubb/plugin-ts @kubb/plugin-client @kubb/plugin-react-querypnpm add -D @kubb/plugin-ts @kubb/plugin-client @kubb/plugin-react-querynpm install --save-dev @kubb/plugin-ts @kubb/plugin-client @kubb/plugin-react-queryyarn add -D @kubb/plugin-ts @kubb/plugin-client @kubb/plugin-react-query| Package | Generates |
|---|---|
@kubb/plugin-ts | TypeScript types and interfaces |
@kubb/plugin-client | HTTP client functions (Axios, Fetch, custom) |
@kubb/plugin-react-query | TanStack Query hooks for React |
@kubb/plugin-vue-query | TanStack Query hooks for Vue |
@kubb/plugin-zod | Zod schemas for runtime validation |
@kubb/plugin-faker | Faker.js mock data generators |
@kubb/plugin-msw | MSW request handlers |
@kubb/plugin-cypress | Cypress end-to-end tests |
@kubb/plugin-mcp | MCP server from your spec |
@kubb/plugin-redoc | Redoc API documentation |
See the plugins page for a complete list.
3. Create kubb.config.ts
The config points Kubb at your spec and your output directory. defineConfig applies the OpenAPI adapter automatically.
import { } from 'kubb'
import { } from '@kubb/plugin-ts'
export default ({
: '.',
: { : './petStore.yaml' },
: { : './src/gen', : true },
: [()],
})Kubb looks for kubb.config.ts (recommended) in the project root and the .config/ and configs/ subdirectories. JavaScript variants (.js, .mjs, .cjs) and TypeScript .mts/.cts are also supported.
TIP
Use --config <path> to point Kubb at a config file in a custom location.
4. Add a script
Add a generate script to package.json so generation is a single command:
{
"scripts": {
"generate": "kubb generate"
}
}5. Generate
npm run generateGenerated files appear under output.path. Re-run this command whenever your spec changes.
Continue to Basic Usage to write a full config with multiple plugins, or jump to Configuration for every available option. To run generation as part of your bundler see Integrations.