curl --request GET \
--url https://api.flex.ai/v1/flex/usage \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.flex.ai/v1/flex/usage"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.flex.ai/v1/flex/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.flex.ai/v1/flex/usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
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.flex.ai/v1/flex/usage"
req, _ := http.NewRequest("GET", 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.get("https://api.flex.ai/v1/flex/usage")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flex.ai/v1/flex/usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"object": "usage",
"currency": "USD",
"total_spend": 123,
"total_tokens": 123,
"total_requests": 123,
"by_model": [
{
"model": "<string>",
"canonical_model": "<string>",
"modality": "text",
"requests": 123,
"total_tokens": 123,
"billing_unit": "<string>",
"total_spend": 123,
"units_consumed": 123
}
],
"daily": [
{
"date": "2023-12-25",
"requests": 123,
"total_tokens": 123,
"total_spend": 123
}
],
"generated_at": "2023-11-07T05:31:56Z"
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"detail": [
{}
]
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}Programmatic spend for the calling key
FlexAI-specific shape (intentionally not OpenAI’s /v1/organization/usage/*
— that surface requires org/team scoping which FlexAI does not yet model).
Returns total spend, total tokens, per-model breakdown, and a daily
history for the API key in the Authorization header. Cached per-key
for 60 seconds.
total_spend is the sum of the charges applied to your account for the
requests in the window, so it matches your invoice for that period
exactly. Note that it is not recoverable from total_tokens and the
published per-token rates: a cached prompt is billed at the lower cached
rate, so a token-based re-derivation will read high. Group by
canonical_model to reconcile per model.
curl --request GET \
--url https://api.flex.ai/v1/flex/usage \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.flex.ai/v1/flex/usage"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.flex.ai/v1/flex/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.flex.ai/v1/flex/usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
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.flex.ai/v1/flex/usage"
req, _ := http.NewRequest("GET", 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.get("https://api.flex.ai/v1/flex/usage")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flex.ai/v1/flex/usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"object": "usage",
"currency": "USD",
"total_spend": 123,
"total_tokens": 123,
"total_requests": 123,
"by_model": [
{
"model": "<string>",
"canonical_model": "<string>",
"modality": "text",
"requests": 123,
"total_tokens": 123,
"billing_unit": "<string>",
"total_spend": 123,
"units_consumed": 123
}
],
"daily": [
{
"date": "2023-12-25",
"requests": 123,
"total_tokens": 123,
"total_spend": 123
}
],
"generated_at": "2023-11-07T05:31:56Z"
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"detail": [
{}
]
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}Authorizations
Virtual API key. Create one from the
FlexAI dashboard. Pass as
Authorization: Bearer sk-xxxx.
Query Parameters
Number of trailing days to include in daily. Capped at 90, the
period for which per-key billed spend is retained.
1 <= x <= 90Response
Successful response
usage USD Per-model spend rows. Group by canonical_model+modality
for reconciliation: canonical_model is the stable catalog
id (the same id /v1/pricing and /v1/models use), whereas
model is the raw ledger id (the served routing target, e.g.
an FP8 packaging name) and is NOT stable across the
request/served/ledger forms of the same model. Two rows can
share a canonical_model when the ledger recorded one model
under two raw forms. Multi-modality models appear once per
modality (image+image_edit, etc.). Text rows have
modality=text, units_consumed=null, billing_unit=tokens.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Was this page helpful?