Skip to main content
https://img.shields.io/badge/chatGPT-74aa9c.svg?logo=openai https://img.shields.io/pypi/pyversions/setuptools.svg

OpenAI Cost Logger

  • Simple cost logger for OpenAI requests.

  • Track the cost of every request you make to OpenAI and visualize them in a user-friendly way.

  • Homepage on PyPI.

  • Demo file with a usage example.

How to install:

  • pip install openai-cost-logger
  • from openai_cost_logger import OpenAICostLogger
    from openai_cost_logger import OpenAICostLoggerViz
    from openai_cost_logger import OpenAICostLoggerUtils
    from openai_cost_logger import OpenAICostLogger_Singleton
    from openai_cost_logger import DEFAULT_LOG_PATH, MODELS_COST

Key Features:

  • Track the cost of every request you make and save them in a JSON file.

  • Choose the feature you want to track (prompt_tokens, completion_tokens, completion, prompt, etc.).

  • Check the cost of your requests filtering by model or strftime aggregation (see the docs).

Models supported:

  • The generation of responses is totally up to the user. The library supports every model whose response contains the fields usage.prompt_tokens and usage.total_tokens (e.g. chat completions, embeddings, etc.).

Multithreading:

  • Be aware that the classic cost logger is not thread-safe.

  • If you want to use it in a multithreading environment, you should use the thread-safe version of the logger: OpenAICostLogger_Singleton. The interface is the same as the classic logger. This will prevent multiple threads from writing to the same file at the same time.

Note:

  • Every cost is specified per million tokens.

  • If you don’t specify the cost, the library will look to the MODELS_COST dictionary and get the cost of the model you are using. Be aware that if the model is not in the dictionary, an exception will be raised.

Viz example:

Viz example (prints + plot)

Metadata

Release files for openai-cost-logger 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai-cost-logger 0.5.1
File Size Uploaded
openai-cost-logger-0.5.1.tar.gz 7.8 kB Details

Release files / openai-cost-logger-0.5.1.tar.gz

Download URL openai-cost-logger-0.5.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
768ed1e7470d4eadff0e75f9a54c82bd7d29521d34ac0a495f4ff193bfbd7b7a
BLAKE2b-256 checksum
How to use checksums
1a7b539891456e444e4b7bc4370dee4e5e6364687660f4e2ae95d3101969ea36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.5.1 This release

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page