Open-source project
unsplash/unsplash-js avatar
unsplash/unsplash-js

unsplash-js 8: a thin openapi-fetch client where every call is a verb and a path

🤖 Official JavaScript wrapper for the Unsplash API

2,195 stars161 forksTypeScriptMIT

At a glance

What is it?
unsplash-js wraps the Unsplash API with typed GET and POST calls generated from an OpenAPI spec. Browser use needs your own proxy, and OAuth is left to you.
Who is it for?
Use unsplash-js if you call the Unsplash API from Node or through your own proxy and want types generated from the OpenAPI spec. Do not use it for a backend-less browser app, or if you need ready-made OAuth handling.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 51 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 26, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • unsplash/unsplash-js2,195 ★ · +1
Star history
Repository2026-10-082026-11-26
unsplash/unsplash-js2.2k2.2k

1 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

createApi hands back an openapi-fetch client, so the methods are HTTP verbs and paths, not named helpers

Older wrappers for REST services usually expose methods such as `getPhoto` or `searchPhotos`. unsplash-js does not. `createApi` returns a preconfigured openapi-fetch instance whose methods correspond to the usual HTTP verbs: `.GET`, `.POST`, `.PUT`, `.DELETE` and `.PATCH`. You pass the path from Unsplash's API and a `params` object:

ts
unsplash.GET("/photos/{assetSlug}", {
  params: { path: { assetSlug: "123" } },
});

The only runtime dependency in package.json is `openapi-fetch` at `^0.17.0`. The type layer is generated: the `gen:type` script runs `openapi-typescript ./public.json -o ./gen/unsplash.d.ts`, so the TypeScript definitions come from the OpenAPI spec file public.json in the repository, and `gen:alias` runs a jq script over the same file to produce aliases.

The trade is obvious. Any endpoint in the spec is reachable and type-checked, but a developer who expects `unsplash.photos.get(id)` has to learn the path strings and read the OpenAPI spec for parameters. The README links the spec in the Swagger editor for that reason.

In the browser you set baseUrl to your own proxy, and then accessKey is unnecessary

The README's one bolded warning is about browsers. A page that calls the library directly would expose the access key, so the library expects a proxy on your own server. The two constructors look like this:

ts
import { createApi } from "unsplash-js";

// on your node server
const serverApi = createApi({
  accessKey: "MY_ACCESS_KEY",
  //...other fetch options
});

// in the browser
const browserApi = createApi({
  baseUrl: "https://mywebsite.com/unsplash-proxy",
  //...other fetch options
});

If `baseUrl` is set, `accessKey` is unnecessary and vice-versa. The reason given is to authenticate requests with your Access Key in line with the API Guideline and to keep keys confidential.

The consequence is extra work that this library does not do for you. The package contains no proxy server. A static site with no backend cannot satisfy the README's rule without building one, which means a serverless function or a small route that forwards requests and adds the key. The README shows no example of that proxy.

A failed request returns result.error, but a failed network call still throws

There are two outcomes to a request, and the README names the fields. When data arrives, `result.data` is populated. When the server returns an error, `result.error` holds the details, and the README's example reads `result.error.errors[0]`. The raw `Response` is in `result.response`, which is how you reach a header such as `X-Total` on feed responses.

That is only half the error story. The README adds a bold note that all the usual fetch exceptions can still be thrown. A DNS failure, an offline browser or an aborted request does not produce a `result.error`. It rejects the promise. Code that checks `result.error` and nothing else will pass through those cases as unhandled rejections.

The README's AbortController example shows the shape: pass `signal` in the per-request options, call `controller.abort()`, and in the `.catch` check that `err.name === "AbortError"`. Per-request fetch options override the ones given to `createApi`, which includes custom headers such as `X-Custom-Header`.

Public authentication is automatic and the two other schemes are yours to implement

Giving `accessKey` to `createApi` sets the `Authorization` header for public authentication, with no further steps. That covers read-only access to public endpoints. For user authentication or dynamic client registration, the README says you must set the `Authorization` header yourself on each request, following the requirements of the scheme.

This defines the library's limit. unsplash-js does not run an OAuth flow, store tokens or refresh them. The README documents no helper for the authorization code exchange. If your application acts on behalf of an Unsplash user, you write that flow and pass the resulting header through the fetch options.

