NewWacht Bench is live — AI-assisted development for Wacht

rotateApiKey()

Rotates an existing key using the app-scoped route and returns a new one-time secret.

Usage

The following example shows a basic usage of the backend client from @wacht/nextjs/server.

import { wachtClient } from '@wacht/nextjs/server';export async function rotateKey(appName: string, keyId: string) {  const client = await wachtClient();  return client.apiKeys.rotateApiKey(appName, keyId);}

Signature

function rotateApiKey(  appName: string,  keyId: string,): Promise<ApiKeyWithSecret>

Parameters

appName?: string | undefined;
Slug of the app that owns the key.
keyId?: string | undefined;
Identifier of the key to rotate.

Return value

key?: ApiKey | undefined;
Updated key record after rotation.
id?: string | undefined;
Stable key id.
app_slug?: string | undefined;
Owning app slug.
name?: string | undefined;
Key display name.
key_prefix?: string | undefined;
Public key prefix.
key_suffix?: string | undefined;
Public key suffix.
permissions?: string[] | undefined;
Permissions attached to the key.
secret?: string | undefined;
New secret value returned once.

Behavior

  • Wraps the corresponding backend endpoint for this capability.
  • Use the returned payload as canonical backend state for follow-up operations.

Examples

Rotate a compromised key

import { wachtClient } from '@wacht/nextjs/server';export async function rotateCompromisedKey() {  const client = await wachtClient();  return client.apiKeys.rotateApiKey('internal-api', '12345');}

On this page