Usage
Record Usage Events (Batch)
Record up to 500 usage events in one call, with per-item outcomes.
POST
/
v1
/
usage
/
events
/
batch
Record up to 500 usage events
curl --request POST \
--url https://billing.example.com/v1/usage/events/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"events": [
{
"subscription_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"dimension": "<string>",
"quantity": 123,
"properties": {},
"transaction_id": "<string>",
"dynamic_amount": 123
}
]
}
'import requests
url = "https://billing.example.com/v1/usage/events/batch"
payload = { "events": [
{
"subscription_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"dimension": "<string>",
"quantity": 123,
"properties": {},
"transaction_id": "<string>",
"dynamic_amount": 123
}
] }
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({
events: [
{
subscription_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
customer_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
dimension: '<string>',
quantity: 123,
properties: {},
transaction_id: '<string>',
dynamic_amount: 123
}
]
})
};
fetch('https://billing.example.com/v1/usage/events/batch', 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://billing.example.com/v1/usage/events/batch",
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([
'events' => [
[
'subscription_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'customer_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'dimension' => '<string>',
'quantity' => 123,
'properties' => [
],
'transaction_id' => '<string>',
'dynamic_amount' => 123
]
]
]),
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://billing.example.com/v1/usage/events/batch"
payload := strings.NewReader("{\n \"events\": [\n {\n \"subscription_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"dimension\": \"<string>\",\n \"quantity\": 123,\n \"properties\": {},\n \"transaction_id\": \"<string>\",\n \"dynamic_amount\": 123\n }\n ]\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://billing.example.com/v1/usage/events/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"subscription_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"dimension\": \"<string>\",\n \"quantity\": 123,\n \"properties\": {},\n \"transaction_id\": \"<string>\",\n \"dynamic_amount\": 123\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/usage/events/batch")
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 \"events\": [\n {\n \"subscription_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"dimension\": \"<string>\",\n \"quantity\": 123,\n \"properties\": {},\n \"transaction_id\": \"<string>\",\n \"dynamic_amount\": 123\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"index": 123,
"status": "recorded",
"event_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"error": "<string>"
}
]
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}Example request
curl -X POST https://api.recurso.dev/v1/usage/events/batch \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"events": [
{
"subscription_id": "8b1f4e27-9c5a-4d3e-b8f2-6a7c9d0e1f23",
"customer_id": "9f2c1e84-6a3d-4b7e-9c21-8f4a5d6e7b01",
"dimension": "api_calls",
"quantity": 1250,
"transaction_id": "batch-2026-08-13-000001"
},
{
"subscription_id": "8b1f4e27-9c5a-4d3e-b8f2-6a7c9d0e1f23",
"customer_id": "9f2c1e84-6a3d-4b7e-9c21-8f4a5d6e7b01",
"dimension": "api_calls",
"quantity": 830,
"transaction_id": "batch-2026-08-13-000002"
}
]
}'
transaction_id — retries with the same ID are
deduplicated, so a crashed batch can be resent whole.
Batches cap at 500 events; above that, split the batch.
Errors
| Status | Code | When | Fix |
|---|---|---|---|
400 | validation_failed | events is missing or empty | Send at least one event in events |
400 | validation_failed | More than 500 events in one call (at most 500 events per batch) | Split into multiple batches |
401 | unauthorized | Missing or invalid API key | Send Authorization: Bearer $API_KEY |
500 | internal_error | The batch write failed as a whole | Resend the whole batch with the same transaction_ids — dedup makes it safe |
200 and
the offending index carries "status": "error" with its reason (bad UUIDs,
non-positive quantity, unknown subscription, customer mismatch). Errors use
the standard envelope — see Errors.Authorizations
Tenant API key obtained from POST /auth/register or POST /v1/developer/keys.
Body
application/json
Maximum array length:
500Show child attributes
Show child attributes
Response
Per-item outcomes, index-aligned with the request.
Show child attributes
Show child attributes
⌘I
Record up to 500 usage events
curl --request POST \
--url https://billing.example.com/v1/usage/events/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"events": [
{
"subscription_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"dimension": "<string>",
"quantity": 123,
"properties": {},
"transaction_id": "<string>",
"dynamic_amount": 123
}
]
}
'import requests
url = "https://billing.example.com/v1/usage/events/batch"
payload = { "events": [
{
"subscription_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"dimension": "<string>",
"quantity": 123,
"properties": {},
"transaction_id": "<string>",
"dynamic_amount": 123
}
] }
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({
events: [
{
subscription_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
customer_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
dimension: '<string>',
quantity: 123,
properties: {},
transaction_id: '<string>',
dynamic_amount: 123
}
]
})
};
fetch('https://billing.example.com/v1/usage/events/batch', 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://billing.example.com/v1/usage/events/batch",
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([
'events' => [
[
'subscription_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'customer_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'dimension' => '<string>',
'quantity' => 123,
'properties' => [
],
'transaction_id' => '<string>',
'dynamic_amount' => 123
]
]
]),
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://billing.example.com/v1/usage/events/batch"
payload := strings.NewReader("{\n \"events\": [\n {\n \"subscription_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"dimension\": \"<string>\",\n \"quantity\": 123,\n \"properties\": {},\n \"transaction_id\": \"<string>\",\n \"dynamic_amount\": 123\n }\n ]\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://billing.example.com/v1/usage/events/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"subscription_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"dimension\": \"<string>\",\n \"quantity\": 123,\n \"properties\": {},\n \"transaction_id\": \"<string>\",\n \"dynamic_amount\": 123\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/usage/events/batch")
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 \"events\": [\n {\n \"subscription_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"dimension\": \"<string>\",\n \"quantity\": 123,\n \"properties\": {},\n \"transaction_id\": \"<string>\",\n \"dynamic_amount\": 123\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"index": 123,
"status": "recorded",
"event_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"error": "<string>"
}
]
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}