Type-safe fetch client for OpenAPI schemas, version 0.17.0. Maintained actively on GitHub (openapi-ts/openapi-typescript) with frequent releases. Weighs 6 kB (minified) and has virtually zero runtime overhead. Differs from alternatives like axios or openapi-typescript-codegen by providing automatic type inference from generated TypeScript types, eliminating manual type assertions and reducing bundle size. Works with any framework or vanilla JS, and integrates with openapi-typescript for schema-to-TypeScript generation. Supports GET, PUT, POST, DELETE, OPTIONS, HEAD, PATCH, TRACE methods. ESM-only; no CJS support.
npm install openapi-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows client creation with type parameter from generated schema and a typed GET request with path parameters, handling data and error responses.
Use import syntax or dynamic import(). If using CommonJS project, switch to ESM or use dynamic import.
Use default import: import createClient from 'openapi-fetch';
Install openapi-typescript as dev dependency and run: npx openapi-typescript ./path/to/schema.yaml -o ./types.ts
Pass custom fetch as part of options object: createClient<paths>({ baseUrl, fetch: myFetch })Replace import { createClient } with import createClient.Switch to ESM (type: "module" in package.json) or use dynamic import: const createClient = (await import('openapi-fetch')).default;Run npx openapi-typescript on your OpenAPI schema and import the resulting .d.ts file.