This project provides a simple tool to help users make informed decisions about whether to opt for the ChatGPT API or a monthly subscription. By analyzing your ChatGPT previous usage data, it calculates and visualizes token consumption and associated costs, offering valuable insights for cost-effective decision-making.
- Token counting using OpenAI's official tokenizer
- Monthly and cumulative token usage visualization
- Cost calculation based on current API pricing
- Comparative analysis between API usage and subscription costs
- Easy-to-read graphs for quick decision-making
Here's an example of the visualization produced by this tool:
This graph shows monthly token usage and associated costs, helping you visualize your ChatGPT usage patterns over time.
- Clone this repository:
git clone https://github.com/riparise/chatgpt-api-cost-calculator.git cd chatgpt-api-cost-calculator
- Install the required dependencies:
pip install -r requirements.txt
-
Export your ChatGPT data:
- Go to ChatGPT Data Controls
- Click on "Export data"
- Download and extract the zip file
-
Copy the
conversations.json
file to the./conversation
directory in this project. -
Run the script:
python main.py
Alternatively, you can use your favorite IDE to run the script.
-
The script will generate two graphs:
- Monthly token usage and cost
- Cumulative token usage and cost
-
Use these visualizations to compare your usage patterns with the cost of a monthly subscription and make an informed decision.
You can adjust the COST_INPUT_TOKEN
, COST_OUTPUT_TOKEN
and image processing costs in the script to reflect current API pricing or to perform what-if analyses. The
most current pricing information can be found on the OpenAI pricing page.
Contributions to improve the calculator or extend its functionality are welcome. Please feel free to submit pull requests or open issues for discussion.
This project is open-source and available under the MIT License. See the LICENSE file for more details.
This tool provides estimates based on your usage data and current pricing information. Always refer to OpenAI's official pricing and terms for the most up-to-date and accurate information when making decisions about API usage or subscriptions.
- This project uses the
tiktoken
library provided by OpenAI for accurate token counting. - Thanks to the open-source community for inspiration and support.