{"id":48841,"library":"openapi-fetch","title":"openapi-fetch","description":"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.","status":"active","version":"0.17.0","language":"javascript","source_language":"en","source_url":"https://github.com/openapi-ts/openapi-typescript","tags":["javascript","openapi","swagger","rest","api","oapi_3","oapi_3_1","typescript","fetch"],"install":[{"cmd":"npm install openapi-fetch","lang":"bash","label":"npm"},{"cmd":"yarn add openapi-fetch","lang":"bash","label":"yarn"},{"cmd":"pnpm add openapi-fetch","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to generate TypeScript types from an OpenAPI schema; openapi-fetch consumes these types for type safety.","package":"openapi-typescript","optional":true}],"imports":[{"note":"Package is ESM-only (since first release); CommonJS require() will fail.","wrong":"const createClient = require(\"openapi-fetch\");","symbol":"default","correct":"import createClient from \"openapi-fetch\";"},{"note":"createClient is the default export; named import will be undefined.","wrong":"import { createClient } from \"openapi-fetch\";","symbol":"createClient","correct":"import createClient from \"openapi-fetch\";"},{"note":"Use 'import type' to avoid bundling runtime artifacts; paths is a type-only export from openapi-typescript-generated files.","wrong":"import { paths } from \"./my-schema\";","symbol":"type paths","correct":"import type { paths } from \"./my-schema\";"}],"quickstart":{"code":"import createClient from \"openapi-fetch\";\nimport type { paths } from \"./api-schema\"; // generated by openapi-typescript\n\nconst client = createClient<paths>({\n  baseUrl: \"https://api.example.com/v1\",\n});\n\nasync function getPost(id: string) {\n  const { data, error } = await client.GET(\"/posts/{postId}\", {\n    params: {\n      path: { postId: id },\n    },\n  });\n  if (error) {\n    console.error(\"Error:\", error);\n    return;\n  }\n  console.log(\"Post:\", data);\n}","lang":"typescript","description":"Shows client creation with type parameter from generated schema and a typed GET request with path parameters, handling data and error responses."},"warnings":[{"fix":"Use import syntax or dynamic import(). If using CommonJS project, switch to ESM or use dynamic import.","message":"Package is ESM-only. Using require() will throw a runtime error.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Use default import: import createClient from 'openapi-fetch';","message":"Default export named createClient; named import { createClient } is undefined.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Install openapi-typescript as dev dependency and run: npx openapi-typescript ./path/to/schema.yaml -o ./types.ts","message":"Must generate TypeScript types from OpenAPI schema using openapi-typescript before using openapi-fetch; otherwise type safety is lost.","severity":"gotcha","affected_versions":">0"},{"fix":"Pass custom fetch as part of options object: createClient<paths>({ baseUrl, fetch: myFetch })","message":"In version <0.6, createClient accepted a second generic parameter for custom fetch; now use the 'fetch' option in the config object.","severity":"deprecated","affected_versions":"<0.6"}],"env_vars":null,"search_vec":"'/openapi-typescript':21 '0.17.0':13 '1':106 '3':103,105 '6':26 'activ':15 'altern':37 'api':101 'assert':57 'automat':47 'axio':39 'bundl':60 'cjs':95 'client':8 'codegen':44 'delet':85 'differ':35 'elimin':54 'esm':92 'esm-on':91 'fetch':3,7,108 'framework':65 'frequent':23 'generat':51,80 'get':82 'github':17 'head':87 'infer':49 'integr':70 'javascript':97 'js':68 'kb':27 'like':38 'maintain':14 'manual':55 'method':90 'minifi':28 'oapi':102,104 'openapi':2,10,19,42,73,98 'openapi-fetch':1 'openapi-t':18 'openapi-typescript':72 'openapi-typescript-codegen':41 'option':86 'overhead':34 'patch':88 'post':84 'provid':46 'put':83 'reduc':59 'releas':24 'rest':100 'runtim':33 'safe':6 'schema':11,77 'schema-to-typescript':76 'size':61 'support':81,96 'swagger':99 'trace':89 'ts':20 'type':5,48,53,56 'type-saf':4 'typescript':43,52,74,79,107 'vanilla':67 'version':12 'virtual':31 'weigh':25 'work':62 'zero':32","created_at":"2026-06-07T16:58:44.814623+00:00","updated_at":"2026-06-07T16:58:44.814623+00:00","problems":[{"fix":"Replace import { createClient } with import createClient.","cause":"Using named import { createClient } instead of default import.","error":"Error: createClient is not a function"},{"fix":"Switch to ESM (type: \"module\" in package.json) or use dynamic import: const createClient = (await import('openapi-fetch')).default;","cause":"Using require() in a CommonJS environment; package is ESM-only.","error":"TypeError: Cannot find module 'openapi-fetch'"},{"fix":"Run npx openapi-typescript on your OpenAPI schema and import the resulting .d.ts file.","cause":"paths type not generated or incorrectly typed; likely missing openapi-typescript step or incorrect schema path.","error":"Type 'string' is not assignable to type 'never'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://openapi-ts.dev","github":"https://github.com/openapi-ts/openapi-typescript","docs":null,"changelog":null,"pypi":null,"npm":"openapi-fetch","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}