What CostGraph scrapes
Read the labels off the running data plane pods and narrow the selector until it
matches them and nothing else:
How the metric maps
agentgateway_gen_ai_client_token_usage becomes
costgraph_gen_ai_usage_total:
The unit is always
tokens.
Attribute usage to your customers
Add a metric attribute computed from the request. On Kubernetes this goes in an AgentgatewayPolicy. The value is a CEL expression, so the identifier can come from a header, a JWT claim, or anything else in the request.A policy applies only where it is targeted, so it needs
targetRefs or
targetSelectors naming your Gateway. It must also live in that Gateway’s
namespace, because a policy cannot reach across namespaces. If a policy
already targets the Gateway, add the attributes block to that one instead
of creating a second.Group usage by agent run
Add arun attribute next to customer in the same policy. A run’s model cost
then appears next to its sandbox cost on AutoPilot > Sandboxes > Runs.
x-costgraph-run-id on each request, set to the run tag of
the run’s sandboxes. Refer to
Group cost by run.
AI gateways
Connecting, pricing, and sending usage yourself.