Prompt
How do I monitor spend by app or project for LLM usage?
Latest observation
Oct 10, 2026
OpenAI APIWeb search: off
To monitor LLM spend by app or project, the best approach is to combine request-level metadata with usage/cost aggregation.
1) Tag every request with app/project identifiers
When you send a request to the model API, include metadata such as:
app_nameproject_nameenvironment(prod/staging/dev)teamuser_idortenant_idif relevant
If your provider supports custom metadata fields or request tags, use those. If not, add the tags in your own application logs.
2) Log usage per request
For each LLM call, capture:
- timestamp
- model name
- input token count
- output token count
- total token count
- request ID
- app/project tags
Example log record:
{
"timestamp": "2026-10-10T12:34:56Z",
"app_name": "support-bot",
"project_name": "customer-care",
"model": "gpt-4.1",
"input_tokens": 1200,
"output_tokens": 300,
"request_id": "req_123",
"environment": "prod"
}
3) Convert tokens into cost
Multiply tokens by the model’s pricing:
- input token rate
- output token rate
Then aggregate by:
- app
- project
- team
- environment
- day/week/month
4) Use dashboards and cost reports
Push these logs into a monitoring/analytics tool such as:
- Datadog
- Grafana / Prometheus
- BigQuery / Snowflake
- Elasticsearch / OpenSearch
- OpenTelemetry-based observability pipelines
Build charts for:
- spend by app
- spend by project
- spend by model
- token usage trend
- average cost per request
- top expensive endpoints
5) Set budgets and alerts
Create alerts for:
- daily spend over threshold
- unexpected spikes in token usage
- high-cost model usage in non-prod
- unusually long prompts or responses
6) If your provider offers billing tags or organization usage reports
Some LLM providers expose usage data grouped by API key, project, or org. If available, use:
- project-scoped API keys
- separate keys per app/environment
- billing exports
- usage APIs
- cost allocation tags
This makes reporting much easier.
Recommended setup
If you want something practical and reliable:
- Assign a unique API key per app/project/environment
- Log every request with app/project tags
- Store token counts and model name
- Join logs with pricing data
- Build a daily cost dashboard
- Add alerts for unusual spend
If you want, I can also give you:
- a sample database schema for tracking LLM spend,
- a Python/Node middleware example that logs cost per request,
- or a dashboard design for app/project spend monitoring.