OpenAI Usage and Costs
Retrieve OpenAI usage and cost data for organization-level reporting inside AITracer.
AITracer primarily tracks cost at the trace level.
For teams that need broader financial reporting, OpenAI also provides organization-level usage and cost APIs that can be used alongside AITracer trace records.
This allows teams to compare:
- trace-level execution costs
- organization-wide OpenAI spend
- model allocation trends
- project-level usage patterns
- cost anomalies across teams and workflows
AITracer can ingest this data and map it back to internal action groups, workflows, or business units.
Usage API
Use the OpenAI Usage API to retrieve model consumption data across your organization.
What it returns
- input tokens
- output tokens
- cached tokens
- audio tokens
- request volume
- project IDs
- user IDs
- model usage distribution
- API key attribution
Retrieval workflow
- Create an OpenAI Admin API key
- Request
/v1/organization/usage/completions - Provide a
start_timeUnix timestamp - Use
bucket_widthsuch as1dfor daily aggregation - Use
group_by=["model", "project_id"]when analyzing model distribution
import os
import time
import requests
headers = {
"Authorization": f"Bearer {os.environ['OPENAI_ADMIN_KEY']}"
}
params = {
"start_time": int(time.time()) - (30 * 24 * 60 * 60),
"bucket_width": "1d",
"group_by": ["model", "project_id"],
"limit": 7,
}
response = requests.get(
"https://api.openai.com/v1/organization/usage/completions",
headers=headers,
params=params,
)
response.raise_for_status()
usage_data = response.json()["data"]Costs API
Use the OpenAI Costs API to retrieve organization-level billing totals.
What it returns
- total spend
- currency values
- line items
- project IDs
- billing buckets
Retrieval workflow
- Request
/v1/organization/costs - Use the same
start_timewindow - Aggregate daily, weekly, or monthly cost buckets
- Compare total spend against AITracer trace-level cost records
costs = requests.get(
"https://api.openai.com/v1/organization/costs",
headers=headers,
params={
"start_time": params["start_time"],
"bucket_width": "1d",
"limit": 30
},
)
costs.raise_for_status()
cost_data = costs.json()["data"]How AITracer uses this data
This data can be joined with AITracer records to answer broader operational questions:
- Which teams consume the most model resources?
- Which workflows generate the highest spend?
- Are trace-level costs aligned with provider billing totals?
- Are specific models driving abnormal spending patterns?
This helps organizations move beyond simple prompt-level cost tracking into broader financial governance.
Never hardcode OpenAI Admin API keys.
Use environment variables, secret managers, or secure credential storage.