Ky is a lightweight HTTP client library for JavaScript built on top of the Fetch API, designed to provide a simpler and more elegant alternative to using fetch directly. The repository, maintained by Sindre Sorhus, targets modern browsers, Node.js, Bun, and Deno environments. As a zero-dependency package, Ky offers a minimal footprint while adding substantial convenience features that extend the native fetch functionality.
The library provides several key advantages over plain fetch usage. It includes method shortcuts like ky.post(), ky.get(), and other HTTP verbs for cleaner syntax. Ky treats non-2xx status codes as errors after redirects, providing more intuitive error handling. The package includes built-in retry logic for failed requests, timeout support, and progress tracking for both uploads and downloads. Additional features include a base URL option for relative requests, the ability to create instances with custom defaults, hooks for request and response interception, and response validation using Standard Schema compatible validators like Zod and Valibot. For TypeScript users, Ky provides enhanced type safety with features like generic support for the .json() method and defaults to unknown rather than any.
The API closely mirrors the standard fetch interface, accepting the same input and options parameters while adding Ky-specific enhancements. The library provides convenient body method shortcuts including .json(), .text(), .formData(), .arrayBuffer(), .blob(), and .bytes(). A notable feature is that these body methods throw HTTPError if the response status falls outside the 200-299 range, and .json() specifically throws when the body is empty or the status is 204. The searchParams option allows flexible query string handling, accepting strings, objects, arrays, or URLSearchParams instances. The retry configuration is highly customizable, with defaults that retry up to twice on specific status codes like 408, 429, 500, 502, 503, and 504, with exponential backoff and support for Retry-After headers.
Ky is available through multiple CDN options including jsDelivr, unpkg, and esm.sh, making it accessible for various deployment scenarios. The project is actively maintained with documentation covering both the current stable version and upcoming features, reflecting ongoing development and community support.