Rotate spend key
curl --request POST \
--url https://api.lava.so/v1/spend_keys/{id}/rotate \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.lava.so/v1/spend_keys/{id}/rotate"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.lava.so/v1/spend_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://api.lava.so/v1/spend_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_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.lava.so/v1/spend_keys/{id}/rotate"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.lava.so/v1/spend_keys/{id}/rotate")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.lava.so/v1/spend_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>'
response = http.request(request)
puts response.read_body{
"spend_key_id": "<string>",
"key_preview": "<string>",
"name": "<string>",
"status": "active",
"request_shape": "openai",
"wallet_id": "<string>",
"current_spend": "<string>",
"total_spend": "<string>",
"current_requests": 1,
"total_requests": 1,
"created_at": "2023-11-07T05:31:56Z",
"key": "<string>",
"allowed_models": [
"<string>"
],
"allowed_providers": [
"<string>"
],
"spend_limit": {
"amount": "<string>",
"cycle": "daily"
},
"request_limit": {
"count": 5000000,
"cycle": "daily"
},
"rate_limit": {
"rpm": 2,
"burst": 2
},
"expires_at": "2023-11-07T05:31:56Z",
"last_used_at": "2023-11-07T05:31:56Z"
}{
"error": {
"message": "Invalid authentication credentials",
"code": "forward_token_json_invalid",
"status": 400,
"issues": [
{
"path": [
"model"
],
"message": "Missing required field: model"
},
{
"path": [
"messages",
"0",
"content"
],
"message": "Invalid message content format"
}
]
}
}{
"error": {
"message": "Invalid authentication credentials",
"code": "forward_token_json_invalid",
"status": 400,
"issues": [
{
"path": [
"model"
],
"message": "Missing required field: model"
},
{
"path": [
"messages",
"0",
"content"
],
"message": "Invalid message content format"
}
]
}
}Spend Keys
Rotate spend key
Rotate the raw secret for an existing spend key while preserving key settings and usage. The new raw key is returned once in the response. Requires a merchant secret key (aks_live_* / aks_test_*).
POST
/
spend_keys
/
{id}
/
rotate
Rotate spend key
curl --request POST \
--url https://api.lava.so/v1/spend_keys/{id}/rotate \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.lava.so/v1/spend_keys/{id}/rotate"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.lava.so/v1/spend_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://api.lava.so/v1/spend_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_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.lava.so/v1/spend_keys/{id}/rotate"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.lava.so/v1/spend_keys/{id}/rotate")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.lava.so/v1/spend_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>'
response = http.request(request)
puts response.read_body{
"spend_key_id": "<string>",
"key_preview": "<string>",
"name": "<string>",
"status": "active",
"request_shape": "openai",
"wallet_id": "<string>",
"current_spend": "<string>",
"total_spend": "<string>",
"current_requests": 1,
"total_requests": 1,
"created_at": "2023-11-07T05:31:56Z",
"key": "<string>",
"allowed_models": [
"<string>"
],
"allowed_providers": [
"<string>"
],
"spend_limit": {
"amount": "<string>",
"cycle": "daily"
},
"request_limit": {
"count": 5000000,
"cycle": "daily"
},
"rate_limit": {
"rpm": 2,
"burst": 2
},
"expires_at": "2023-11-07T05:31:56Z",
"last_used_at": "2023-11-07T05:31:56Z"
}{
"error": {
"message": "Invalid authentication credentials",
"code": "forward_token_json_invalid",
"status": 400,
"issues": [
{
"path": [
"model"
],
"message": "Missing required field: model"
},
{
"path": [
"messages",
"0",
"content"
],
"message": "Invalid message content format"
}
]
}
}{
"error": {
"message": "Invalid authentication credentials",
"code": "forward_token_json_invalid",
"status": 400,
"issues": [
{
"path": [
"model"
],
"message": "Missing required field: model"
},
{
"path": [
"messages",
"0",
"content"
],
"message": "Invalid message content format"
}
]
}
}Authorizations
Bearer token authentication used for standard API calls. Format: 'Bearer YOUR_API_KEY'
Path Parameters
Spend key ID
Response
Spend key rotated
Masked key preview (e.g., lava_sk_a1b2c3d4****)
Available options:
active, paused Request format this key accepts
Available options:
openai, anthropic Current spend in this cycle (decimal string)
Total spend tracked for this key across completed/current cycles (decimal string)
Current request count in this cycle
Required range:
x >= 0Total request count tracked for this key across completed/current cycles
Required range:
x >= 0The raw spend key (shown once)
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes