Skip to content
Plugin
Client logo
plugins: [pluginClient()]
Officialv6.7.2kubb >=5.19.0node >=22.22

OpenAPI to TypeScript API client generator

@kubb/plugin-client

Generates typed operation functions from your OpenAPI spec that call a client module you own, so you decide the transport, auth, and error handling.

kubb add plugin-client
Repositorynpmx

Stijn Van Hulle

@stijnvanhulle

api-clienthttp-clientcodegenopenapi
  • Downloads
    650.4K/ monthnpm, last 30 days
  • GitHub stars
    15kubb-labs/plugins
  • Unpacked size
    827.1kBv6.7.2 on npm
  • Latest release
    3d agov6.7.2 · Nov 26, 2026

The Client plugin turns each OpenAPI operation into a typed function that calls your own client module, with no Fetch, axios, or Kubb runtime dependency.

  • Each function takes grouped path, query, headers, cookies, and body parameters, and passes your client the operation's auth requirements as security.
  • A call can pass its own client to replace the default.
  • The query plugins and @kubb/plugin-mcp can call the generated functions.
  • For a ready-made client, use @kubb/plugin-fetch, @kubb/plugin-axios, or @kubb/plugin-ky instead.

Installation

kubb add plugin-client

kubb add installs the version the Kubb registry pins and adds pluginClient() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.

Setup

  • Set the required importPath to your client module.
  • Add @kubb/plugin-ts for the operation types, or @kubb/plugin-zod with inferred: true.
  • When you set validator, add @kubb/plugin-zod and install zod v4. Generation fails without the plugin.

Options worth knowing

OptionWhat it does
importPathYour client module, resolved from each generated file.
returnType'plain' returns what your client returns. 'full' adds .unwrap(). 'data' resolves to the body.
validatorPasses Zod schemas to your client.
throwOnErrorDefaultThe throwOnError value each call passes. Defaults to true.

See Options for every option. Next, write your client.

Example

This config groups the functions by tag and points them at src/client.ts.

kubb.config.ts
import { defineConfig } from 'kubb/config'
import { adapterOas } from '@kubb/adapter-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginClient } from '@kubb/plugin-client'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  adapter: adapterOas({ integerType: 'number' }),
  plugins: [
    pluginTs(),
    pluginClient({
      output: { path: 'clients', mode: 'directory', barrel: { type: 'named' } },
      group: { type: 'tag' },
      // resolved from each generated file: src/gen/clients/<tag>/ to src/client.ts
      importPath: '../../../client',
    }),
  ],
})

Dependencies

No extension dependencies.

Optional dependencies

Extensions Client works with when they are in the config.

TypeScript logo
TypeScript
@kubb/plugin-tsGenerates TypeScript types and interfaces from your OpenAPI spec, the typed foundation the other Kubb plugins build on.
Zod logo
Zod
@kubb/plugin-zodGenerates Zod v4 schemas from your OpenAPI spec so you validate API responses, form input, and query params at runtime.