Skip to content
POST/api/v1/api-keys/{keyId}/rotate

Rotate an API key (new key issued; old expires after grace window)

Mints a replacement key with identical scopes/binding and schedules the original to expire after grace_period_hours (default 24). The replacement rawKey is returned ONLY once. Admin role required.

Authentication

Send Authorization: Bearer YOUR_API_KEY on every request. Generate API keys at /dashboard/api-keys.

Parameters

keyId in pathrequired
string

Request body

Example

{
  "grace_period_hours": 24
}
Schema
{
  "application/json": {
    "schema": {
      "type": "object",
      "properties": {
        "grace_period_hours": {
          "type": "integer",
          "minimum": 1,
          "maximum": 168,
          "default": 24,
          "description": "Hours the original key remains valid after rotation."
        }
      }
    }
  }
}

Response

201 example

{
  "success": true
}

All status codes

201Rotation succeeded — body has replacement.rawKey + original expiry.
400(no description)
401(no description)
403Forbidden — admin role required.
404API key not found.
429(no description)

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 '{ "grace_period_hours": 24 }'

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: {
    "grace_period_hours": 24
  },
});
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={
    "grace_period_hours": 24
},
)
print(response)

Go

package main

import (
	"context"
	"fmt"
	"net/http"
	"os"
	"strings"
)

func main() {
	body := strings.NewReader(`{"grace_period_hours":24}`)
	req, _ := http.NewRequestWithContext(context.Background(), "POST", "https://evalguard.ai/api/v1/api-keys/{keyId}/rotate", body)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("EVALGUARD_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil { panic(err) }
	defer resp.Body.Close()
	fmt.Println(resp.Status)
}

Errors

400401403404429

Other API Keys endpoints