Skip to main content
Send model usage from your own collector when the CostGraph operator or agent does not scrape your gateway. CostGraph prices token usage and includes it in Cost breakdown alongside your other costs. Create an AI gateway connection and select Neither under Where it runs. Choose the ingestion format that matches your collector.

Send usage through the API

Use an API key with focus: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.
Rows containing BilledCost, EffectiveCost, ListCost, or ContractedCost are rejected. If your collector calculates costs, use Push FOCUS data to send priced records.

Send Prometheus metrics

Send the costgraph_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 are input, 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

Set costgraph_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.

Verify imported usage

Allow up to an hour for processing. Open Cost breakdown, select the tenant and date range, and group by Provider. Check the gateway’s token quantity and cost. Enable Columns > Show zero cost to see usage without a matching rate. If usage is missing, check the connection identifiers and required labels. If quantity appears without a cost, check the model mapping and rates.