Overview
Typescript client for unkey
If you prefer a typed experience over calling http endpoints directly, you can use our sdk @unkey/api
.
Install
Unkey Root Key
When creating, revoking or updating resources, you will need your root key — you can create a new one in the settings. Afterwards you need to provide it to the client:
Always keep your root key safe and reset it if
you suspect it has been compromised.
Response format
Because forgetting to handle thrown errors properly in javascript is often forgotten, we have decided to explicitly return errors to be handled. Fortunately typescript helps us here and everything is typesafe.
Every method returns either an error
or a result
field, never both and never none.
Checking for errors
To check for errors you use the error
property, our errors are easy to read and provide a link to our documentation for more information.
Options
The constructor accepts some options to customize the behavior:
Base Url
Run all requests against your own instance of unkey hosted on your own infrastructure.
Retries
By default the client will retry on network errors, you can customize this behavior:
Cache
Configure the fetch
cache behavior.
As of October 2023, the cache
option is not yet implemented in cloudflare workers and will throw an error if used.
Available options are: default
, force-cache
, no-cache
, no-store
, only-if-cached
or reload
.
Disable telemetry
By default, Unkey collects anonymous telemetry data to help us understand which versions of our SDK is being used, and in which environment.
If you wish to disable this, you can do so by passing a boolean flag to the constructor:
Was this page helpful?