How do I attribute LLM costs by feature and team?
Add X-Cost-Feature and X-Cost-Department headers to your LLM API calls. See per-feature and per-team AI spend breakdown in real time.
Pass X-Cost-Feature and X-Cost-Department headers on your Cognocient proxy calls. Every attributed call appears in your dashboard broken down by feature and team — no code changes beyond adding the headers.
Start here — 2 headers unlock 80% of the value
You don't need to add every header on day one. These two are all you need to unlock the most useful dashboards:
| Header | What it does | Example |
|---|---|---|
X-Cost-Feature | Tags the product feature making the call | chatbot, search, pdf-extractor |
X-Cost-Department | Tags the team or business unit | engineering, customer-success, sales |
Add them now, see results immediately.
Set it once at the client level
Instead of adding headers to every call, set them once when you create the client. Every call from that client is tagged automatically — no per-call code changes needed.
What you'll see after tagging
Within seconds of your first tagged call, the dashboard updates:
| Before headers | After headers |
|---|---|
| Total AI spend: $12,400 — no breakdown | chatbot: $5,200 |
| No idea which feature is expensive | search-summariser: $4,800 |
| Can't do chargebacks | pdf-extractor: $2,400 |
The Spend by Feature and Spend by Department charts light up automatically. No configuration required.
Naming conventions
Use lowercase hyphen-separated names. Cognocient aggregates by exact string match.
If you have multiple services, tag each one at the client level with its own feature name. This gives you automatic per-service cost breakdown with zero per-call overhead.
Add more context when you're ready
The next two headers that deliver the most value:
Track individual users — X-Cost-User
Pass an internal user ID (never raw email or PII). Unlocks the Users tab showing your most expensive users and cost-per-user trends.
Track conversations — X-Cost-Session
Pass a unique ID for each conversation or task. Unlocks the Sessions tab showing total cost per conversation, turn count, and context growth.
X-Cost-Session is also how you connect AI spend to JIRA tickets and GitHub PRs. See Workstream Attribution below.
What attribution headers does Cognocient support?
All headers are optional. Use what's relevant to your product.
| Header | What it tags | Dashboard it unlocks |
|---|---|---|
X-Cost-Feature | Product feature name | Spend by Feature chart |
X-Cost-Department | Team or business unit | Spend by Department chart, chargebacks |
X-Cost-User | Internal user ID | Users tab — top spenders, cost trends |
X-Cost-Session | Conversation or task ID | Sessions tab, Workstreams tab |
X-Cost-GL-Account | General Ledger account code | FOCUS 1.1 export, accounting integration |
X-Cost-Run-ID | Single agent execution ID | Per-run budget isolation |
X-Cost-Workload | agentic-write or agentic-read | Controls budget enforcement behaviour |
X-Cost-Project | Time-bounded project name | Project spend tracking |
X-Cost-Outcome | Business outcome achieved | Cost/Outcome ROI dashboard |
GL account tagging — for finance teams
Add X-Cost-GL-Account to route AI spend to specific cost centres in your accounting system. The value appears as-is in the FOCUS 1.1 export, so your accounting team can reconcile without any mapping.
Workstream attribution — tie spend to JIRA tickets and PRs
Use X-Cost-Session with your ticket or PR ID to see exactly how much AI spend each story or PR generated.
The Workstreams dashboard shows each session with total cost, call count, duration, and models used:
| Workstream | Feature | Total Cost | Calls | Duration |
|---|---|---|---|---|
| JIRA-2341 | chatbot | $12.40 | 847 | 3d 2h |
| pr-892 | search | $4.20 | 47 | 45m |
This answers the question your engineering manager and CFO both ask: "What work did we spend that AI budget on?"
Per-run attribution — for agent workflows
For autonomous agents that run multiple steps, pass a unique X-Cost-Run-ID for the entire execution. Cognocient tracks total spend per run. When a run exceeds its per-run budget, only that run is blocked — other concurrent runs continue normally.
Generate a fresh run_id per execution, not per call. Re-using the same run ID across different agent executions defeats per-run budget isolation.
X-Cost-Workload — control what happens when the budget runs out
| Value | On budget exceeded | Use when |
|---|---|---|
agentic-write | Hard stop (429) | Agent will write to DB, send email, or call an external API |
agentic-read | Graceful degradation — cheaper model completes the call | Agent is doing research, summarisation, or retrieval |
You don't need to set X-Cost-Workload manually if your tool names are descriptive. Cognocient infers the type: tools with create, update, delete, send, or write in the name are treated as agentic-write. Everything else is agentic-read. Set the header to override.
ROI tracking — X-Cost-Outcome
Add X-Cost-Outcome on calls that produce a measurable business result. This unlocks the AI Investment ROI panel on the dashboard and the Cost/Outcome view in Executive Overview.
The dashboard then shows: cost per ticket resolved, cost per contract drafted, cost per report generated — the ROI number your CFO needs.
See Outcomes & ROI for naming conventions and the full API.
Troubleshooting
No data showing up after I added headers?
- Make sure you're using your Cognocient proxy key (
sk-cog-...), not your OpenAI key directly. - Make sure
base_url/baseURLpoints tohttps://api.cognocient.com/v1. - Check the Live Calls tab (
/calls) — your call should appear there within seconds. If it does, the headers are working. Dashboard charts update within a few minutes.
Feature names showing up inconsistently?
Attribution is case-sensitive and exact-match. Chatbot and chatbot are different features. Pick a convention (lowercase-hyphen) and stick to it.
Next steps: Waste Detection · Budget Enforcement · MCP/A2A Attribution
Related articles