Send usage through the API
Use an API key withfocus:write and the connection’s UUID. Send FOCUS 1.2 rows
with usage quantities and no cost fields. CostGraph calculates the cost using
the connection’s model rates.
The following request sends 20,000 output tokens for one model. Replace the
connection ID and charge period with your values.
BilledCost, EffectiveCost, ListCost, or ContractedCost
are rejected. If your collector calculates costs, use
Push FOCUS data to send priced records.
Send Prometheus metrics
Send thecostgraph_gen_ai_usage_total counter through Prometheus remote write
to https://tsdb.costgraph.ai/api/v1/write. Include your API key in the
X-API-Key header. Prometheus, OpenTelemetry Collector, and Grafana Alloy can
send these metrics.
The counter records cumulative units consumed. This example reports 20,000
input tokens attributed to the customer acme. Replace the tenant ID and gateway
name with the values from your connection.
Supported labels
The required labels identify the connection and the usage to price.
Optional labels add attribution and pricing context.
CostGraph skips series with missing required labels, unknown usage kinds or
units, or values of zero or less. Both the tenant ID and gateway name must match
the connection.
Use Attribution spec to
read other labels, such as
team or route, into cost dimensions. These labels
do not need a costgraph_ prefix.
Usage kinds
The accepted usage kinds areinput, output, cached_input, cache_write,
reasoning, image, audio_input, audio_output, and embedding.
CostGraph also accepts input_cache_read as cached_input and
input_cache_write as cache_write.
Cached token accounting
Setcostgraph_input_includes_cache="true" when your input count includes the
cached input and cache-write tokens you report separately. CostGraph subtracts
these from input to avoid counting them twice.
Without this label, CostGraph uses the host’s convention. Anthropic, Bedrock,
and Claude on Vertex report cached tokens separately from input. Other hosts
include them in input.