Rotate Project API Key
(v2)POST
Rotates a project-scoped API key in place — same id, name and history, and no second key is created. The new value is returned exactly once, in this response. Requests made with the outgoing value during a grace period carry Sunset and X-Api-Key-Warning headers, which is the window to redeploy. Reviving an expired key cannot take a grace period.
curl -X POST "https://api.confident-ai.com/v2/projects/{projectId}/api-keys/{apiKeyId}/rotate" \
-H "CONFIDENT_API_KEY: <ORGANIZATION-API-KEY>" \
-H "Content-Type: application/json" \
-d '{
"gracePeriodInHours": 24,
"expiresInDays": 90
}'{
"success": true,
"data": {
"id": 1420,
"name": "CI pipeline",
"valid": true,
"created_at": "2025-01-15T09:30:00.000Z",
"expiresAt": "2025-04-15T09:30:00.000Z",
"value": "confident_us_org_5tRw8xYz2aBc4dEf6gHi8jKl0mNo2pQr4sTu6vWx",
"shadowValue": null,
"rotatesAt": null,
"lastUsed": "2025-02-28T18:45:12.000Z"
},
"deprecated": false
}Headers
CONFIDENT_API_KEYstringRequiredThe organization API key for your Confident AI organization.
Path parameters
projectIdstringRequiredThe id of the project the key belongs to.
apiKeyIdintegerRequiredThe id of the API key.
Request body
gracePeriodInHoursintegerHow long the current value keeps authenticating alongside the new one, in hours from now — a duration, not a date, stored on the key as
rotatesAtand never set pastexpiresAt. Defaults to 0, which replaces the value immediately and stops the old one at once.expiresInDaysinteger | nullA new lifetime for the key, in days from now — a duration, not a date, stored on the key as
expiresAt. Omit it to keep the current expiry, or sendnullto remove the expiry altogether. Required when rotating a key that has already expired.
Response
Rotate Project API Key succeeded.
successbooleanIndicates if the request was successful.
dataobject | objectA just-rotated API key. Which variant you get follows
gracePeriodInHours: without one the new secret isvalueandshadowValueisnull, with one the new secret isshadowValueandvalueis the masked outgoing key.Show 2 variantsHide 2 variants
Immediately Rotated API KeyobjectThe result of rotating without a grace period:
valuehas already been replaced and the previous value stopped authenticating the moment this response was produced.Show 9 propertiesHide 9 properties
idintegerThe id of the API key, generated by Confident AI.
namestring | nullThe label for the key, shown on the Confident AI platform.
validbooleanWhether the key authenticates. A deactivated key is rejected on every request until it is reactivated.
created_atstringWhen the key was created.
expiresAtstring | nullThe instant the key stops authenticating, or
nullwhen it never expires. Confident AI computes it from theexpiresInDaysduration sent when the key was created or last rotated.valuestringThe new full API key. This response is the only place it is ever returned, so store it now — every later response masks it.
shadowValuenullAlways
null: the rotation completed as this request was served, so no second value is in flight.rotatesAtnullAlways
null: no rotation is pending.lastUsedstring | nullWhen the key last authenticated a request, or
nullwhen it never has.
- OR
API Key With Rotation PendingobjectThe result of rotating with a grace period: two values authenticate at once, the outgoing one until
rotatesAtand the new one from now on.Show 9 propertiesHide 9 properties
idintegerThe id of the API key, generated by Confident AI.
namestring | nullThe label for the key, shown on the Confident AI platform.
validbooleanWhether the key authenticates. A deactivated key is rejected on every request until it is reactivated.
created_atstringWhen the key was created.
expiresAtstring | nullThe instant the key stops authenticating, or
nullwhen it never expires. Confident AI computes it from theexpiresInDaysduration sent when the key was created or last rotated.valuestringThe outgoing key, masked. It keeps authenticating alongside
shadowValueuntilrotatesAt, then stops.shadowValuestringThe new full API key, issued by this rotation. This response is the only place it is ever returned, so store it now — every later response masks it. It authenticates immediately and becomes
valueoncerotatesAtpasses.rotatesAtstringWhen the grace period ends:
shadowValuebecomesvalueand the outgoing value is rejected. Confident AI computes it from thegracePeriodInHoursduration and never sets it pastexpiresAt.lastUsedstring | nullWhen the key last authenticated a request, or
nullwhen it never has.
deprecatedbooleanIndicates if this endpoint is deprecated.