curl --request POST \
--url https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"expires_at": "2023-11-07T05:31:56Z",
"grace_period_secs": 1
}
'import requests
url = "https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate"
payload = {
"expires_at": "2023-11-07T05:31:56Z",
"grace_period_secs": 1
}
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({expires_at: '2023-11-07T05:31:56Z', grace_period_secs: 1})
};
fetch('https://{host}/api/llm-gateway/admin/api-keys/{id}/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_URL => "https://{host}/api/llm-gateway/admin/api-keys/{id}/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([
'expires_at' => '2023-11-07T05:31:56Z',
'grace_period_secs' => 1
]),
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 := "https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate"
payload := strings.NewReader("{\n \"expires_at\": \"2023-11-07T05:31:56Z\",\n \"grace_period_secs\": 1\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("https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"expires_at\": \"2023-11-07T05:31:56Z\",\n \"grace_period_secs\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"expires_at\": \"2023-11-07T05:31:56Z\",\n \"grace_period_secs\": 1\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"key": "<string>",
"key_prefix": "<string>",
"name": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"previous_key_expires_at": "2023-11-07T05:31:56Z",
"rotated_at": "2023-11-07T05:31:56Z"
}Rotate an API key
Replace the key’s secret in place. The key id, name, bindings and usage history are kept. With grace_period_secs the previous secret keeps working for that long (at most 7 days); otherwise it stops working immediately. The new secret is returned once and never stored.
curl --request POST \
--url https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"expires_at": "2023-11-07T05:31:56Z",
"grace_period_secs": 1
}
'import requests
url = "https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate"
payload = {
"expires_at": "2023-11-07T05:31:56Z",
"grace_period_secs": 1
}
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({expires_at: '2023-11-07T05:31:56Z', grace_period_secs: 1})
};
fetch('https://{host}/api/llm-gateway/admin/api-keys/{id}/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_URL => "https://{host}/api/llm-gateway/admin/api-keys/{id}/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([
'expires_at' => '2023-11-07T05:31:56Z',
'grace_period_secs' => 1
]),
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 := "https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate"
payload := strings.NewReader("{\n \"expires_at\": \"2023-11-07T05:31:56Z\",\n \"grace_period_secs\": 1\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("https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"expires_at\": \"2023-11-07T05:31:56Z\",\n \"grace_period_secs\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{host}/api/llm-gateway/admin/api-keys/{id}/rotate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"expires_at\": \"2023-11-07T05:31:56Z\",\n \"grace_period_secs\": 1\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"key": "<string>",
"key_prefix": "<string>",
"name": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"previous_key_expires_at": "2023-11-07T05:31:56Z",
"rotated_at": "2023-11-07T05:31:56Z"
}Authorizations
A Barndoor API key, sent as Authorization: Bearer <key>. Keys are prefixed bdai_ and are opaque — do not attempt to decode one. Interchangeable with an OAuth 2.0 access token.
Path Parameters
Identifier, a UUID
Body
Body of POST /admin/api-keys/{id}/rotate and POST /user/api-keys/{id}/rotate
(BCP-5195). An empty object rotates immediately and keeps the key's expiry.
New expiry for the key. Omit to keep the current one; null removes
the expiry. Must be in the future.
How long the previous secret keeps authenticating after rotation, in
seconds. 0 (the default) cuts it off immediately. At most 7 days.
x >= 0Response
The rotated key, including its new secret
Unchanged by rotation.
The new API key — only returned by this call, never stored.
Until when the previous secret still authenticates; None when it was
cut off immediately.