Skip to main content

OpenAI Cost Logger

Project description

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 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 response generation is totally up to the user. The library support every model which response contains the fields usage.prompt_tokens and usage.total_tokens (e.g. chat completions, embeddings, etc.).

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai-cost-logger-0.4.1.tar.gz (6.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page