const { result, error } = await unkey.keys.update({
  keyId: "key_1233",
  ownerId: "new owner",
  remaining: 300,
  refill: {
    interval: "monthly",
    amount: 100,
    refillDay: 15,
  },
  enabled: true
});

if (error) {
  // handle potential network or bad request error
  // a link to our docs will be in the `error.docs` field
  console.error(error.message);
  return;
}
console.log(result)
{
  "result": {}
}

All json fields are optional, so you can update only the fields you need. To delete a field, set it to null.

const { result, error } = await unkey.keys.update({
  keyId: "key_1233",
  ownerId: "new owner",
  remaining: 300,
  refill: {
    interval: "monthly",
    amount: 100,
    refillDay: 15,
  },
  enabled: true
});

if (error) {
  // handle potential network or bad request error
  // a link to our docs will be in the `error.docs` field
  console.error(error.message);
  return;
}
console.log(result)
{
  "result": {}
}

Request

keyId
string
required

The ID of the key you want to update.

name
string | null

Update the name of the key.

ownerId
string | null
deprecated

Update the owner id of the key.

externalId
string | null

The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this back to you, so you know who is accessing your API. Under the hood this upserts and connects an ìdentity for you. To disconnect the key from an identity, set externalId: null.

meta
JSON | null

Update the metadata of a key. You will have to provide the full metadata object, not just the fields you want to update.

expires
int | null

Update the expire time of a key.

The expire time is a unix timestamp in milliseconds.

ratelimit
Object | null

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

remaining
int | null

Update the remaining usage of a key.

refill
Object

Unkey allows automatic refill on ‘remaining’ on a ‘daily’ or ‘monthly’ interval.

enabled
boolean

Sets if the key is enabled or disabled.

roles
string[]

A list of roles that this key should have. If the role does not exist, an error is thrown

Example:

["admin", "finance"]
permissions
string[]

A list of permissions that this key should have. If the permission does not exist, an error is thrown

Example:

["domains.create_record", "say_hello"]

Response

result

{}