The README also lists three guidelines you must follow before using the API: hotlink images, attribute photographers, and trigger a download when appropriate. Each links to the Unsplash help center. Nothing in the library enforces them. They are rules about how you display and fetch images, and a wrapper that returns JSON cannot check them.

Replacing fetch is a documented seam, and Node 20 is the engine floor

package.json sets `"node": ">=20"` under engines, so the library expects a runtime where `fetch` exists. For anything else, the README gives two places to swap in a different implementation. Globally on a server, `import fetch from "node-fetch"; global.fetch = fetch;`, and in a browser `import "whatwg-fetch"`. Or per instance, as an argument to `createApi`:

ts
const unsplash = createApi({
  accessKey: "MY_ACCESS_KEY",
  fetch: nodeFetch,
});

The README gives three reasons: mocking fetch in tests, targeting an older runtime and supplying a custom implementation. It refers readers to the openapi-fetch testing documentation for more.

The package ships ESM and CommonJS. The exports map in package.json points `import` at ./dist/index.mjs and `require` at ./dist/index.cjs, with matching .d.mts and .d.cts type files, and sets `"sideEffects": false`. Only the dist folder is published.

A 5 KB size-limit on both bundles keeps the wrapper thin, and TypeScript 4.5 is the type floor

The size-limit entries in package.json cap dist/index.mjs and dist/index.cjs at 5 KB each, checked by the `size` script with `@size-limit/preset-small-lib`. The cap applies to the library's own output as measured by that tool, and the README gives no measured size, so the actual number is for you to run.

The README states that the types target TypeScript v4.5 and above, and recommends an editor such as VSCode for completion even in plain JavaScript. The repository holds four screenshots, vscode-params-completion-1.png, vscode-params-completion-2.png, vscode-path-completion.png and vscode-response-completion.png, which show request and response completion. The development toolchain itself uses TypeScript `^5.8.0`, tsdown for the build, vitest for tests, oxlint and oxfmt for linting and formatting, and pnpm as the package manager, with a flake.nix for a Nix environment.

One gap: the README's Types section has headings for request completion and response completion with the text between them missing in the available copy. The screenshots are the evidence for what the completions look like.

package.json says 8.1.0, but the releases list stops at v7.0.18 in May 2023

The three newest entries on the repository's releases list are v7.0.18 on 11 May 2023, v7.0.17 on 10 May and v7.0.16 on 8 May. package.json reads version 8.1.0. The repository is not archived, and the last push was on 6 October 2026. So the code has moved well beyond what the releases page shows, and the page is the wrong place to learn what changed between 7.x and 8.x. CHANGELOG.md sits in the repository root and is the place to check.

The move to an openapi-fetch core also changes how code is written. The README's Usage section is built around `.GET` and path strings, so an application written against the older named-method style, which this article does not cover, needs a rewrite of every call, not a version bump.

Install with any of the three managers:

bash
$ npm i --save unsplash-js

# OR

$ yarn add unsplash-js

# OR

$ pnpm add unsplash-js

Before using it, register as a developer and read the API Guidelines. The key comes from the application you create there.

Editorial conclusion

Use unsplash-js if you call the Unsplash API from Node or through your own proxy and want types generated from the OpenAPI spec. Do not use it for a backend-less browser app, or if you need ready-made OAuth handling. First read CHANGELOG.md for the 7.x to 8.x differences, because the releases page stops at v7.0.18.

Frequently asked questions

How do I install unsplash-js?

Run npm i --save unsplash-js, yarn add unsplash-js or pnpm add unsplash-js. The package requires Node 20 or later according to package.json.

Can unsplash-js be used directly in the browser?

Only through a proxy on your own server. In the browser you set baseUrl to the proxy, and accessKey is then unnecessary.

What do I need before calling the Unsplash API with unsplash-js?

Register as a developer, create an application to get an access key, and read the API Guidelines. They require hotlinking images, attributing photographers and triggering a download when appropriate.

Does unsplash-js support TypeScript?

Yes. The library is written in TypeScript and its types target TypeScript v4.5 and above. Plain JavaScript users still get type hints in an editor such as VSCode.

Official sources

  1. License: MIT
  2. Project website
  3. README
  4. Releases
  5. unsplash/unsplash-js on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/unsplash-unsplash-js.svg)](https://hysenlabs.com/projects/unsplash-unsplash-js)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/unsplash-unsplash-js.svg)](https://hysenlabs.com/projects/unsplash-unsplash-js)

Was this useful?