plugins: [pluginKy()]OpenAPI to Ky client generator
@kubb/plugin-ky
Generates a type-safe Ky client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.
- GitHub stars12kubb-labs/plugins
- Unpacked size104.5kBv0.1.0 on npm
- Latest release12m agov0.1.0 · Nov 18, 2026
Generates one typed async function per OpenAPI operation that sends the request with Ky and returns a result keyed by status code.
Each function takes grouped path, query, headers, cookies, and body options, plus Ky options such as retry, timeout, and hooks. The query plugins and @kubb/plugin-mcp call these functions. The runtime is copied into .kubb/, so the generated code imports only ky.
Installation
kubb add plugin-kybun add -d @kubb/plugin-kypnpm add -D @kubb/plugin-kynpm install --save-dev @kubb/plugin-kyyarn add -D @kubb/plugin-kykubb add installs the version the Kubb registry pins and adds pluginKy() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.
Setup
- Add
@kubb/plugin-tsfor the operation types, or@kubb/plugin-zodwithinferred: true. - Add
@kubb/plugin-zodand installzodv4 when you setvalidator. Generation fails without the plugin. - Install
ky2.0 or a later 2.x release in the app that runs the generated code.
Options worth knowing
| Option | Set it to |
|---|---|
baseURL | The starting host. The spec's top-level servers URL is not used. |
validator | 'zod' to check response bodies, or { request, params, response } per part. |
throwOnErrorDefault | false to return non-2xx responses as values. |
returnType | 'data' to resolve to the success body instead of the full result. |
sdk | Classes instead of functions. Leave it unset for the query plugins and @kubb/plugin-mcp. |
Next, call operations, or see every option and its default in Options.
Example
import { defineConfig } from 'kubb/config'
import { adapterOas } from '@kubb/adapter-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginKy } from '@kubb/plugin-ky'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
adapter: adapterOas({ integerType: 'number' }),
plugins: [pluginTs(), pluginKy({ baseURL: 'https://petstore.swagger.io/v2' })],
})import { getPetById } from './gen/clients/getPetById'
const { data } = await getPetById({ path: { petId: 1 } })src/gen/
├── .kubb/ # the runtime: client.ts, core.ts, config.ts, serializers/, ...
├── clients/
│ ├── getPetById.ts
│ └── index.ts
└── types/With integerType: 'number', an int64 id such as petId is a number. With the default bigint, pass 1n.
Dependencies
No extension dependencies.
Optional dependencies
Extensions Ky works with when they are in the config.
