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-Run-Budget | Dollar ceiling for a run (first call sets it) | Run-level budget enforcement for concurrent multi-agent runs |
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.
When multiple subagents run concurrently within the same orchestrated task — for example, up to 16 concurrent subagents in a single Dynamic Workflows-style run — per-call budget checks alone can't catch runaway spend: each individual subagent call can look perfectly reasonable while the run as a whole vastly exceeds any sane ceiling. Cognocient closes that gap with a run-level reservation, shared across every subagent call that carries the same X-Cost-Run-ID, checked atomically before each call fires — so the run's total spend, not just any single call, is what gets enforced.
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.
Setting an explicit run budget — X-Cost-Run-Budget
Pass X-Cost-Run-Budget alongside X-Cost-Run-ID on any call in the run to declare that run's dollar ceiling. Only the first call Cognocient sees for a given run_id sets the ceiling — every later call (from any subagent, in any order) reads back that same value, so concurrent subagents that start at nearly the same instant still converge on one agreed-upon budget instead of racing to set different limits.
If an admin has already configured a per-run budget for this call's feature/department/user scope (see Hierarchical Budgets), that admin-configured ceiling takes precedence over X-Cost-Run-Budget — the header is a fallback for runs that don't fall under any configured budget, not an override.
What happens when a run hits its ceiling
Once a run's cumulative spend would exceed its ceiling, the call that would push it over is rejected with HTTP 429 — every earlier call in the run still succeeded, and calls under a different run_id are unaffected:
Default run budgets
If a run declares no X-Cost-Run-Budget and no admin-configured per-run budget matches, Cognocient still gives it a ceiling: your account's default run budget, configurable from the Run Budgets dashboard (defaults to $25). This means a run is never left unbounded just because nobody remembered to set a header.
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.
Frequently asked questions
Related articles