@@ -88,6 +88,24 @@ export class APIKeys extends APIResource {
8888 headers : buildHeaders ( [ { Accept : '*/*' } , options ?. headers ] ) ,
8989 } ) ;
9090 }
91+
92+ /**
93+ * Rotate an API key. Issues a new key that copies the name and project of the
94+ * rotated key, and schedules the rotated key to expire after a grace period so
95+ * in-flight callers can swap over. The new plaintext key is returned once.
96+ *
97+ * @example
98+ * ```ts
99+ * const createdAPIKey = await client.apiKeys.rotate('id');
100+ * ```
101+ */
102+ rotate (
103+ id : string ,
104+ body : APIKeyRotateParams | null | undefined = { } ,
105+ options ?: RequestOptions ,
106+ ) : APIPromise < CreatedAPIKey > {
107+ return this . _client . post ( path `/org/api_keys/${ id } /rotate` , { body, ...options } ) ;
108+ }
91109}
92110
93111export type APIKeysOffsetPagination = OffsetPagination < APIKey > ;
@@ -230,6 +248,20 @@ export interface APIKeyListParams extends OffsetPaginationParams {
230248 sort_direction ?: 'asc' | 'desc' ;
231249}
232250
251+ export interface APIKeyRotateParams {
252+ /**
253+ * Lifetime in days for the new key, up to 3650. Omit to reuse the rotated key's
254+ * original lifetime, or never-expires if it had none.
255+ */
256+ days_to_expire ?: number | null ;
257+
258+ /**
259+ * Grace period in days before the rotated key expires. Use 0 to expire it
260+ * immediately. Omit for the default grace period of 7 days.
261+ */
262+ expire_in_days ?: number | null ;
263+ }
264+
233265export declare namespace APIKeys {
234266 export {
235267 type APIKey as APIKey ,
@@ -239,5 +271,6 @@ export declare namespace APIKeys {
239271 type APIKeyRetrieveParams as APIKeyRetrieveParams ,
240272 type APIKeyUpdateParams as APIKeyUpdateParams ,
241273 type APIKeyListParams as APIKeyListParams ,
274+ type APIKeyRotateParams as APIKeyRotateParams ,
242275 } ;
243276}
0 commit comments