Usage
curl --request GET \
--url https://api.example.com/v1/usageimport requests
url = "https://api.example.com/v1/usage"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.example.com/v1/usage', 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.example.com/v1/usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$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.example.com/v1/usage"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/v1/usage")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"storage_bytes": 123,
"bandwidth_bytes": 123,
"upload_count": 123,
"period_start": "<string>"
}Account
Usage
Get your current usage statistics.
GET
/
v1
/
usage
Usage
curl --request GET \
--url https://api.example.com/v1/usageimport requests
url = "https://api.example.com/v1/usage"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.example.com/v1/usage', 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.example.com/v1/usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$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.example.com/v1/usage"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/v1/usage")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"storage_bytes": 123,
"bandwidth_bytes": 123,
"upload_count": 123,
"period_start": "<string>"
}Retrieve your current usage statistics including storage, bandwidth, and upload counts.
Response
integer
required
Total storage used in bytes.
integer
required
Bandwidth used this period in bytes.
integer
required
Number of uploads this period.
string
required
Start of current billing period (YYYY-MM-DD).
Example
curl https://api.stashfyle.com/v1/usage \
-H "Authorization: Bearer sk_live_xxx"
const response = await fetch('https://api.stashfyle.com/v1/usage', {
headers: { 'Authorization': 'Bearer sk_live_xxx' }
});
const usage = await response.json();
console.log(`Storage: ${usage.storage_bytes} bytes`);
response = requests.get(
'https://api.stashfyle.com/v1/usage',
headers={'Authorization': 'Bearer sk_live_xxx'}
)
usage = response.json()
print(f"Storage: {usage['storage_bytes']} bytes")
Response
{
"storage_bytes": 524288000,
"bandwidth_bytes": 1073741824,
"upload_count": 150,
"period_start": "2024-01-01"
}
Understanding Usage
Storage
Total bytes of all files currently stored. Decreases when you delete files.const storageGB = usage.storage_bytes / (1024 * 1024 * 1024);
console.log(`Using ${storageGB.toFixed(2)} GB`);
Bandwidth
Total bytes downloaded from your files this billing period. Resets monthly.Bandwidth has zero egress fees thanks to Cloudflare R2. Limits are for fair use only.
Upload Count
Number of files uploaded this billing period. Resets monthly.Monitoring Usage
Check Against Limits
const PLAN_LIMITS = {
free: { storage: 1 * 1024 * 1024 * 1024, uploads: 1000 },
hobby: { storage: 10 * 1024 * 1024 * 1024, uploads: 50000 },
pro: { storage: 100 * 1024 * 1024 * 1024, uploads: 500000 },
};
async function checkUsage(plan) {
const response = await fetch('https://api.stashfyle.com/v1/usage', {
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const usage = await response.json();
const limits = PLAN_LIMITS[plan];
return {
storageUsedPercent: (usage.storage_bytes / limits.storage) * 100,
uploadsUsedPercent: (usage.upload_count / limits.uploads) * 100,
isNearLimit: usage.storage_bytes > limits.storage * 0.8
};
}
Set Up Alerts
async function checkAndAlert() {
const { storageUsedPercent, isNearLimit } = await checkUsage('hobby');
if (isNearLimit) {
// Send notification to upgrade or clean up
console.warn(`Storage at ${storageUsedPercent.toFixed(1)}%`);
}
}
// Run daily
setInterval(checkAndAlert, 24 * 60 * 60 * 1000);
Plan Limits Reference
| Plan | Storage | Bandwidth/mo | Uploads/mo |
|---|---|---|---|
| Free | 1 GB | 5 GB | 1,000 |
| Hobby | 10 GB | 50 GB | 50,000 |
| Pro | 100 GB | 500 GB | 500,000 |
Errors
| Code | Status | Description |
|---|---|---|
unauthorized | 401 | Invalid or missing API key |
rate_limit_exceeded | 429 | Too many requests |