@spec create_key(map) :: map()

Creates an API key for your users.

Request

apiId
string
required

Choose an API where this key should be created.

prefix
string

To make it easier for your users to understand which product an api key belongs to, you can add prefix them.

For example Stripe famously prefixes their customer ids with cus_ or their api keys with sk_live_.

The underscore is automtically added if you are defining a prefix, for example: "prefix": "abc" will result in a key like abc_xxxxxxxxx

byteLength
int
default: 16

The bytelength used to generate your key determines its entropy as well as its length. Higher is better, but keys become longer and more annoying to handle.

The default is 16 bytes, or 2128 possible combinations

ownerId
string

Your user’s Id. This will provide a link between Unkey and your customer record.

When validating a key, we will return this back to you, so you can clearly identify your user from their api key.

meta
object

This is a place for dynamic meta data, anything that feels useful for you should go here

Example:

{
  "billingTier": "PRO",
  "trialEnds": "2023-06-16T17:16:37.161Z"
}
expires
int

You can auto expire keys by providing a unix timestamp in milliseconds.

Once keys expire they will automatically be deleted and are no longer valid.

ratelimit
Object

Unkey comes with per-key ratelimiting out of the box.

remaining
int

Optionally limit the number of times a key can be used. This is different from time-based expiration using expires.

Example:

"remaining": 10

The created key can be verified successfully 10 times, afterwards it is invalidated automatically.

Read more here

Response

key
string
required

The newly created api key

keyId
string
required

A unique id to reference this key for updating or revoking. This id can not be used to verify the key.