Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
Skip to content

Installation

Prerequisites

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.

Terminal
shell
npx kubb@beta init

Then run:

Terminal
shell
npx kubb@beta generate

Manual installation

1. Install Kubb

shell
bun add -d kubb@beta
shell
pnpm add -D kubb@beta
shell
npm install --save-dev kubb@beta
shell
yarn add -D kubb@beta

NOTE

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.

shell
bun add -d @kubb/plugin-ts@beta @kubb/plugin-axios@beta @kubb/plugin-react-query@beta
shell
pnpm add -D @kubb/plugin-ts@beta @kubb/plugin-axios@beta @kubb/plugin-react-query@beta
shell
npm install --save-dev @kubb/plugin-ts@beta @kubb/plugin-axios@beta @kubb/plugin-react-query@beta
shell
yarn 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.

kubb.config.ts
typescript
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.

package.json
json
{
  "scripts": {
    "generate": "kubb generate"
  }
}

5. Generate

Terminal
shell
npm run generate

Generated 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.