Cost Tutorials
How to Attribute LLM Spend to Application Features
To attribute LLM spend to application features, assign a stable feature key and application request ID before each workflow calls a model. Record each provider attempt and capture any response ID or usage the provider returns. Estimate spend by feature from those records, then compare the rolled-up results with OpenAI and Anthropic reports at the reporting dimensions they expose. Keep any balance you cannot explain visible.
Carry feature ownership through every model call
OpenAI Chat Completions documents a response id and a usage object. OpenAI Chat Completions reference OpenAI’s organization reporting reference describes grouped usage and cost results. OpenAI Usage and Costs reference For Claude, Anthropic documents the Messages response ID. Anthropic Messages reference Its legacy reports support workspace grouping. Anthropic legacy Usage and Cost API Link response IDs to application events, then use the reporting dimensions to compare totals.
Set the feature key where the application knows what the user is doing. A support workflow can pass support_reply into a shared model client, while a document workflow passes document_summary into the same client. Carry the application request ID and feature key into queued work so background model calls stay linked to the action that started them. Stable feature keys keep historical reports comparable when display names change.
| Ledger field | What to capture | Purpose |
|---|---|---|
feature_key, app_request_id | The owning workflow and its application request ID | Roll up by feature and inspect the calls behind a workflow |
attempt_id, outcome | An internal ID and result for each outbound attempt | Distinguish a retry from a duplicate event for the same call |
provider, provider_response_id | The provider and returned object ID, when available | Locate the response for an individual attempt |
occurred_at, provider_scope | The call timestamp and the project or workspace used | Map local records to the matching provider report scope and time window |
model, usage, usage_status | The model, reported quantities, and whether usage was captured | Calculate an estimate and surface gaps in collection |
Create the attempt record before sending the request. Update it by attempt_id when the response or error arrives, and record each separately issued retry under the same application request. If an attempt ends without usage, mark it as missing and carry that status into the feature report. Use an explicit unassigned feature value for traffic whose owner is unknown.
Capture response usage and keep provider IDs intact
For OpenAI Chat Completions, save id and the documented usage fields prompt_tokens, completion_tokens, and total_tokens when available. OpenAI Chat Completions reference For streaming, set stream_options.include_usage to true to request a final usage chunk. An interrupted or cancelled stream may end before that chunk arrives. OpenAI Chat Completions reference If the chunk never arrives, retain any response ID you captured and mark usage as missing.
For Claude Messages, save the msg_... response ID alongside the local attempt ID when it is available. Anthropic Messages reference Preserve the usage object when captured. Anthropic’s Messages reference lists cache creation and cache read fields in the usage schema. Anthropic Messages reference Anthropic’s legacy usage guide describes reporting for uncached input, cached input, cache creation, and output tokens. Anthropic legacy Usage and Cost API Keep the provider’s usage categories so you can compare them with the corresponding report fields.
Keep the application request ID, provider response object ID, and any transport request ID your integration captures in separate fields. Record them together so an engineer can look up an attempt with whichever identifier they have. To estimate cost, apply the applicable rate to each usage category and retain the rate version with the result. ByteCosts guide to calculating LLM API cost
Add feature tags to request traces with Helicone
In its March 2023 Launch HN post, Helicone introduced its OpenAI logging tool as a proxy and described logging prompts, completions, latencies, and costs. Helicone’s March 2023 Launch HN post Helicone’s Custom Properties documentation describes grouping requests for feature-level cost analysis with headers in the Helicone-Property-[Name] format. Helicone Custom Properties documentation
For calls sent through Helicone, set Helicone-Property-Feature to the same value stored in feature_key. To link a trace back to an application request, add a property such as Helicone-Property-App-Request-Id with your opaque application ID. Helicone Custom Properties documentation Use that identifier for lookup and the stable feature property for aggregation. Helicone also documents a reserved Helicone-User-Id property for per-user analytics. Helicone Custom Properties documentation
Anthropic’s Messages reference separately documents metadata.user_id as an external user identifier and asks callers to use an opaque value without identifying information. Anthropic Messages reference Keep user identity and feature ownership in separate fields, since one user can use several features.
Compare local totals with provider usage and cost reports
Import usage and cost data separately. Before comparing request-derived estimates with provider totals, match the time window, account scope, and product coverage. Retain the provider’s original units and scope keys on import so you can reproduce a comparison when a report is refreshed.
| Provider | Usage report | Cost report | Scope to compare |
|---|---|---|---|
| OpenAI | GET /organization/usage/completions documents grouped results with fields including project, API key, and model. OpenAI Usage and Costs reference | GET /organization/costs documents grouped results with fields including project and line item. OpenAI Usage and Costs reference | Use project as a common scope and preserve cost line items for review. |
| Anthropic legacy Admin API | /v1/organizations/usage_report/messages supports grouping by dimensions including workspace, model, and service tier. Anthropic legacy Usage and Cost API | /v1/organizations/cost_report reports daily USD costs in cents, supports grouping by workspace and description, and excludes Priority Tier costs. Anthropic legacy Usage and Cost API | Use workspace as a common scope and track Priority Tier usage separately. |
Anthropic labels those Admin API endpoints as legacy and directs new integrations to its Usage and Cost Analytics API. Anthropic legacy Usage and Cost API
Aggregate local usage and estimated costs by provider scope and report window. Compare usage quantities first, then compare cost totals. Check which token categories and calls each side covers. For example, OpenAI’s organization reference lists separate usage endpoints for completions and embeddings. OpenAI Usage and Costs reference If an application feature uses both, compare only the matching local calls against completions usage.
Keep the local estimate, provider-reported amount, and difference visible. Before assigning a difference to a feature, investigate missing response usage, untagged work, and line items outside the application ledger. If the team allocates shared costs, document the rule and show the result as an allocation. ByteCosts guide to usage receipts and invoices
Follow a support request through the ledger
In this illustrative setup, a support reply and a document summary share an OpenAI project. A support action starts under support_reply. Its application request ID stays the same when the worker retries a call, while each outbound attempt gets a distinct attempt ID. The first attempt ends without captured usage. The retry returns usage, so the feature report includes an estimate for the retry and flags the first attempt for review. The document summary follows the same path under document_summary.
At the end of the reporting window, add the local estimates for both features when comparing with the project total. If the project report contains a balance the application ledger cannot explain, leave it at project level until there is evidence for an assignment. Project grouping is documented in OpenAI’s organization cost results. OpenAI Usage and Costs reference
Before using feature totals in a dashboard, replay a completed call, a retry, and an interrupted stream. Check that duplicate deliveries update the same attempt, missing usage stays visible, and each feature’s rows roll up to the scope used in the comparison. If the team also tracks revenue and usage by customer, use attributable customer costs as inputs to the ByteCosts per-user margin calculator.
Sources
- Launch HN: Helicone.ai, open-source logging for OpenAI (Helicone on Hacker News, March 23, 2023)
- Custom Properties (Helicone, documentation snapshot November 30, 2026)
- Usage and Costs API reference (OpenAI, documentation snapshot November 30, 2026)
- Chat Completions API reference (OpenAI, documentation snapshot November 30, 2026)
- Usage and Cost API, legacy (Anthropic, documentation snapshot November 30, 2026)
- Messages API reference (Anthropic, documentation snapshot November 30, 2026)
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
How to Attribute LLM Spend to Application Features. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/attribute-llm-spend-to-features/