Skip to main content
Connect an AI gateway to see token usage and calculated costs in Cost breakdown. CostGraph reads the gateway’s metrics and prices them using model rates. Customer and agent run labels let you attribute that usage to the people and workloads behind it. Allow up to an hour for usage to appear after collection starts. Select the tenant and date range that include your traffic, then group by Provider. If a model has no matching rate, enable Columns > Show zero cost to see its usage.

Supported gateways

Choose your gateway for its metrics configuration and attribution instructions.

Connect your gateway

Open Integrations, select your gateway, and name the connection. Choose its tenant and deployment location under Where it runs. Complete the settings for that location, then select Connect.

Kubernetes cluster

Install the CostGraph operator and enable its AI gateway scraper in your Helm values.
Select the cluster, namespace, and pod selector for your gateway’s data plane. The operator discovers new connections within five minutes. You do not need to add individual scrape targets. An explicit target in operatorPrometheus.scrapeTargets takes precedence over a discovered target.

Pod selector

Use a comma-separated list of key=value labels. Every term must match the same pod. Select only the gateway’s data plane pods. Its control plane does not expose the required token metrics. The following command lists pod labels so you can build the selector.
For example, this selector matches an agentgateway data plane named llm.
A single label also works. Inequality, set membership, and existence checks are not supported.

Virtual machine

Install the CostGraph agent on the host. Select A virtual machine, choose the Instance, and confirm Metrics port. Only machines with a reporting agent appear in the instance list. The agent reads metrics from the host’s loopback address. The connection prefills these ports. Change the port to match your gateway’s configuration. If the connection stays pending, check that its metrics endpoint responds. For a vLLM server using the default port, run the following command on the host.

View gateway metrics

After the connection starts collecting, open its Metrics tab to chart requests, latency, tokens, and spend per hour for each model. CostGraph also alerts you when a connection stops delivering data. Refer to View gateway metrics for each chart, the gateways that report it, and how to resolve an empty chart.

Attribute usage to your customers

Configure the customer identifier in your gateway’s metrics. CostGraph stores it as a sub-account so you can group usage and costs by customer. The Supported gateways table links to each gateway’s setup. For workload-level attribution, use the costgraph.ai/sub-account annotation. A customer label on a request takes precedence over this annotation. vLLM supports workload-level attribution only.

Group usage by agent run

Include the sandbox’s run tag value in each request using your gateway’s supported header or metadata field. CostGraph adds the model cost to that run under AutoPilot > Sandboxes > Runs. The run value must match exactly. Follow your gateway’s guide for the request configuration and Group cost by run for sandbox setup.

How usage is priced

CostGraph selects a rate for each model and token type in the following order.
  1. A rate selected by a costgraph.ai/pricing-id.model label on the collected Kubernetes pods or their namespace.
  2. A matching model catalog rate. This is a reference cost, which can differ from the cost of serving the model yourself.
  3. An amortized rate for a connected Kubernetes model server such as vLLM. CostGraph divides its serving namespace’s daily cost by the tokens collected through that connection that day. A proxy such as agentgateway does not use this fallback to price the model servers behind it.
If a selected pricing ID has no applicable rate, usage stays unpriced. CostGraph does not fall back to a catalog rate. Only token usage is priced through this integration.

Use your own model rates

To use a different price, register your input and output rates with Publish model prices. Use an API key with pricing:write. Each entry specifies the model, token_bucket, and unit_price_per_mtok. Supply a rate for each token type you want to price. The API returns an id for each entry. For a model that isn’t in the CostGraph catalog, set the entry’s model to the exact name your gateway reports. CostGraph prices that model’s usage at your rates, without a pin. For a Kubernetes connection serving one model, set costgraph.ai/pricing-id.model on the gateway’s data plane pods to a returned ID. Set the label in the pod template so replacement pods keep it. CostGraph uses the selected model’s rates for each token type from the same registered host. The pin applies to all model usage collected through that connection. Do not use one pin to assign different prices to several models behind a shared gateway. The dashboard does not provide a per-model rate editor for gateway connections. After the next processing cycle, check the model’s quantity and cost in Cost breakdown. For example, set rates of $1 per million input tokens and $4 per million output tokens. One million input tokens and 250,000 output tokens then cost $2. The table’s unit price blends the token types in the row. These rates change CostGraph’s cost calculation. They do not change what your model provider charges or configure customer invoicing. See Pricing IDs for how to assign a rate.

Connection settings

Set model_map and attribution_spec in the API request when creating a connection. Set model_map and tenant_map on an existing connection.

Model map

Use model_map to match a model identifier reported by your gateway to a CostGraph catalog model. It changes which model CostGraph looks up. It does not set an input or output price. To change those prices, see Use your own model rates. For example, the following map identifies gpt4o-prod as openai/gpt-4o. CostGraph then looks for a rate for that model.
Include this field in the request to Connect an AI gateway, or send it to Update an AI gateway connection. The update replaces the whole map, and an empty object removes every mapping. To edit the map in the dashboard, open the gateway connection’s settings on its integration page. When the gateway’s Metrics tab says CostGraph doesn’t recognise a model, you can also select Map models there. The Model mapping dialog lists the names the gateway reported in the last seven days that match no catalog model, and the names you already mapped. To map a name that isn’t listed, enter it below the list and select Add. Choose a catalog model for each name, then select Save mapping. Editing the map needs an organization owner, admin, or billing admin. Saving a changed map reprices the last two days of usage. Earlier days keep the models they were priced with. Keys match the reported identifier after trimming surrounding whitespace. Without a matching entry, CostGraph uses the reported name. Empty mapping values are ignored. The target must identify an existing catalog model. If the connection reports an unpriced model, use the identifier from that error as the mapping key. A successful match still needs an applicable rate. Do not map a model to a different model to obtain a price.

Tenant map

Use tenant_map to rename a reported sub-account. This example displays acct-7 as Acme.
The map cannot assign a customer to usage that has no customer label.

Attribution spec

Use attribution_spec to select labels or fields for customer and other cost dimensions. This example reads customer_id into the sub-account and retains team as a cost extension.
Set source to prom_label for scraped metrics, focus_field for pushed rows, or static for a fixed value in key. Add "transform": "sha256" to hash a value before storage. A rule with "required": true rejects a batch if its key is absent. Without a spec, the connection reads costgraph_sub_account from metrics or SubAccountId from pushed rows into the sub-account.

Send custom usage

Select Neither under Where it runs if you collect usage outside the operator or agent. Send unpriced FOCUS records through the API or remote-write Prometheus counters. Follow Send custom gateway usage for both formats.

Supported labels

Custom metrics need tenant, gateway, model, usage kind, and unit labels. Add customer and host labels for attribution and rate matching. See the Supported labels reference for the complete list and accepted values.