Skip to content
Plugin
Axios logo
plugins: [pluginAxios()]
Officialv6.0.4kubb >=5.19.0node >=22.22

OpenAPI to Axios client generator

@kubb/plugin-axios

Generates a type-safe axios client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.

kubb add plugin-axios
api-clientaxioshttp-clientcodegenopenapivalidator

Generates one typed async function per OpenAPI operation that sends the request with axios and returns a result keyed by status code.

Each function takes grouped path, query, headers, cookies, and body options. The query plugins and @kubb/plugin-mcp call these functions. The runtime is copied into .kubb/, so the generated code imports only axios.

Installation

kubb add plugin-axios

kubb add installs the version the Kubb registry pins and adds pluginAxios() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.

Setup

  • Add @kubb/plugin-ts for the operation types, or @kubb/plugin-zod with inferred: true.
  • Add @kubb/plugin-zod and install zod v4 when you set validator. Generation fails without the plugin.
  • Install axios 1.20 or a later 1.x release in the app that runs the generated code.

Options worth knowing

OptionSet it to
baseURLThe starting host. The spec's top-level servers URL is not used.
validator'zod' to check response bodies, or { request, params, response } per part.
throwOnErrorDefaultfalse to return non-2xx responses as values.
returnType'data' to resolve to the success body instead of the full result.
sdkClasses 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 { pluginAxios } from '@kubb/plugin-axios'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  adapter: adapterOas({ integerType: 'number' }),
  plugins: [pluginTs(), pluginAxios({ baseURL: 'https://petstore.swagger.io/v2' })],
})

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 Axios works with when they are in the config.