Skip to content

Point at an env-driven host

Set baseURL to a value with a ${...} interpolation, which Kubb emits as a template literal in the generated client config so it reads the environment variable at runtime.

kubb.config.ts
typescript
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', clean: true },
  plugins: [
    pluginTs(),
    pluginFetch({
      baseURL: '${process.env.API_URL}',
    }),
  ],
})

Output example

The template literal above reads process.env.API_URL at runtime rather than substituting it at build time:

usage.ts
typescript
import { getPetById } from './src/gen/clients/getPetById'

const { data } = await getPetById({ path: { petId: 1 } })