Skip to content

Commit 92a7bb1

Browse files
authored
Merge pull request #134 from Portkey-AI/openapi-spec/4432-admin-api-upgrade
docs(openapi): add API key rotate endpoint and document reset_usage update flow
2 parents 40ca2ec + 0422d00 commit 92a7bb1

1 file changed

Lines changed: 169 additions & 2 deletions

File tree

openapi.yaml

Lines changed: 169 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17686,6 +17686,19 @@ paths:
1768617686
application/json:
1768717687
schema:
1768817688
$ref: "#/components/schemas/UpdateApiKeyObject"
17689+
examples:
17690+
update_api_key:
17691+
summary: Update key metadata and limits
17692+
value:
17693+
name: API_KEY_NAME_0909
17694+
rate_limits:
17695+
- type: requests
17696+
unit: rpm
17697+
value: 100
17698+
reset_usage:
17699+
summary: Reset accumulated usage for this key
17700+
value:
17701+
reset_usage: true
1768917702
parameters:
1769017703
- name: id
1769117704
in: path
@@ -17821,7 +17834,7 @@ paths:
1782117834
- lang: curl
1782217835
label: Default
1782317836
source: |
17824-
curl -X GET "https://api.portkey.ai/v1/api-keys/{id}"
17837+
curl -X PUT "https://api.portkey.ai/v1/api-keys/{id}" \
1782517838
-H "x-portkey-api-key: PORTKEY_API_KEY" \
1782617839
-H "Content-Type: application/json" \
1782717840
-d '{
@@ -17885,7 +17898,7 @@ paths:
1788517898
- lang: curl
1788617899
label: Self-Hosted
1788717900
source: |
17888-
curl -X GET "SELF_HOSTED_CONTROL_PLANE_URL/api-keys/{id}" \
17901+
curl -X PUT "SELF_HOSTED_CONTROL_PLANE_URL/api-keys/{id}" \
1788917902
-H "x-portkey-api-key: PORTKEY_API_KEY" \
1789017903
-H "Content-Type: application/json" \
1789117904
-d '{
@@ -18253,6 +18266,130 @@ paths:
1825318266
})
1825418267
console.log(apiKey);
1825518268

