Skip to content
Reference

Options

Configuration options for @kubb/plugin-axios.

Pass these options to pluginAxios(). Shared options link to Shared plugin options, which documents their behavior once.

Options overview

OptionPurposeDefault
outputWhere the generated files are written and exported.{ path: 'clients', barrel: { type: 'named' } }
↳ output.pathChoose the output folder or file.'clients'
↳ output.modeWrite a single file or a directory of files.Inferred from output.path
↳ output.barrelConfigure barrel exports.{ type: 'named' }
↳ output.bannerAdd content before generated code.None
↳ output.footerAdd content after generated code.None
groupSplit output into per-tag or per-path folders.None
↳ group.typeGroup operations by tag or URL path.Required with group
↳ group.nameCustomize output group names.camelCased tag or raw path segment
baseURLBase URL prepended to every request.None
throwOnErrorDefaultDefault error behavior and return type for generated operations.true
validatorValidate request and response bodies with Zod.false
↳ validator.requestValidate request bodies with Zod.None
↳ validator.responseValidate response bodies with Zod.None
commentsHow much of each description reaches the JSDoc.'full'
sdkEmit a class-based SDK instead of standalone functions.None
↳ sdk.modeGenerate one SDK class per tag or a flat SDK.'tag'
↳ sdk.nameName the composed or flat SDK class.None
returnTypeShape of the value a generated call resolves to.'full'
includeKeep only operations that match.None
excludeSkip operations that match.[]
overrideApply different options per pattern.[]
resolverCustomize generated names and file paths.resolverClient
macrosRewrite AST nodes before printing.[], run after the built-in client macros

Option details

baseURL

Base URL prepended to every request. When omitted, no host is prepended and each request uses the operation's relative path from the spec, with no server-URL fallback. A value containing a ${...} interpolation is emitted as a template literal, so baseURL: '${process.env.API_URL}' reads the environment variable at runtime.

Typestring
Requiredfalse

throwOnErrorDefault

Set throwOnErrorDefault: false to return documented error responses as values by default. This sets the fallback on each generated request and the default ThrowOnError type parameter on standalone functions and SDK methods. A call with throwOnError: true still throws for a non-2xx response and narrows its return type to successful responses.

Typeboolean
Requiredfalse
Defaulttrue
// pluginAxios({ throwOnErrorDefault: false }) or pluginFetch({ throwOnErrorDefault: false })
const result = await getPetById({ path: { petId: 1 } })
if (result.error) console.error(result.error)

This setting applies to the whole plugin and cannot be set in override. Pass throwOnError on a call to override it. Query hooks continue to set throwOnError: true explicitly.

validator

Validates request and response bodies using schemas from @kubb/plugin-zod. Add pluginZod() when either direction uses 'zod'. Invalid bodies cause the generated function to throw a ParseError.

Typefalse | 'zod' | { request?: 'zod'; response?: 'zod' }
Requiredfalse
Defaultfalse
false
Default value. Skips validation and casts the response to the generated type.
'zod'
Validates the success response body and, when a non-2xx call does not throw, the error body.
{ request?: 'zod', response?: 'zod' }
Enables validation separately for requests and responses.
kubb.config.ts
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginZod } from '@kubb/plugin-zod'
import { pluginAxios } from '@kubb/plugin-axios'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [
    pluginTs(),
    pluginZod(),
    pluginAxios({ validator: { request: 'zod', response: 'zod' } }),
  ],
})

comments

Controls generated JSDoc.

Type'full' | 'brief' | 'none'
Requiredfalse
Default'full'
'full'
Default value. Keeps complete descriptions and tags.
'brief'
Keeps the first sentence and other tags. Descriptions over 150 characters without a sentence ending are cut at the last word before 120.
'none'
Omits JSDoc but keeps the generated-by banner.

sdk

Generates a class-based SDK. Each instance receives a client configuration, so environments can use separate clients. Leave sdk unset to keep the standalone functions used by query plugins.

Type{ mode?: 'tag' | 'flat'; name?: string }
Requiredfalse
'tag'
Default value for sdk.mode. Generates one class per tag, such as PetClient and StoreClient. Set sdk.name to also generate a root class that instantiates the tag clients from one shared configuration, used as new PetStore(config).pet.getPetById(...).
'flat'
Generates a single class named by sdk.name, with every operation as a direct method. Supports single-file output.

mode: 'tag' needs one file per tag, so pairing it with a single-file output (output.mode: 'file', or an output.path that already names a file such as 'clients.ts') throws KUBB_INVALID_PLUGIN_OPTIONS. Use mode: 'flat' for a single-file SDK, or give output.path a directory so mode: 'tag' can split per tag.

Construct a class with a ClientConfig (baseURL, headers, and so on), then call a method with the grouped options object ({ path, query, headers, body }). Each call resolves to { status, data, error, contentType, request, response }. With the default throwOnErrorDefault: true, a resolved call means the request succeeded and data is set. Pass throwOnError: false to get the discriminated union instead, keyed on the top-level status:

import { PetClient } from './src/gen/clients/petClient'

const pet = new PetClient({ baseURL: 'https://petstore.swagger.io/v2' })
const { status, data, error } = await pet.getPetById({ path: { petId: 1 }, throwOnError: false })

if (status === 200) {
  console.log(data) // data is the success body, error is undefined
} else {
  console.error(status, error) // status is the documented error code, error is its parsed body
}

returnType

Shape of the value a generated call resolves to.

Type'full' | 'data'
Requiredfalse
Default'full'
'full'
Default value. Returns { status, data, error, contentType, request, response }.
'data'
Returns the success body when throwOnError is true. With throwOnError: false, returns the full result so callers can distinguish errors from successful responses.
pluginAxios({ returnType: 'data' })

const pet = await getPetById({ path: { petId: 1 } }) // Pet, not { status, data, ... }

This applies to the standalone functions and the class-based SDK. @kubb/plugin-react-query, @kubb/plugin-vue-query, @kubb/plugin-swr, and @kubb/plugin-mcp read the same option, so their hooks and tool handlers give you the success body as data either way. They also honor a per-operation returnType set through override.

To read response headers such as ETag under 'data', pass throwOnError: false on the call. It then resolves to the full result, and a non-2xx comes back on error instead of throwing:

const result = await getPetById({ path: { petId: 1 }, throwOnError: false })

if (result.error === undefined) {
  const etag = result.response.headers.etag
}

resolver

Overrides generated file and symbol names. Omitted members keep resolverClient. The shared members (name, file, imports) and the this context are described under resolver.

TypeResolverPatch<ResolverClient>
Requiredfalse
Partial override
type ResolverClientPatch = {
  name?(name: string): string
  file?: {
    baseName?(params: { name: string; extname: string }): string
    path?(params: { baseName: string; output: Output }): string
  }
  imports?(options: ResolveImportsOptions): Array<ImportNode>
  className?(name: string): string
  groupName?(name: string): string     // → 'PetClient'
  propertyName?(name: string): string
}