Agent in Production
ObservabilityLong read

Per-User Token Attribution Across Shared AI Coding Agent Deployments

Shared API keys erase ownership, so attribution must start at credentials.

· 8 min read
Cover illustration for “Per-User Token Attribution Across Shared AI Coding Agent Deployments”
Observability · November 12, 2026 · 8 min read · 1,876 words

Per-user token attribution across shared AI coding agent deployments requires an unbroken ownership chain, beginning before the first model call. Session-scoped credentials establish identity, gateway metadata makes that identity queryable, and enforced per-user budgets turn attribution into control. Complete session visibility also requires tool calls and file diffs to remain attributable to the same person or trigger, rather than appearing as disconnected activity under a shared account.

Why shared credentials make per-user token attribution structurally impossible

When six developers use one API key, the billing layer sees the same credential for every call. More detailed token records cannot show who owned a request if the request never recorded that distinction.

Okta’s “AI Agents at Work 2026” report found that 44% of enterprises credential their AI agents with static API keys, while a similarly large share use shared username/password combinations. With these setups, people and agents that share an account use the same credential. Each additional agent then expands the attribution gap as well as the potential spend. Even a careful log audit cannot fix this setup, because the systems that receive the requests already see everyone as the same identity.

How the transition to token-based billing turned an inconvenience into an operational risk

Token-consumption metering makes this missing ownership financially consequential. Under fixed request counts, teams could treat a request as a rough unit of capacity, even when its underlying workload varied. Token billing removes that simplifying assumption because a long agent run can consume far more than a short interaction. Teams can no longer count on a flat rate to keep spending within a limit.

Windsurf moved to a quota model in March 2026, replacing credits with daily and weekly usage limits per seat while pooling purchased add-on credits across the organization. That arrangement distinguishes seat allowances from shared additional consumption. It does not provide native per-repository attribution, leaving that granularity to third-party tooling.

An agent sends accumulated context at each reasoning step, so the same context can be billed repeatedly across a long chain. Runs of the same task can use very different total numbers of tokens even when the quality of their output is much the same. Teams need attribution for each run when they cannot rely on estimates for the task.

Uber disclosed in April 2026 that its full-year AI budget had been consumed in four months. Microsoft also changed access to agentic coding tools as token costs rose higher than expected, driven by those costs and the push to bring its toolchain together. These examples show the risk of growing usage, but they do not prove that missing attribution caused either company’s problem. They nevertheless make ownership of consumption a financial control.

What actually breaks inside a shared-credential agent deployment

Cost misattribution begins when a convenient label substitutes for ownership. A system that charges the “active” repository at inference time cannot accurately represent an agent turn touching a shared utilities package, three feature services, and an infrastructure module. All consumption lands in one bucket despite the broader work. Coordinator agents complicate this further because they can consume a disproportionate share of the token budget while worker agents produce the visible output. Assigning cost by output therefore obscures the work that generated it.

Prompt caching introduces a separate accounting distortion. If Project A’s CI pipeline writes a shared system prompt to cache at 1.25× cost and Project B reads it an hour later at 0.1× cost, simple project attribution over-bills A while giving B the benefit of A’s cache creation. A single total hides that distinction. Cache-creation tokens, cache-read tokens, input tokens, and output tokens need separate columns so that the ledger preserves the basis for allocation.

The same identity collapse also weakens the boundaries that permissions set. Okta illustrates this with a hypothetical CFO agent in a shared Slack channel that uses the CFO’s credentials and exposes executive compensation information to junior analysts. This is an illustrative scenario, not a documented incident. Its mechanism is the mismatch between the requesting person and the authority used to answer. In a service-account deployment, a chain that updates a deal stage, adds a contact note, and sends an email can similarly execute every step with admin-level access.

An audit log inherits that mismatch when every action points to one service account. It may record an operation without establishing who authorized it or connecting it to the changes that followed. That gap obstructs the question asked in SOC 2 Type II assessments and post-mortems about what the AI changed and why. EU AI Act Article 12 also makes logging matter for regulated deployments, though the Digital Omnibus has pushed high-risk obligations back to December 2, 2027. Per-user, per-system, and time-based traceability requires attribution architecture beyond a shared credential.

Why fixing identity at the credential layer is the prerequisite for everything else

The architectural response begins before token consumption, with a distinction between the agent and the person authorizing its work. The delegation token pattern gives the agent its own standing identity and a separate token for each invocation that holds the user-authority context. Both identities remain attributable to the action. The permission scope is bounded by what the user explicitly consented to for that invocation.

RFC 8693 provides the token-exchange mechanism for an On-Behalf-Of pattern. A service acts for a user while preserving that user’s permission scope. This establishes the identity that later metadata can describe. A gateway cannot manufacture the missing delegation after execution, regardless of how detailed its dashboards are.

