For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Invoice-grade attribution
Carry a validated caller identity into AWS billing records, so LLM spend is attributed per team, app, user, or any chosen attribution value on the provider’s own bill.
Invoice-grade attribution means that the value that names a request reaches the cloud provider’s own billing records. Finance then slices the same numbers that the provider charges. Agentgateway can also compute per-team spend from token counts and a price list, but that number is an estimate rather than the invoice. For the reasoning behind the term, see Invoice-grade attribution on Amazon Bedrock with agentgateway.
You configure the attribution values, and agentgateway resolves each one from an identity that it validated or from a static value that you assign.
Note
Invoice-grade attribution depends on the provider. The provider must accept a per-request attribution value and expose that value in its billing data. Providers with no equivalent billing dimension cannot support it. For those providers, attribute usage inside agentgateway instead, such as with virtual keys.
Before you begin
- Set up an agentgateway proxy.
- Create the AgentgatewayBackend and HTTPRoute for the LLM provider that you want to attribute, such as Amazon Bedrock.
- Apply a JWT authentication policy to the route, so that
jwt.*values are available to attribution expressions.
Amazon Bedrock
Bedrock attributes inference cost to the IAM principal that made the call. For gateway traffic, the documented pattern is a per-caller session. Agentgateway assumes an AWS Identity and Access Management (IAM) role for each request. The session name and the session tags come from the caller’s identity.
The session name lands in AWS CloudTrail and in the IAM principal column of the Cost and Usage Report. The tags surface as cost allocation tags in Cost Explorer and in the Cost and Usage Report.
Session identity and tags
Configure assumeRole in the auth.aws settings of the AgentgatewayBackend. The session name is either a static sessionName or a sessionNameExpression. Each tag is either a static value or a CEL expression that agentgateway evaluates against the request.
kubectl apply -f- <<EOF
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: bedrock
namespace: agentgateway-system
spec:
ai:
provider:
bedrock:
model: "amazon.nova-micro-v1:0"
region: "us-east-1"
policies:
auth:
aws:
assumeRole:
roleArn: arn:aws:iam::123456789012:role/bedrock-invoke
sessionNameExpression: jwt.sub
tags:
- key: user
expression: jwt.sub
- key: team
expression: request.headers["x-team"]
- key: environment
value: prod
EOFReview the following table to understand this configuration. For more information, see the API reference.
| Setting | Description |
|---|---|
assumeRole.roleArn | The role that agentgateway assumes for each request. The ambient credentials of the workload are the source credentials for AWS Security Token Service (STS), and must be allowed sts:AssumeRole and sts:TagSession on the role. |
assumeRole.sessionName | A static STS RoleSessionName, 2 to 64 characters that match [\w+=,.@-]. If you do not set it, AWS generates a random name. |
assumeRole.sessionNameExpression | A CEL expression that agentgateway evaluates against each request to produce the session name, such as jwt.sub. A per-caller session name makes callers distinguishable in CloudTrail and in the Cost and Usage Report. Set either sessionName or sessionNameExpression, not both. |
assumeRole.tags | STS session tags that agentgateway passes to AssumeRole. Each tag has a key and exactly one of value for a static value or expression for a value that agentgateway computes per request. After you activate a key as a cost allocation tag, it appears in the Cost and Usage Report under resourceTags/user:<key>. STS allows at most 50 tags per role session, with keys up to 128 characters and values up to 256 characters. |
Agentgateway checks static values against the STS limits when the resource is accepted. Expressions are evaluated per request and fail closed. An expression that errors, or that produces an empty or invalid value, rejects the request before agentgateway calls AWS. No request reaches Bedrock unattributed.
To see the tags on the bill, activate the keys as cost allocation tags in the AWS Billing console. New keys take up to 24 hours to become available for activation. Activated tags apply to usage from that point on.
Choose attribution values
Where the value comes from decides what the bill is worth in a dispute.
jwt.*values come from a token that agentgateway validated under a JWT authentication policy. The value is a fact about who logged in, checked on every request.- Static values are the ones that you assign to the backend or route. Use them for callers that do not log in, such as batch jobs and internal services.
request.headers[...]is the caller’s word. Use it only for dimensions that the caller is trusted to assert, such as an environment name. Never use it for the identity that chargeback depends on.
Keep the values low-cardinality on the bill. Every distinct set of session tags is its own STS session and its own set of line items in the Cost and Usage Report. Tag by team and cost center everywhere, and tag per user only where the chargeback question needs it.
Verify
Learn more
- Transform requests for request transformations and the CEL context.
- Virtual keys to attribute usage inside agentgateway.
- Amazon Bedrock provider configuration.