OpenAI cost per API key: find which key is spending
When the OpenAI bill jumps, the first question is which key did it. OpenAI can now answer that per API key, in the dashboard and through the Costs API. Here's how to pull cost per key, turn key IDs into names you recognise, get a same-day view, and what per-key data can't tell you.
Last reviewed 10 Nov 2026
The short version
- Dashboard: open the Usage dashboard and filter or group by API key (added 4 Aug 2026, per OpenAI's changelog).
- API:
GET /v1/organization/costs?group_by=api_key_idwith an Admin key returns daily cost per key ID. - Names: the cost rows only carry an ID like
key_abc; map it with the project API keys list. - Same day: the Usage API gives hourly tokens and requests per key, not dollars.
- Caps: there's no per-key spend limit. One key per project, plus a project hard limit, is the closest thing.
KeyBark checks your OpenAI, Anthropic or OpenRouter spend about every 15 minutes during the beta and emails you when it crosses a daily or monthly threshold you set, or jumps above its 7-day average. It doesn't set or enforce limits for you. Free for one key, no card.
1. In the dashboard
OpenAI's changelog entry of 4 Aug 2026 says customers can filter and group data by API key in the Usage and Costs dashboards. Per OpenAI's help article Reviewing API usage and costs (read 10 Nov 2026):
- You need to be an organization owner or have the Usage Dashboard permission.
- Dashboard data is in UTC, so line it up with your logs in UTC too.
- The dashboard has its own project selector; clear it to see the whole organization.
- If several applications share one project or key, that total can't tell you which application made a request.
2. With the Costs API
The Costs API needs an Admin API key (create one at Organization settings → Admin keys; Admin keys only work on administration endpoints, per the Admin APIs guide). Last 7 days of cost, one row per key per day:
START=$(( $(date -u +%s) - 7*86400 ))
curl -s --get https://api.openai.com/v1/organization/costs \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
--data-urlencode "start_time=$START" \
--data-urlencode "group_by=api_key_id" \
--data-urlencode "limit=7" \
| jq -r '.data[] | .start_time as $d | .results[]
| [($d|todate[:10]), (.api_key_id // "no key id"), .amount.value] | @tsv'What the reference says (read 10 Nov 2026):
- Daily buckets only:
bucket_widthsupports1dand nothing else. limitis the number of buckets, 1 to 180, default 7.start_timeis inclusive,end_timeexclusive (Unix seconds).- Results are paged: if
has_moreis true, sendpage=with thenext_pagevalue. api_key_idsnarrows the result to the keys you name, which is handy when you're checking one suspicious key.group_byalso takesproject_id,user_id,line_itemandapi_source. Addline_itemto see which model and token type the key spent on. Some combinations depend on your organization and date range, and unsupported ones return HTTP400.amount.valueis the cost in the currency named inamount.currency(e.g.usd).
Keep any rows without a key ID as “unattributed” instead of dropping them, so your per-key totals still add up to the organization total. The help article notes, for example, that Scale Tier bundle costs sit at the organization level, not in a project.
3. Turn key IDs into names
Cost rows give you api_key_id, not the name you typed when you created the key. The list project API keys endpoint returns, for each key: id, name, redacted_value (like sk-abc...def), the owner (user or service account), last_used_at and expires_at.
curl -s "https://api.openai.com/v1/organization/projects/$PROJECT_ID/api_keys?owner_project_access=any&limit=100" \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
| jq -r '.data[] | [.id, .name, .redacted_value, (.owner.user.email // .owner.service_account.name)] | @tsv'- Repeat per project (list them with
GET /v1/organization/projects) and page withafter=whilehas_moreis true. - Pass
owner_project_access=any: the reference says that without it the endpoint applies membership-based visibility rules that may leave some enabled keys out. - If an ID from the cost data isn't in any list, the key may have been deleted since. OpenAI's docs don't say how deleted or rotated keys appear in cost history, so check your own records before blaming a key.
4. A same-day view: hourly usage per key
Daily cost buckets are fine for a monthly review and slow for “is a key running away right now?”. The Usage API completions endpoint supports 1m, 1h and 1d buckets with group_by=api_key_id (and model), so you can see which key's tokens and request count spiked this morning:
curl -s --get https://api.openai.com/v1/organization/usage/completions \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
--data-urlencode "start_time=$(( $(date -u +%s) - 24*3600 ))" \
--data-urlencode "bucket_width=1h" \
--data-urlencode "group_by=api_key_id" \
--data-urlencode "group_by=model" \
--data-urlencode "limit=24"It returns tokens and num_model_requests, not dollars, and it covers completions only; images, audio, embeddings and other products have their own usage endpoints. Multiply by the model's price yourself for a rough figure, and use the Costs API for the real number.
5. What per-key cost can't do
- It isn't a limit. OpenAI's spend limits are monthly caps on the organization or a project; there's no per-key spend limit. To cap one workload, give it its own project and key, set a project spend limit and turn on Enforce a hard limit. Over it, requests get
429 project_spend_limit_exceeded(see error codes); the docs say enforcement is not instantaneous, so recorded spend can slightly pass the limit. - A shared key blends workloads. If two services use one key, the key total is exact and still can't split them. One key per service (or per environment) is what makes the breakdown useful.
- It isn't your invoice. Daily cost rows are good for allocation and trends; credits, adjustments and invoice timing are a separate question for the Billing page.
- It's after the fact. Cost data arrives in daily UTC buckets, so per-key cost tells you who spent yesterday's money, not who is spending right now.
Checklist
- Give every service and environment its own key, named so you'd recognise it in a report.
- Put workloads that need a hard ceiling in their own project with an enforced project spend limit and alert thresholds below it.
- Create a dedicated Admin key for reporting and keep it out of app code and servers that don't need it.
- Run the Costs API with
group_by=api_key_id(plusline_item) weekly, joined to the key names from step 3. - Delete keys whose
last_used_atis old, and set expiry dates on new keys. - Have something tell you the same day when spend is far above normal, instead of finding out from the daily report.
Not sure your OpenAI (and Anthropic / OpenRouter) limits would stop a leaked key or a runaway loop? The free AI key limit audit walks through them in a few minutes (no sign-up, no key needed). Related: OpenAI spend limit not working, OpenAI API key leaked, runaway AI agent cost, OpenAI spend limit API, read-only admin key for cost tools.
Where KeyBark fits (and where it doesn't)
KeyBark reads your OpenAI organization costs (with an Admin key) from our servers about every 15 minutes during the beta and emails you when a daily or monthly threshold you set is crossed, or when today's spend jumps above your 7-day average. That covers the last checklist item.
Limits, honestly: KeyBark watches the organization total today; it does not break cost down per API key or per project, and it does not set OpenAI spend limits for you. OpenAI's cost data comes in daily buckets and checks run on a schedule, so an alert can arrive after money has been spent. KeyBark is not a proxy and can't block a request. Use the per-key report above to find the key, and OpenAI's project hard limits to cap it.
FAQ
Can I see OpenAI costs per API key?
Yes. Since 4 August 2026 OpenAI's Usage and Costs dashboards can filter and group by API key, and the Costs API accepts group_by=api_key_id (and an api_key_ids filter) to return daily cost per key ID. You need an organization owner role or the Usage Dashboard permission for the dashboard, and an Admin API key for the API.
How do I turn an api_key_id into the key's name?
List each project's keys with GET /v1/organization/projects/{project_id}/api_keys using an Admin key. Each entry has the key's id, name, redacted value, owner, last_used_at and expires_at. Pass owner_project_access=any, because without it the endpoint applies membership-based visibility rules that can leave some enabled keys out.
Can I set a spend limit on a single OpenAI API key?
No. OpenAI's spend limits are monthly limits on the organization or on a project. To cap one workload, give it its own project with its own key and a project spend limit with “Enforce a hard limit” on. Requests over it get HTTP 429 project_spend_limit_exceeded, and enforcement is not instantaneous, so recorded spend can slightly pass the limit.
Why can't I see hourly cost per key?
The Costs API only supports daily buckets (bucket_width=1d). For a same-day view, the Usage API (for example /v1/organization/usage/completions) supports 1m, 1h and 1d buckets grouped by api_key_id, but it returns tokens and request counts, not dollars.
Sources (read 10 Nov 2026): OpenAI API changelog (4 Aug 2026), Costs API, Usage API (completions), List project API keys, Admin APIs, Spend limits, Error codes; OpenAI Help Center Reviewing API usage and costs. KeyBark is not affiliated with OpenAI.
KeyBark watches your OpenAI, Anthropic and OpenRouter spend from the server and flags a crossed threshold or spike by email and on your dashboard. Free for one key.