Skip to main content

Easily check the current costs of OpenAI's GPT and ChatGPT models.

Project description

openai-pricing

================

This repository hosts an unofficial library for OpenAI pricing calculations. Its purpose is to simplify the prediction of costs when using GPT models. The data is obtained from https://gptforwork.com/tools/openai-chatgpt-api-pricing-calculator.

Library usage


The module provides just one class, OpneAIPricing, which loads the pricing data when instanced and answers about max tokens and costs per tokens (prompt and completion tokens).

Currently, it supports the following models:

  • GPT-4 32k
  • GPT-4
  • GPT-3.5 16k
  • GPT-3.5
  • Davinci
  • Curie
  • Babbage
  • Ada

This list can be obtained by calling OpenAIPricing.list_available_models().

Example


from openai_pricing import OpenAIPricing

p = OpenAIPricing()

p.list_available_models()


model = 'gpt-4-32k'
tokens = 1000 # default value for tokens is 1000 


model_name = p.model_name(model) # get model name

max_tokens = p.get_max_tokens(model) # get the max tokens for a model 

price_prompt = p.get_price(model, type='prompt', tokens=1000) # get the current price per 1,000 tokens in prompt 

price_completion = p.get_price(model, type='completion', tokens=1000) # get the current price per 1,000 tokens in completion  


print('The model', model_name)

print('accepts up to', max_tokens,'tokens.')

print('It costs $', price_prompt,'per 1,000 prompt tokens')

print('and $', price_completion, 'per 1,000 completion tokens.')

# Get an average price per requests with  "p.get_price(model, type='both')". "both" is the default value for the "type" argument and 1000 is the default value for the "tokens" argument.
print('The average value for request is', p.get_price(model, type='both'),'per 1,000 tokens (500 tokens in prompt and 500 pormpt in completion.')

Output:

+--------------+-------------------+
| Model name   | Technical name    |
|--------------+-------------------|
| GPT-4 32k    | gpt-4-32k         |
| GPT-4        | gpt-4             |
| GPT-3.5 16k  | gpt-3.5-turbo-16k |
| GPT-3.5      | gpt-3.5-turbo     |
| Davinci      | text-davinci-003  |
| Curie        | text-curie-001    |
| Babbage      | text-babbage-001  |
| Ada          | text-ada-001      |
+--------------+-------------------+
The model GPT-4 32k
accepts up to 32768 tokens.
It costs $ 0.06 per 1,000 prompt tokens
and $ 0.12 per 1,000 completion tokens.
The average value for request is 0.09 per 1,000 tokens (500 tokens in prompt and 500 pormpt in completion.

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-pricing-1.1.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openai_pricing-1.1.3-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file openai-pricing-1.1.3.tar.gz.

File metadata

  • Download URL: openai-pricing-1.1.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.0

File hashes

Hashes for openai-pricing-1.1.3.tar.gz
Algorithm Hash digest
SHA256 f2625ccd94068d2179cc21b538660788f61b5191002410622ac94393c97677f0
MD5 190f2098788da1f28bc269c15f29f753
BLAKE2b-256 19baf14a2359a61c21bedf5cddfe651f437eea724c34e164e036ca707faa5fd3

See more details on using hashes here.

File details

Details for the file openai_pricing-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: openai_pricing-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.0

File hashes

Hashes for openai_pricing-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cd250898a3edd82e26c13095bb478269b77c3fa20a9f292a8ba52cad0c40582e
MD5 a8f789ebc11c2abd34377cd1123691d9
BLAKE2b-256 493d15fcd46b0d33d72b2d3e5297c054002639934673b84d6a01ec58e6055622

See more details on using hashes here.

Supported by

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