Add OpenAI API billing
This page shows you how to let Prism read what your organisation spends on the OpenAI API.
OpenAI reports two things for each day: what you were billed, broken down by model, kind of token and project, and how many tokens each project and API key used. Prism copies both, and the list of your projects, so it can name them.
When you finish, people can ask Prism questions like these:
- "What did we spend on the OpenAI API per day over the last 14 days?"
- "Which OpenAI projects cost the most in the last 30 days?"
- "Which models used the most output tokens in the last 30 days?"
It takes about 15 minutes. You do it once.
Before you start
You need three things.
1. You must be a Prism admin. If you can see Admin in Prism's menu, you are one.
2. An owner of your OpenAI organisation. Only an organisation Owner can make the key Prism needs. Members cannot see the page.
3. An Admin key. This is a key for the whole organisation. It starts with
sk-admin-. To make one, the OpenAI owner:
- Opens
platform.openai.com. - Goes to Settings, then Organization, then Admin keys.
- Clicks Create new admin key, and names it something like
prism-billing. - Copies the key. OpenAI shows it only once.
An ordinary project key (sk-proj-…) does not work. OpenAI refuses it for
billing reports. You do not choose a project: an Admin key covers all of
them, and Prism reports spend per project.
What the key can do. An Admin key can also manage your organisation's users, projects and keys. Prism only reads with it, and keeps it encrypted. Treat it like any other admin password.
Step 1: Open the page
- Open Prism.
- Click Admin.
- Click Context streams.
A context stream is one kind of data Prism can answer questions about.
Step 2: Choose OpenAI API billing
- Click Add a context stream.
- Find the tile called OpenAI API billing.
- Click Use on that tile.
A form opens. Its title is Register "OpenAI API billing".
Step 3: Fill in the form
name. Type:
openai_billing
label. This is the name people see in answers. Type:
OpenAI API billing
api_url. Leave it as it is. It already says https://api.openai.com.
backfill_days. This is how many days of past billing Prism reads the first
time. Leave it as 90.
cost_group_by and usage_group_by. Leave them as they are.
max_requests_per_minute. Leave it as 30.
secret. This is the Admin key. Paste it into this box. The box hides what you type. That is normal.
Step 4: Register
- Click Register.
- Wait a few seconds. Prism checks the key with OpenAI.
If it worked, you see OpenAI API billing in the list of context streams.
If the key is wrong, you see a message, and a button that says Store the
credential for openai_billing. Check that you pasted the whole key, and that
it starts with sk-admin-. Then paste it again and click that button.
Step 5: Turn it on
Find OpenAI API billing in the list. Then:
- Click Approve.
- Click Enable.
Prism starts reading within 15 minutes. The first read of 90 days takes a few minutes.
Step 6: Check that it worked
Wait about half an hour. Then ask Prism this question, exactly as written:
What did we spend on the OpenAI API per day over the last 14 days?
It worked if you get an amount for each day, today included.
To be sure, compare it with OpenAI:
- On
platform.openai.com, open Usage. - Pick the same 14 days.
- Prism's amount for each day before today should match OpenAI's.
Today's amount keeps growing. OpenAI reports the day in progress as the amount so far, so Prism's figure for today is the spend up to its last read. It is final after midnight UTC.
It did not work if Prism says it has no data. Go to "If something is wrong" below.
How to undo it
To stop reading, but keep everything:
- Go to Admin, then Context streams.
- Find OpenAI API billing.
- Click Disable.
Prism stops reading new days and stops answering questions about them. The key and the settings stay. To start again, click Enable.
To remove it completely:
- Go to Admin, then Context streams.
- Find OpenAI API billing.
- Click Delete….
- Type
openai_billingin the box. - Click Delete openai_billing.
This removes the source and the stored key. Nothing at OpenAI changes. To be sure the key can never be used again, the OpenAI owner can also delete it in Settings → Organization → Admin keys.
If something is wrong
"Store the credential" keeps failing. The key is probably a project key. Ask an organisation Owner to make an Admin key as described in "Before you start".
Prism has no data. Check the source's page in Admin → Context streams. If it says the last read failed, the key may have been deleted. Make a new one and store it on the source's page.
The amounts are a little different from OpenAI's for the last few days. OpenAI revises recent days as usage is reconciled. Prism reads the last three days again every time it runs, so the difference closes by itself within a day.
What Prism reads, and what it does not
- Prism reads, for each UTC day: each billed line item (a model and a kind of token, or another billed service) and its cost in US dollars, per project.
- It reads tokens per model, per project and per API key for the chat and responses endpoints. Usage of embeddings, images, audio and moderation is not read, though their cost is in the billed amounts.
- A cost OpenAI does not attribute to a project is counted under the
project
(none). So is usage with no API key, under the key(none). - It reads each project's name and status. It does not read the names of API keys: OpenAI lists keys separately for each project.
- It does not read prompts, responses, or anything sent to a model.
- It reads the OpenAI API platform organisation only. ChatGPT Enterprise or Team seats, and OpenAI models used through Azure, are billed elsewhere and are not in these figures.
- Spend that also went through Agent Router appears in both. Never add the two together.
For your technical team
- The recipe is
components/source-manifest/manifests/preview/openai_billing.yaml(recipe keyopenai_billing). It reads the organisation Usage and Costs API:GET /v1/organization/costs,/v1/organization/usage/completionsand/v1/organization/projects. - OpenAI takes the time bounds of a report as whole seconds since 1970 and
refuses a date. The usage report also counts only the part of a day inside
the requested period while labelling it as the whole day, and the cost
report drops a day the period ends inside. So every request runs from the
midnight (UTC) before the period to the midnight after it
(
{{ window.start_day_unix }}/{{ window.end_day_unix }}), and each day is read whole. - A key column cannot be empty. A record that leaves out a key dimension
(project, API key, model, line item) is stored with
(none)in it (null_asin the recipe), so it cannot fail the run. - Cost is read a week per page (
limit: "7"). A page of 90 days, broken down by line item and project, can be larger than the 2 MiB the Manifest tab's Test reads. - The project list is read as one page of up to 100 projects, the endpoint's limit. An organisation with more projects has only the first 100 named.
- It ingests every 6 hours (
schedule: PT6H), and re-reads the last three days each time (lookback: P3D). - To read days again that OpenAI revised more than three days back, set
ingest.openai_billing.rewalkFromto the first such date (YYYY-MM-DD) and upgrade. The next run re-reads from that date, once. It applies only to a source namedopenai_billing.