explaingit

sindresorhus/ky

Analysis updated 2026-06-24

16,849TypeScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

Small JavaScript/TypeScript library that wraps the browser's fetch API to make HTTP requests cleaner, handles JSON serialization, error throwing, retries, timeouts, and upload/download progress automatically.

Mindmap

mindmap
  root((ky))
    What it does
      Wraps fetch API
      Handles JSON
      Auto-retries
      Timeout support
    Tech stack
      TypeScript
      JavaScript
      Fetch API
    Use cases
      Browser HTTP calls
      Node Bun Deno scripts
      Schema validation
      Progress tracking
    Audience
      Web developers
      TypeScript users
      API consumers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Make API calls from a browser or Node.js/Bun/Deno app without writing boilerplate fetch code each time

USE CASE 2

Retry failed HTTP requests automatically with a single configuration option on a ky instance

USE CASE 3

Validate API responses against a Zod or Valibot schema right when you parse the JSON response

USE CASE 4

Share a base URL and default headers across all requests by creating a named ky instance

What is it built with?

TypeScriptJavaScriptFetch API

How does it compare?

sindresorhus/kylyswhut/lx-music-mobilegraphql/graphiql
Stars16,84916,84016,827
LanguageTypeScriptTypeScriptTypeScript
Setup difficultyeasymoderatemoderate
Complexity2/53/53/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

In plain English

Ky is a small JavaScript library for making HTTP requests, the kind of calls a web app or script makes to fetch data from an API or send data to a server. It is built on top of the Fetch API, which is the modern, browser-native way to do this, and it works in modern browsers as well as in the Node.js, Bun, and Deno server runtimes. The whole package has no dependencies of its own, so adding it does not pull in a tree of extra code. The point of Ky is to smooth over the rough edges of plain fetch. With raw fetch, you have to write boilerplate every time: set headers, serialize JSON yourself, check the response status, and throw your own error class. Ky wraps all of that into a friendlier shape. There are method shortcuts like ky.post and ky.get, a json option that handles serialization and the correct header automatically, and any response outside the 200-299 success range is treated as an error and thrown for you. It also retries failed requests, supports timeouts, exposes upload and download progress, lets you set a base URL for an instance, and offers hooks for customizing behavior at various points in a request. Responses can be validated against a Standard Schema (with libraries like Zod or Valibot) directly when you call .json(), and the TypeScript types are sharper than fetch's, for instance.json() defaults to unknown instead of any. You would reach for Ky whenever you need to talk to an HTTP API from JavaScript or TypeScript and want a cleaner experience than raw fetch without committing to a heavier client. It is written in TypeScript and installed via npm, or imported from a CDN for Deno. The full README is longer than what was provided.

Copy-paste prompts

Prompt 1
Using the ky library, write a TypeScript function that fetches paginated JSON from /api/items, retries up to 3 times on failure, and validates the response with a Zod schema using .json().
Prompt 2
I'm migrating from axios to ky in a Node.js project. Show me how to create a ky instance with a base URL, attach an Authorization header to every request, and handle 4xx responses with a custom error message.
Prompt 3
How do I track upload progress when posting a file with ky in the browser? Show a working example that updates a progress bar using ky's upload progress hook.
Prompt 4
Write a ky instance that reads a Bearer token from localStorage, sets a 10-second timeout on all requests, and uses an afterResponse hook to refresh the token on a 401 response.

Frequently asked questions

What is ky?

Small JavaScript/TypeScript library that wraps the browser's fetch API to make HTTP requests cleaner, handles JSON serialization, error throwing, retries, timeouts, and upload/download progress automatically.

What language is ky written in?

Mainly TypeScript. The stack also includes TypeScript, JavaScript, Fetch API.

How hard is ky to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is ky for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.