Create usage

Ingests a batch of account-usage samples — what a developer's OWN AI accounts have consumed of their OWN plans, metered from each provider's own login — and appends them to the warehouse series.

POST /v1/usage

Addresshttps://api.hanzo.ai/v1/usage
MethodPOST
Operationpost_usage
AuthAuthorization: Bearer $HANZO_API_KEY

Ingests a batch of account-usage samples — what a developer's OWN AI accounts have consumed of their OWN plans, metered from each provider's own login — and appends them to the warehouse series. Answers 202.

Send either a samples array or one sample's fields at the top level. Every sample needs a provider, a machine and a known window class; an unknown window or kind is refused rather than silently rewritten, because a dash filled with a class nobody reported is worse than an error. There is no timestamp field: the server owns the observation clock, and a sample says which window it measured with windowStart or resetsAt.

It is FAIL-SOFT on storage: a warehouse outage costs a poll of history (stored:false), never a failed request. It records usage ONLY — the link registry is refreshed separately via POST /v1/link, so there is one and only one way to update an account row.

Request

43 fields, body application/json (required).

FieldInTypeRequiredDescription
accountbodystring—Account is the linked account the window was metered from.
cachedInputTokensbodyinteger (int64)—CachedInputTokens is the prompt tokens the provider served from cache.
confidencebodystring—Confidence says how much the counters below mean.
costCentsbodyinteger (int64)—CostCents is what the window cost on the PROVIDER's own plan, in US cents.
costLimitCentsbodyinteger (int64)—CostLimitCents is the plan's spend ceiling for the window, in US cents.
currencybodystring—Currency is the provider's currency when it is not US cents.
inputTokensbodyinteger (int64)—InputTokens is prompt tokens consumed in the window.
kindbodystring—Kind is subscription or apikey.
lanebodystring—Lane is the meter lane within the account.
machinebodystring—Machine is the host whose meter read the window.
outputTokensbodyinteger (int64)—OutputTokens is completion tokens produced in the window.
planbodystring—Plan is the subscription plan the account is on, as the provider names it.
providerbodystring—Provider is the upstream the account belongs to, e.g. anthropic.
requestsbodyinteger (int64)—Requests is how many requests the window covers.
resetsAtbodystring—ResetsAt is when the measured window rolls over, RFC3339.
samplesbodyusage.sampleReq[]—Samples is the batch form: every lane a poller measured, in one call.
samples[].accountbodystring—Account is the linked account the window was metered from.
samples[].cachedInputTokensbodyinteger (int64)—CachedInputTokens is the prompt tokens the provider served from cache.
samples[].confidencebodystring—Confidence says how much the counters below mean.
samples[].costCentsbodyinteger (int64)—CostCents is what the window cost on the PROVIDER's own plan, in US cents.
samples[].costLimitCentsbodyinteger (int64)—CostLimitCents is the plan's spend ceiling for the window, in US cents.
samples[].currencybodystring—Currency is the provider's currency when it is not US cents.
samples[].inputTokensbodyinteger (int64)—InputTokens is prompt tokens consumed in the window.
samples[].kindbodystring—Kind is subscription or apikey.
samples[].lanebodystring—Lane is the meter lane within the account.
samples[].machinebodystring—Machine is the host whose meter read the window.
samples[].outputTokensbodyinteger (int64)—OutputTokens is completion tokens produced in the window.
samples[].planbodystring—Plan is the subscription plan the account is on, as the provider names it.
samples[].providerbodystring—Provider is the upstream the account belongs to, e.g. anthropic.
samples[].requestsbodyinteger (int64)—Requests is how many requests the window covers.
samples[].resetsAtbodystring—ResetsAt is when the measured window rolls over, RFC3339.
samples[].syntheticbodyboolean—Synthetic marks a window the meter inferred rather than read.
samples[].totalTokensbodyinteger (int64)—TotalTokens is the window's total tokens.
samples[].usedPctbodynumber (double)—UsedPct is how much of the window's allowance is consumed, 0–100.
samples[].windowbodystring—Window is the window class: 6h, day, week or month.
samples[].windowMinutesbodyinteger (int32)—WindowMinutes is the window's real length in minutes, as the meter reports it.
samples[].windowStartbodystring—WindowStart is when the measured window opened, RFC3339.
syntheticbodyboolean—Synthetic marks a window the meter inferred rather than read.
totalTokensbodyinteger (int64)—TotalTokens is the window's total tokens.
usedPctbodynumber (double)—UsedPct is how much of the window's allowance is consumed, 0–100.
windowbodystring—Window is the window class: 6h, day, week or month.
windowMinutesbodyinteger (int32)—WindowMinutes is the window's real length in minutes, as the meter reports it.
windowStartbodystring—WindowStart is when the measured window opened, RFC3339.

Response

StatusBodyMeaning
202usage.reportRespaccepted
defaultproblem-detailsrefused

202 body — 2 fields.

FieldInTypeAlwaysDescription
acceptedbodyinteger (int64)—Accepted is how many samples passed validation.
storedbodyboolean—Stored is whether the warehouse actually persisted them.

Failure carries the platform error shape — see Errors.

Examples

hanzo usage create
import { Configuration, UsageApi } from 'hanzoai';

const api = new UsageApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postUsage({ account: "<account>", cachedInputTokens: 0 });
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import UsageApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = UsageApi(client).post_usage(account="<account>", cached_input_tokens=0)
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.UsageAPI.PostUsage(context.Background()).Execute()
if err != nil {
	return err
}
use hanzo_client::apis::{configuration::Configuration, usage_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = usage_api::post_usage(&cfg, Default::default()).await?;
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.UsageApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new UsageApi(client).postUsage();
curl -X POST https://api.hanzo.ai/v1/usage \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "account": "<account>",
       "cachedInputTokens": 0
     }'

MCP reaches usage through the usage tool, which names its 5 operations with its own verbs — this one among them, under a name only MCP declares. describe explains any of them:

curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "list_usage_analytics"
         }
       }
     }'

Usage API · All Hanzo APIs · Interactive reference

Was this page useful?