plugins: [pluginFetch()]Fetch
@kubb/plugin-fetch
Generates a type-safe Fetch API client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.
- Downloads83.6K/ monthnpm, last 30 days
- GitHub stars8kubb-labs/plugins
- Unpacked size487.1kBv5.5.11 on npm
- Latest release9h agov5.5.11 · Oct 13, 2026
The Fetch plugin turns each operation in your OpenAPI spec into a typed async function that sends the request with the native Fetch API. Each function takes grouped path, query, headers, and body parameters and returns a result keyed by status code.
The query plugins (@kubb/plugin-react-query, @kubb/plugin-vue-query, and @kubb/plugin-swr) and @kubb/plugin-mcp call these functions. The plugin also copies its runtime files (client.ts, serializers.ts, and standardSchema.ts) to .kubb/ in the root output folder.
Installation
bun add -d @kubb/plugin-fetchpnpm add -D @kubb/plugin-fetchnpm install --save-dev @kubb/plugin-fetchyarn add -D @kubb/plugin-fetchOr run kubb add plugin-fetch to install the version the Kubb registry pins and add pluginFetch() to kubb.config.ts.
Setup
- Add
@kubb/plugin-tsfor the operation types, or@kubb/plugin-zodwithinferred: true. - Add
@kubb/plugin-zodwhen you setvalidator, and installzodv4. Without the plugin,validatordoes nothing. - No HTTP client package is needed. The generated code calls the global
fetch.
Options worth knowing
baseURLis prepended to every request. The spec'sserversURL is not used, so withoutbaseURLyou set one at runtime withclient.setConfig({ baseURL }).validator: 'zod'validates response bodies with the schemas from@kubb/plugin-zod. Use{ request: 'zod', response: 'zod' }to also validate request bodies.throwOnErrorDefault: falsereturns non-2xx responses as values instead of throwing. A single call can still passthrowOnError.returnType: 'data'makes a call resolve to the success body instead of the full result. WiththrowOnError: false, the call still returns the full result.sdkgenerates a class-based SDK, grouped by tag or flat, instead of standalone functions. The query plugins and@kubb/plugin-mcpneed the standalone functions, so leavesdkunset when you use them.
See Options for every option and its default.
Example
The config below generates a Fetch client that sends every request to the Petstore API.
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginFetch } from '@kubb/plugin-fetch'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
plugins: [
pluginTs(),
pluginFetch({ baseURL: 'https://petstore.swagger.io/v2' }),
],
})Dependencies
Extensions that must be in the same config as Fetch.