Git operations need an additional distinction because push authentication and commit authorship are independent controls. Vitruvian Software’s earlier configuration set the token but left commits attributed to the machine owner while pull requests showed the bot. The history was silently inconsistent. Its later use of distinct bot identities addresses that earlier shared-identity problem, but the example shows why changing authentication alone does not establish correct authorship.

GitHub Apps provide the appropriate primitive for multi-agent deployments, with up to 100 Apps per organization and a distinct name[bot] identity for each. They authenticate with short-lived installation tokens, leaving the private key in a vault as the long-lived secret. Restricting each installation to specific repositories makes write access reviewable as configuration. Protocol adoption does not replace this work. The Model Context Protocol’s 2026 roadmap calls for ways to move away from static secrets, but does not itself provide protocol-level rate limiting or cost attribution.

Gateway-level metadata tagging as the second layer of attribution

Once credentials give each actor a distinct identity, request-time metadata lets the cost and audit systems use those identities. The minimum useful ownership contract includes trace_id, owner_team, workflow_id, feature, and a non-PII user or tenant handle. These fields connect an individual call to its organizational and execution context. Tags belong at the SDK call site, before dispatch, because logs cannot reliably reconstruct missing context weeks later. The gateway must reject untagged requests rather than silently assigning them to a default bucket.

Different tags support different kinds of investigation. Low-cardinality fields, including feature, deployment, and prompt version, suit threshold alerts and dashboards. High-cardinality fields, including user_id and agent_run_id, support investigation of a particular user or run after a spike. Neither category replaces the other. A team needs both a stable view of aggregate consumption and a path back to the calls that explain it.

Databricks’ Unity AI Gateway provides a concrete native implementation of much of this pattern. It tracks usage by user or service principal, endpoint tags, custom request tags, model, and provider, with budget controls per user, use case, and workspace. Every request is logged to Unity Catalog system tables with DBU costs. Dollar estimates for Databricks-hosted models require a join to list prices, while external model spend is recorded as estimated USD. Those accounting distinctions affect how a team interprets the resulting ledger.

Claude Code exposes a different part of the attribution chain through local session records at ~/.claude/projects/*/*.jsonl. Each entry records input, output, cache-creation, and cache-read tokens separately, with model identifiers and timestamps. The production pattern is to tail these files in real time and stream enriched records to a data warehouse. Local token detail is useful, but it does not replace authenticated ownership or mandatory dispatch tags.

Enforced per-user budget caps as the third layer, closing the loop from attribution to control

Attribution becomes governance only when it constrains execution. A report that one user consumed a large share of last month’s allowance cannot prevent the same concentration during the current session. That requires a budget check at the gateway before execution. The ownership contract provides the identity against which the check runs, so enforcement depends on the preceding credential and tagging layers.

Tiered alert thresholds provide notice as consumption approaches the boundary, followed by a hard session cap and a kill switch at exhaustion. The cutoff must be binding. Without per-user caps, a single outlier can exhaust shared allocations before the billing period ends, particularly where a small fraction of users or tenants accounts for most consumption.

Cost-aware routing complements these limits by selecting an inference target according to available budget headroom before execution. It changes the routing decision rather than merely recording the cost afterward. This treats model selection as a budget control instead of automatically sending every task to the highest-capability model. In an agents-as-code design, budget caps, scoped credentials, and permission boundaries are versioned with task configuration. Review then covers the authority and spending limits of an agent as well as the work assigned to it.

What the full architecture looks like across the three layers in a production deployment

A production session starts with a fresh GitHub App installation token and a delegation token containing the initiating user’s authority context. The agent has its own identity, while the invocation retains its human owner or trigger. Credentials are revoked when the session finishes. During execution, the model client holding the API key runs outside the execution sandbox, while the shell, test runner, file edits, and package manager run inside a locked-down container without long-lived secrets.

At dispatch, the request gets the required ownership metadata and passes the gateway’s budget check. Its usage records preserve cache creation, cache reads, input, and output as separate quantities for roll-up by user and project. Subsequent execution remains subject to the applicable limits, and budget headroom is checked before the next session begins. No default ownership bucket is allowed. Such a fallback would admit precisely the unattributed traffic that the credential architecture was designed to exclude.

Every tool call, file diff, and token must be attributable to the same person or trigger, so an investigation can connect consumption to the actions and code changes within the run. The user_id, feature, deployment, and agent_run_id fields also connect cost analysis with audit evidence. These records support SOC 2 assessments and Article 12 logging needs, rather than turning a collection of usage charts into a claim of compliance.

A managed platform can supply the credential, tagging, and enforcement layers as default infrastructure, avoiding the ongoing operational work of building all three in-house. In this design, agents are YAML configuration files checked into the repository, and hard caps apply at session, developer, and time-period levels. SOC 2 Type I certification and Y Combinator backing are evaluation signals to consider alongside inspection of those controls.

Filed underObservability

More in Observability