plugins: [pluginClient()]Client
@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.
- Downloads469.3K/ monthnpm, last 30 days
- GitHub stars8kubb-labs/plugins
- Unpacked size303.7kBv5.5.9 on npm
- Latest release9h agov5.5.9 · Oct 13, 2026
The Client plugin turns each operation in your OpenAPI spec into a typed function that calls a client module you write. The generated code has no Fetch, axios, or Kubb runtime dependency.
Each function takes grouped path, query, headers, and body parameters and passes the operation's auth requirements to your client in a security list. A single call can pass its own client to replace the default. For a ready-made client, or to use the query plugins or @kubb/plugin-mcp, use @kubb/plugin-fetch or @kubb/plugin-axios instead.
Installation
bun add -d @kubb/plugin-clientpnpm add -D @kubb/plugin-clientnpm install --save-dev @kubb/plugin-clientyarn add -D @kubb/plugin-clientOr run kubb add plugin-client to install the version the Kubb registry pins and add pluginClient() to kubb.config.ts.
Setup
- Set the required
importPathoption to your client module. The module must exportclientand theOptionsandRequestResulttypes. When the spec has server-sent event operations, it must also exporttoEventStreamand theEventStreamResultandSuccessOftypes. - Add
@kubb/plugin-tsfor the operation types, or@kubb/plugin-zodwithinferred: true. - Add
@kubb/plugin-zodwhen you setvalidator, and installzodv4. Generation fails without the plugin.
Options worth knowing
importPathis written into every generated import as given, so it must resolve from the generated file. A relative path, a package name, or an alias works.validator: 'zod'passes response schemas from@kubb/plugin-zodto your client. Use{ request: 'zod', response: 'zod' }to also pass request body schemas.throwOnErrorDefaultis thethrowOnErrorvalue each call passes to your client. The default istrue.
See Options for every option and its default.
Example
The config below groups the generated functions by tag and points them at the client module in src/client.ts.
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginClient } from '@kubb/plugin-client'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
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
Extensions that must be in the same config as Client.