curl --request POST \
--url https://api.lava.so/v1/spend_keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"allowed_models": [
"<string>"
],
"allowed_providers": [
"<string>"
],
"spend_limit": {
"amount": "<string>"
},
"request_limit": {
"count": 5000000
},
"rate_limit": {
"rpm": 2,
"burst": 2
},
"expires_at": "2023-11-07T05:31:56Z"
}
'import requests
url = "https://api.lava.so/v1/spend_keys"
payload = {
"name": "<string>",
"allowed_models": ["<string>"],
"allowed_providers": ["<string>"],
"spend_limit": { "amount": "<string>" },
"request_limit": { "count": 5000000 },
"rate_limit": {
"rpm": 2,
"burst": 2
},
"expires_at": "2023-11-07T05:31:56Z"
}
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({
name: '<string>',
allowed_models: ['<string>'],
allowed_providers: ['<string>'],
spend_limit: {amount: '<string>'},
request_limit: {count: 5000000},
rate_limit: {rpm: 2, burst: 2},
expires_at: '2023-11-07T05:31:56Z'
})
};
fetch('https://api.lava.so/v1/spend_keys', 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",
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([
'name' => '<string>',
'allowed_models' => [
'<string>'
],
'allowed_providers' => [
'<string>'
],
'spend_limit' => [
'amount' => '<string>'
],
'request_limit' => [
'count' => 5000000
],
'rate_limit' => [
'rpm' => 2,
'burst' => 2
],
'expires_at' => '2023-11-07T05:31:56Z'
]),
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://api.lava.so/v1/spend_keys"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"allowed_models\": [\n \"<string>\"\n ],\n \"allowed_providers\": [\n \"<string>\"\n ],\n \"spend_limit\": {\n \"amount\": \"<string>\"\n },\n \"request_limit\": {\n \"count\": 5000000\n },\n \"rate_limit\": {\n \"rpm\": 2,\n \"burst\": 2\n },\n \"expires_at\": \"2023-11-07T05:31:56Z\"\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://api.lava.so/v1/spend_keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"allowed_models\": [\n \"<string>\"\n ],\n \"allowed_providers\": [\n \"<string>\"\n ],\n \"spend_limit\": {\n \"amount\": \"<string>\"\n },\n \"request_limit\": {\n \"count\": 5000000\n },\n \"rate_limit\": {\n \"rpm\": 2,\n \"burst\": 2\n },\n \"expires_at\": \"2023-11-07T05:31:56Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.lava.so/v1/spend_keys")
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 \"name\": \"<string>\",\n \"allowed_models\": [\n \"<string>\"\n ],\n \"allowed_providers\": [\n \"<string>\"\n ],\n \"spend_limit\": {\n \"amount\": \"<string>\"\n },\n \"request_limit\": {\n \"count\": 5000000\n },\n \"rate_limit\": {\n \"rpm\": 2,\n \"burst\": 2\n },\n \"expires_at\": \"2023-11-07T05:31:56Z\"\n}"
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"
}
]
}
}Create spend key
Create a new spend key for the authenticated wallet. Spend key issuance is enabled on request: until then, requests return 403 with code spend_key_issuance_paused (email support@lava.so). When enabled, the raw key is returned once in the response — store it securely. Requires a merchant secret key (aks_live_* / aks_test_*).
curl --request POST \
--url https://api.lava.so/v1/spend_keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"allowed_models": [
"<string>"
],
"allowed_providers": [
"<string>"
],
"spend_limit": {
"amount": "<string>"
},
"request_limit": {
"count": 5000000
},
"rate_limit": {
"rpm": 2,
"burst": 2
},
"expires_at": "2023-11-07T05:31:56Z"
}
'import requests
url = "https://api.lava.so/v1/spend_keys"
payload = {
"name": "<string>",
"allowed_models": ["<string>"],
"allowed_providers": ["<string>"],
"spend_limit": { "amount": "<string>" },
"request_limit": { "count": 5000000 },
"rate_limit": {
"rpm": 2,
"burst": 2
},
"expires_at": "2023-11-07T05:31:56Z"
}
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({
name: '<string>',
allowed_models: ['<string>'],
allowed_providers: ['<string>'],
spend_limit: {amount: '<string>'},
request_limit: {count: 5000000},
rate_limit: {rpm: 2, burst: 2},
expires_at: '2023-11-07T05:31:56Z'
})
};
fetch('https://api.lava.so/v1/spend_keys', 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",
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([
'name' => '<string>',
'allowed_models' => [
'<string>'
],
'allowed_providers' => [
'<string>'
],
'spend_limit' => [
'amount' => '<string>'
],
'request_limit' => [
'count' => 5000000
],
'rate_limit' => [
'rpm' => 2,
'burst' => 2
],
'expires_at' => '2023-11-07T05:31:56Z'
]),
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://api.lava.so/v1/spend_keys"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"allowed_models\": [\n \"<string>\"\n ],\n \"allowed_providers\": [\n \"<string>\"\n ],\n \"spend_limit\": {\n \"amount\": \"<string>\"\n },\n \"request_limit\": {\n \"count\": 5000000\n },\n \"rate_limit\": {\n \"rpm\": 2,\n \"burst\": 2\n },\n \"expires_at\": \"2023-11-07T05:31:56Z\"\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://api.lava.so/v1/spend_keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"allowed_models\": [\n \"<string>\"\n ],\n \"allowed_providers\": [\n \"<string>\"\n ],\n \"spend_limit\": {\n \"amount\": \"<string>\"\n },\n \"request_limit\": {\n \"count\": 5000000\n },\n \"rate_limit\": {\n \"rpm\": 2,\n \"burst\": 2\n },\n \"expires_at\": \"2023-11-07T05:31:56Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.lava.so/v1/spend_keys")
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 \"name\": \"<string>\",\n \"allowed_models\": [\n \"<string>\"\n ],\n \"allowed_providers\": [\n \"<string>\"\n ],\n \"spend_limit\": {\n \"amount\": \"<string>\"\n },\n \"request_limit\": {\n \"count\": 5000000\n },\n \"rate_limit\": {\n \"rpm\": 2,\n \"burst\": 2\n },\n \"expires_at\": \"2023-11-07T05:31:56Z\"\n}"
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"
}
]
}
}Authorizations
Bearer token authentication used for standard API calls. Format: 'Bearer YOUR_API_KEY'
Body
255active, paused openai, anthropic 1Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Response
Spend key created
Masked key preview (e.g., lava_sk_a1b2c3d4****)
active, paused Request format this key accepts
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
x >= 0Total request count tracked for this key across completed/current cycles
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