POST
/api/v1/api-keys/{keyId}/rotateRotate an API key (new key issued, old expires after grace window)
Mints a new API key value for the given keyId. The new rawKey is returned ONLY in this response and cannot be retrieved again. The previous key continues to work for a configurable grace period so clients can roll without an outage.
Authentication
Send Authorization: Bearer YOUR_API_KEY on every request. Generate API keys at /dashboard/api-keys.
Parameters
keyId in pathrequiredstringRequest body
Example
{
"graceSeconds": 0
}Schema
{
"application/json": {
"schema": {
"type": "object",
"properties": {
"graceSeconds": {
"type": "integer",
"minimum": 0,
"description": "Seconds the previous key remains valid after rotation."
}
}
}
}
}Response
All status codes
200Rotation succeeded; body includes the new rawKey + the previous key expiry timestamp
404API key not found or caller not authorized for this org
Code samples
cURL
curl -X POST \
https://evalguard.ai/api/v1/api-keys/{keyId}/rotate \
-H "Authorization: Bearer $EVALGUARD_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "graceSeconds": 0 }'TypeScript
import { EvalGuard } from "@evalguard/sdk";
const client = new EvalGuard({ apiKey: process.env.EVALGUARD_API_KEY });
const response = await client.request({
method: "POST",
path: "/api/v1/api-keys/{keyId}/rotate",
body: {
"graceSeconds": 0
},
});
console.log(response);Python
from evalguard import EvalGuard
import os
client = EvalGuard(api_key=os.environ["EVALGUARD_API_KEY"])
response = client.request(
method="POST",
path="/api/v1/api-keys/{keyId}/rotate",
body={
"graceSeconds": 0
},
)
print(response)Go
package main
import (
"context"
"fmt"
"os"
"github.com/evalguard/evalguard-go"
)
func main() {
client := evalguard.NewClient(os.Getenv("EVALGUARD_API_KEY"))
resp, err := client.Request(context.Background(), "POST", "/api/v1/api-keys/{keyId}/rotate", map[string]any{"graceSeconds": 0})
if err != nil { panic(err) }
fmt.Println(resp)
}Errors
404