Installation
This page walks you through getting Kubb running in your project, from the first install to your first generated files. Pick the quick start if you want the wizard to set everything up for you, or follow the manual steps to see each piece.
Prerequisites
Before you start, make sure your machine has these two tools installed:
- 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 fastest way to start is the kubb init wizard. It detects your package manager, asks where your spec lives and where generated files should go, installs the plugins you pick, and writes a kubb.config.ts for you.
Run the wizard and answer its prompts:
npx kubb@beta initOnce the wizard finishes, generate your files:
npx kubb@beta generateThat is all you need to get started. If you would rather set things up by hand, the manual steps below walk through the same result one piece at a time.
Manual installation
Prefer to do it yourself? These five steps install Kubb, add the plugins you want, write a config, and run your first generation.
1. Install Kubb
Start by adding the kubb package as a dev dependency. Use the tab for your package manager:
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, so you install only what you need. The example below adds TypeScript types, an Axios client, and React Query hooks, but you can swap in any plugins from the table that follows:
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
Next, create a kubb.config.ts file in your project root. The config points Kubb at your spec and your output directory, and defineConfig wires up the OpenAPI adapter, the default parsers, and a barrel plugin for you. Here is a minimal starting point:
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
To save typing, add a generate script to your package.json so you can run generation with one command:
{
"scripts": {
"generate": "kubb generate"
}
}5. Generate
You are ready for the payoff. Run the script to generate your files:
npm run generateYour generated files appear under output.path. Re-run this command whenever your spec changes, and the output updates to match.
Nice work, your project is set up. 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.