🚀 Introducing Agent Gateway — governance, observability, and control for your AI agents.  Register for live webinar ↗
import requests
response = requests.post(
"https://api.portkey.ai/v1/api-keys/API_KEY_ID/rotate",
headers={
"x-portkey-api-key": "PORTKEY_API_KEY",
"Content-Type": "application/json",
},
json={
"key_transition_period_ms": 3600000
}
)
print(response.json()){
"id": "550e8400-e29b-41d4-a716-446655440000",
"key": "pk_live_new_rotated_key_value",
"key_transition_expires_at": "2026-01-15T10:30:00.000Z"
}Rotates an existing API key and returns a newly generated key value.
The previous key remains valid during the transition period and expires at key_transition_expires_at.
import requests
response = requests.post(
"https://api.portkey.ai/v1/api-keys/API_KEY_ID/rotate",
headers={
"x-portkey-api-key": "PORTKEY_API_KEY",
"Content-Type": "application/json",
},
json={
"key_transition_period_ms": 3600000
}
)
print(response.json()){
"id": "550e8400-e29b-41d4-a716-446655440000",
"key": "pk_live_new_rotated_key_value",
"key_transition_expires_at": "2026-01-15T10:30:00.000Z"
}Optional transition period in milliseconds during which the previous key remains valid.
x >= 18000003600000
OK
Was this page helpful?