Simple Library for OpenAI Usage
Project description
openai-usage
One usage model for every OpenAI API.
The OpenAI Python SDK reports usage in a different shape for almost every
endpoint — Chat Completions, Responses, Agents SDK, Realtime, Batch, Embeddings,
Images, Transcription. openai-usage collapses them all into a single, additive
Usage object and estimates what it costs against live model pricing.
📖 Full documentation: https://allen2c.github.io/openai-usage/
Installation
pip install openai-usage
Requires Python 3.11+.
Quickstart
from openai_usage import Usage
# Normalize usage from any OpenAI API into one shape
total = Usage()
total.add(Usage.from_openai(chat_completion.usage)) # Chat Completions
total.add(Usage.from_openai(response.usage)) # Responses API
total.add(Usage.from_openai(realtime_event.response.usage)) # Realtime
print(total.input_tokens, total.output_tokens, total.total_tokens)
# Estimate the cost against any model
print(f"${total.estimate_cost('gpt-4o'):.6f}")
What it does
- Unify —
Usage.from_openai(...)accepts Chat Completions, Responses, Agents SDK, Realtime, Batch, Embeddings, Images, Transcription, and Assistants run usage. - Aggregate —
Usage.add()accumulates requests, tokens, and per-modality detail (cached, reasoning, audio, image, text) across calls. - Estimate —
Usage.estimate_cost()prices usage against any model using OpenRouter pricing, with separate rates for cached, reasoning, audio, and image tokens. - Serialize —
Usageis a Pydantic model with full backward compatibility for older payloads.
See the Supported Usage Types table for the full compatibility matrix, and Estimating Costs for pricing details and limitations.
Documentation
The docs are built with Material for MkDocs
and deployed to GitHub Pages on every push to main.
make mkdocs # serve locally at http://localhost:8000
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openai_usage-0.9.0.tar.gz.
File metadata
- Download URL: openai_usage-0.9.0.tar.gz
- Upload date:
- Size: 74.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.13 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d46bd41993feef5383166995c985c422f23e66dc585e26ea04b2e8576190029c
|
|
| MD5 |
1e350a4537dfa1ef13be20789d1dfa4d
|
|
| BLAKE2b-256 |
6f4a33f4eba01f125a493f8d546b8bfe151447d08e9aea4df83d0ab0183db65a
|
File details
Details for the file openai_usage-0.9.0-py3-none-any.whl.
File metadata
- Download URL: openai_usage-0.9.0-py3-none-any.whl
- Upload date:
- Size: 78.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.13 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa7cc5cfd32a4e446cd0032aec36c9e79c61aac8913ebc01e7eea7db33aa9a32
|
|
| MD5 |
ce0a8e4d6401668052c09ddaa87c7f34
|
|
| BLAKE2b-256 |
8f3856ba8beb082645f26fdd5fcf9cc3adfab179e2c269fba3d017d5e07bd0b6
|