If the response comes back into a Node process you control, wrapping the client there is simpler and also gives you the gateway’s real cost. Use this pattern for traffic you cannot wrap, for example from services in other languages.
- A Stigg server API key in both the application and the proxy.
- A metered feature or credit currency to bill against. This guide reports to the
creditscurrency insyncmode, so no meter configuration is needed.
1
Check and send attribution from the application
Check the budget before sending the request, then add the attribution headers.The headers carry the customer, the attribution dimensions (here
{"agentId":"agent-support-bot"}), the attribution key that names the agent, and a correlation ID. They contain no secrets.Applications in other languages can set the same headers by hand: x-stigg-customer-id, x-stigg-dimensions (a JSON object), x-stigg-attribution-key (the key in x-stigg-dimensions that names the agent, here agentId) and x-stigg-run-id.2
Report from the proxy
After the upstream call returns, report the usage with the incoming request’s headers:
vendornames the response shape the proxy observed:openai,openai-responses,anthropic,geminiortypesafe.idempotencyKeyshould be the upstream request ID, so a retried report is not counted twice.- Reporting never throws. Answer the caller even if
result.okisfalse, and log the failure. - Requests without an
x-stigg-customer-idheader are not attributed.
3
Verify
Send a request through the proxy and open
customer-acme in the Stigg app. The credit balance drops by the reported amount, and the usage is attributed to agent-support-bot and every level above it.Limits of this pattern
- The proxy cannot deny a call. Only the application holds the budget context, so the check happens there. A request that skips the check is still metered, but not gated.
- Tokens, not cost. What crosses the boundary is a usage report. To bill the gateway’s real cost, wrap a gateway you call instead.
- No double metering. Do not also wrap the client in the application for the same requests, or usage is reported twice.