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. It asks where your spec lives and where generated files should go. Then it installs the plugins you pick and writes a kubb.config.ts.
npx kubb@beta initThen run:
npx kubb@beta generateManual installation
1. Install Kubb
bun add -d kubb@betapnpm add -D kubb@betanpm install --save-dev kubb@betayarn add -D kubb@betaNOTE
The kubb package includes the CLI, the core runtime, the OpenAPI adapter, and the TypeScript, TSX, and Markdown parsers 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@beta @kubb/plugin-axios@beta @kubb/plugin-react-query@betapnpm add -D @kubb/plugin-ts@beta @kubb/plugin-axios@beta @kubb/plugin-react-query@betanpm install --save-dev @kubb/plugin-ts@beta @kubb/plugin-axios@beta @kubb/plugin-react-query@betayarn add -D @kubb/plugin-ts@beta @kubb/plugin-axios@beta @kubb/plugin-react-query@beta| Package | Generates |
|---|---|
@kubb/plugin-ts | TypeScript types and interfaces |
@kubb/plugin-axios | Axios HTTP client functions |
@kubb/plugin-fetch | Fetch HTTP client functions |
@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 wires up the OpenAPI adapter, the default parsers, and a barrel plugin for you.
import { } from 'kubb'
import { } from '@kubb/plugin-ts'
export default ({
: '.',
: { : './petStore.yaml' },
: { : './src/gen', : true },
: [()],
})Kubb looks for kubb.config.ts in the project root and the .config/ and configs/ subdirectories. JavaScript variants (.js, .mjs, .cjs) and TypeScript .mts/.cts also work.
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 you run generation with one 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. Jump to Configuration for every option. To run generation from your bundler, see Integrations.