18269+
/api-keys/{id}/rotate:
18270+
servers: *ControlPlaneServers
18271+
post:
18272+
tags:
18273+
- Api-Keys
18274+
summary: Rotate API Key
18275+
description: |
18276+
Rotates an existing API key and returns a newly generated key value.
18277+
The previous key remains valid during the transition period and expires at `key_transition_expires_at`.
18278+
requestBody:
18279+
content:
18280+
application/json:
18281+
schema:
18282+
$ref: "#/components/schemas/RotateApiKeyRequest"
18283+
examples:
18284+
default:
18285+
summary: Rotate with a custom transition period
18286+
value:
18287+
key_transition_period_ms: 3600000
18288+
parameters:
18289+
- name: id
18290+
in: path
18291+
schema:
18292+
type: string
18293+
format: uuid
18294+
required: true
18295+
responses:
18296+
"200":
18297+
description: OK
18298+
headers:
18299+
Content-Type:
18300+
schema:
18301+
type: string
18302+
example: application/json
18303+
content:
18304+
application/json:
18305+
schema:
18306+
$ref: "#/components/schemas/RotateApiKeyResponse"
18307+
x-code-samples:
18308+
- lang: python
18309+
label: Default
18310+
source: |
18311+
import requests
18312+
18313+
response = requests.post(
18314+
"https://api.portkey.ai/v1/api-keys/API_KEY_ID/rotate",
18315+
headers={
18316+
"x-portkey-api-key": "PORTKEY_API_KEY",
18317+
"Content-Type": "application/json",
18318+
},
18319+
json={
18320+
"key_transition_period_ms": 3600000
18321+
}
18322+
)
18323+
18324+
print(response.json())
18325+
- lang: javascript
18326+
label: Default
18327+
source: |
18328+
const response = await fetch("https://api.portkey.ai/v1/api-keys/API_KEY_ID/rotate", {
18329+
method: "POST",
18330+
headers: {
18331+
"x-portkey-api-key": "PORTKEY_API_KEY",
18332+
"Content-Type": "application/json",
18333+
},
18334+
body: JSON.stringify({
18335+
key_transition_period_ms: 3600000
18336+
}),
18337+
});
18338+
18339+
const rotatedApiKey = await response.json();
18340+
console.log(rotatedApiKey);
18341+
- lang: curl
18342+
label: Default
18343+
source: |
18344+
curl -X POST "https://api.portkey.ai/v1/api-keys/{id}/rotate" \
18345+
-H "x-portkey-api-key: PORTKEY_API_KEY" \
18346+
-H "Content-Type: application/json" \
18347+
-d '{
18348+
"key_transition_period_ms": 3600000
18349+
}'
18350+
- lang: python
18351+
label: Self-Hosted
18352+
source: |
18353+
import requests
18354+
18355+
response = requests.post(
18356+
"SELF_HOSTED_CONTROL_PLANE_URL/api-keys/API_KEY_ID/rotate",
18357+
headers={
18358+
"x-portkey-api-key": "PORTKEY_API_KEY",
18359+
"Content-Type": "application/json",
18360+
},
18361+
json={
18362+
"key_transition_period_ms": 3600000
18363+
}
18364+
)
18365+
18366+
print(response.json())
18367+
- lang: javascript
18368+
label: Self-Hosted
18369+
source: |
18370+
const response = await fetch("SELF_HOSTED_CONTROL_PLANE_URL/api-keys/API_KEY_ID/rotate", {
18371+
method: "POST",
18372+
headers: {
18373+
"x-portkey-api-key": "PORTKEY_API_KEY",
18374+
"Content-Type": "application/json",
18375+
},
18376+
body: JSON.stringify({
18377+
key_transition_period_ms: 3600000
18378+
}),
18379+
});
18380+
18381+
const rotatedApiKey = await response.json();
18382+
console.log(rotatedApiKey);
18383+
- lang: curl
18384+
label: Self-Hosted
18385+
source: |
18386+
curl -X POST "SELF_HOSTED_CONTROL_PLANE_URL/api-keys/{id}/rotate" \
18387+
-H "x-portkey-api-key: PORTKEY_API_KEY" \
18388+
-H "Content-Type: application/json" \
18389+
-d '{
18390+
"key_transition_period_ms": 3600000
18391+
}'
18392+
1825618393
/policies/usage-limits:
1825718394
post:
1825818395
tags:
@@ -34306,6 +34443,10 @@ components:
3430634443
example: 100
3430734444
usage_limits:
3430834445
$ref: "#/components/schemas/UsageLimits"
34446+
reset_usage:
34447+
type: boolean
34448+
description: Whether to reset current usage. If the current status is exhausted, this will change it back to active.
34449+
example: true
3430934450
scopes:
3431034451
type: array
3431134452
items:
@@ -34330,6 +34471,32 @@ components:
3433034471
format: email
3433134472
example: "foo@bar.com"
3433234473

34474+
RotateApiKeyRequest:
34475+
type: object
34476+
properties:
34477+
key_transition_period_ms:
34478+
type: integer
34479+
minimum: 1800000
34480+
description: Optional transition period in milliseconds during which the previous key remains valid.
34481+
example: 3600000
34482+
34483+
RotateApiKeyResponse:
34484+
type: object
34485+
properties:
34486+
id:
34487+
type: string
34488+
format: uuid
34489+
example: "550e8400-e29b-41d4-a716-446655440000"
34490+
key:
34491+
type: string
34492+
description: Newly rotated API key value.
34493+
example: "pk_live_new_rotated_key_value"
34494+
key_transition_expires_at:
34495+
type: string
34496+
format: date-time
34497+
description: Timestamp when the previous key version stops being accepted.
34498+
example: "2026-01-15T10:30:00.000Z"
34499+
3433334500
PromptRenderResponse:
3433434501
type: object
3433534502
required:

0 commit comments

Comments
 (0)