Add attribution metadata
Attach customer, feature, team, and prompt metadata so every request is queryable in the dashboard.
Metadata turns each tracked call into spend you can slice by customer, feature, team, environment, and prompt version.
All fields are optional. Start with none and add them as you need dashboards and alerts.
Recommended fields
| Field | Type | Purpose |
|---|---|---|
customer_id | string | End-customer or account consuming the AI call |
feature | string | Product feature (for example search, support_agent) |
team | string | Internal team owning the feature |
environment | string | production, staging, dev, and similar |
prompt_key | string | Prompt template identifier |
prompt_version | string | number | Prompt version (1, beta, 2.1) |
session_id | string | Groups one conversation for content capture |
turn_id | string | Groups one turn across tool round-trips |
| Any other key | string | Stored as a custom tag |
Where to set it
- Wrap-time defaults apply to every call on that client.
- Per-call overrides win for a single request.
- Trace / context helpers apply across a block or function.
Precedence is per-call > trace/context > wrap-time defaults.
Python
client = sp.wrap(OpenAI(), metadata={
"feature": "doc_summary",
"environment": "production",
})
with sp.metadata(customer_id="cust_acme_123"):
client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Summarize this"}],
)sp.metadata() is the recommended per-call override. It works on every wrapped provider and never touches the HTTP body, so provider validators cannot reject it.
TypeScript
const openai = wrap(new OpenAI(), {
metadata: { feature: "support_agent", environment: "production" },
});
await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello" }],
spMetadata: { customer_id: "cust_acme_123" },
});The wrapper strips spMetadata / sp_metadata before forwarding the request to the provider.
Why this matters
Native provider tags are incomplete across vendors: different schemas, soft limits, and units that are not dollars. SuperPenguin uses one structured metadata schema across providers and normalizes estimated cost to USD for dashboards and alerts. See Attribution.