curl --request POST \
--url http://localhost:8000/v1/keys/rotate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"environment": "live",
"name": "Production API Key"
}
'import requests
url = "http://localhost:8000/v1/keys/rotate"
payload = {
"environment": "live",
"name": "Production API Key"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({environment: 'live', name: 'Production API Key'})
};
fetch('http://localhost:8000/v1/keys/rotate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "8000",
CURLOPT_URL => "http://localhost:8000/v1/keys/rotate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'environment' => 'live',
'name' => 'Production API Key'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "http://localhost:8000/v1/keys/rotate"
payload := strings.NewReader("{\n \"environment\": \"live\",\n \"name\": \"Production API Key\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://localhost:8000/v1/keys/rotate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"environment\": \"live\",\n \"name\": \"Production API Key\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:8000/v1/keys/rotate")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"environment\": \"live\",\n \"name\": \"Production API Key\"\n}"
response = http.request(request)
puts response.read_body{
"deprecated_key": {
"created_at": "2024-01-01T10:30:00Z",
"deprecated_at": "2024-01-15T10:30:00Z",
"environment": "live",
"grace_period_days_remaining": 7,
"grace_period_ends_at": "2024-01-22T10:30:00Z",
"is_active": true,
"key_id": "550e8400-e29b-41d4-a716-446655440000",
"key_prefix": "dk_live_",
"key_suffix": "xY9z",
"last_used_at": "2024-01-15T10:29:00Z",
"name": "Production API Key",
"status": "deprecated"
},
"new_key": {
"api_key": "dk_live_newKeyXYZ123456789abcdefghijklmnop",
"created_at": "2024-01-15T10:30:00Z",
"environment": "live",
"key_id": "770e8400-e29b-41d4-a716-446655440002",
"name": "Production API Key"
}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Rotate API key
Rotate your API key.
Creates a new API key and deprecates the current active key. The old key remains valid for 7 days (grace period) to allow migration.
This is the recommended way to rotate keys without service disruption.
curl --request POST \
--url http://localhost:8000/v1/keys/rotate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"environment": "live",
"name": "Production API Key"
}
'import requests
url = "http://localhost:8000/v1/keys/rotate"
payload = {
"environment": "live",
"name": "Production API Key"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({environment: 'live', name: 'Production API Key'})
};
fetch('http://localhost:8000/v1/keys/rotate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "8000",
CURLOPT_URL => "http://localhost:8000/v1/keys/rotate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'environment' => 'live',
'name' => 'Production API Key'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "http://localhost:8000/v1/keys/rotate"
payload := strings.NewReader("{\n \"environment\": \"live\",\n \"name\": \"Production API Key\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://localhost:8000/v1/keys/rotate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"environment\": \"live\",\n \"name\": \"Production API Key\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:8000/v1/keys/rotate")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"environment\": \"live\",\n \"name\": \"Production API Key\"\n}"
response = http.request(request)
puts response.read_body{
"deprecated_key": {
"created_at": "2024-01-01T10:30:00Z",
"deprecated_at": "2024-01-15T10:30:00Z",
"environment": "live",
"grace_period_days_remaining": 7,
"grace_period_ends_at": "2024-01-22T10:30:00Z",
"is_active": true,
"key_id": "550e8400-e29b-41d4-a716-446655440000",
"key_prefix": "dk_live_",
"key_suffix": "xY9z",
"last_used_at": "2024-01-15T10:29:00Z",
"name": "Production API Key",
"status": "deprecated"
},
"new_key": {
"api_key": "dk_live_newKeyXYZ123456789abcdefghijklmnop",
"created_at": "2024-01-15T10:30:00Z",
"environment": "live",
"key_id": "770e8400-e29b-41d4-a716-446655440002",
"name": "Production API Key"
}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Authorizations
API Key authentication. Format: dk_test_ or dk_live_
Body
Request schema for creating a new API key (POST /v1/keys).
Attributes: name: Human-readable name for the API key (e.g., "Production API Key") environment: Key environment - "live" for production, "test" for testing (default: "live")
Response
New API key created and old key deprecated
Response for API key rotation (POST /v1/keys/rotate).
Returns the new key and information about the deprecated old key. The old key remains active for 7 days (grace period) to allow migration.
WARNING: The api_key field in new_key is shown only in this response. Store it securely immediately - it cannot be retrieved again.
The newly created API key (includes plaintext key, shown only once)
Show child attributes
Show child attributes
{ "api_key": "dk_live_abcdefghijklmnopqrstuvwxyz1234567890ABC", "created_at": "2024-01-15T10:30:00Z", "environment": "live", "key_id": "550e8400-e29b-41d4-a716-446655440000", "name": "Production API Key" }
The old key that was deprecated (with grace period information)
Show child attributes
Show child attributes
{ "created_at": "2024-01-15T10:30:00Z", "environment": "live", "is_active": true, "key_id": "550e8400-e29b-41d4-a716-446655440000", "key_prefix": "dk_live_", "key_suffix": "xY9z", "last_used_at": "2024-01-15T12:45:00Z", "name": "Production API Key", "status": "active" }
{ "created_at": "2024-01-01T10:30:00Z", "deprecated_at": "2024-01-15T10:30:00Z", "environment": "live", "grace_period_days_remaining": 5, "grace_period_ends_at": "2024-01-22T10:30:00Z", "is_active": true, "key_id": "660e8400-e29b-41d4-a716-446655440001", "key_prefix": "dk_live_", "key_suffix": "aBc1", "last_used_at": "2024-01-15T12:45:00Z", "name": "Old Production Key", "status": "deprecated" }