> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensorcost.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Attribution

> Tag each call with the customer, feature, team, agent and run it was for, so spend can be split and capped.

Spend is only as useful as what it is attributed to. Every field below is optional. Set defaults once when you wrap the client, and override them per call.

| Field | Node.js option | Python argument | Shows up as |
| - | - | - | - |
| Customer | `customer` | `customer` | Cost per customer in **Spend › Customers** |
| Feature | `feature` | `feature` | Cost per feature |
| Team | `teamId` | `team_id` | Team spend and chargeback; also selects the team's compliance profile |
| Agent | `agentId` | `agent_id` | Spend per agent |
| Run | `workflowId` | `workflow_id` | One agent run, and the run caps set in **Authority › Limits** |
| Application | `application` | `application` | Spend by application |
| Tags | `tags` | `tags` | Spend by tag |
| Environment | `environment` | `environment` | Environment label |
| Release | `deployment` | Node.js only | Spend by release |
| Prompt template | `promptTemplateId` | Node.js only | Spend by prompt template |

Each field also has an environment variable, `TENSORCOST_` plus the name in capitals (for example `TENSORCOST_CUSTOMER`); see [SDKs](https://docs.tensorcost.com/developers/sdk.md).

## Per call

Defaults go on `wrap()`. For values that change per request, such as the customer or the run, use `withMeta()` in Node.js or `with_meta()` in Python.

```ts Node.js theme={null}
const client = wrap(new OpenAI(), { agentId: "support-bot" });

await client
  .withMeta({ workflowId: crypto.randomUUID(), customer: "acme", feature: "ticket-triage" })
  .chat.completions.create({ model: "gpt-4o-mini", messages });
```

```python Python theme={null}
client = wrap(OpenAI(), agent_id="support-bot")

client.with_meta(
    workflow_id="ticket-48291", customer="acme", feature="ticket-triage"
).chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Summarize this ticket"}],
)
```

`withMeta()` works on OpenAI and Anthropic clients. Bedrock and Vertex clients take the defaults set on `wrap()`.

## Runs and caps

A run is a series of calls that share a `workflowId`. Give every run its own id and TensorCost can show it as one unit, apply a run cap, and let an operator stop it. A run that reaches its cap is refused with `RUN_BUDGET_EXCEEDED` where your workspace has enforcement for that layer; see [Limits](https://docs.tensorcost.com/control/limits.md).

Whether a run can be stopped or capped depends on the layer. At `govern` the SDK asks TensorCost before each call, and at `steer` and `route` the call goes through the proxy. In both, an operator's stop refuses the call before the provider is billed. A run cap refuses it only when your workspace has enforcement for that layer; otherwise the cap is recorded but the call goes through. At `observe` nothing asks first, so a cap is recorded but cannot stop the next call. See [Control layers](https://docs.tensorcost.com/developers/control-layers.md).

## Environment is set by the key

The environment of an SDK call comes from the SDK key's own environment. The `environment` option does not override it, which keeps a development key from posting into production.

## Without the SDK

The same fields travel as headers on the [proxy](https://docs.tensorcost.com/developers/proxy.md) (`x-tc-customer`, `x-tc-feature`, `x-tc-agent-id`, `x-tc-workflow-id`, `x-tc-team-id`, `x-tc-application`, `x-tc-tags`) and as span attributes through [OpenTelemetry](https://docs.tensorcost.com/developers/opentelemetry.md). On the proxy, a team-bound key's team wins over the header.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.