Skip to content
Plugin
Client logo
plugins: [pluginClient()]
Officialv6.2.0kubb >=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
api-clienthttp-clientcodegenopenapi

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.