openai-pricing


Nameopenai-pricing JSON
Version 1.1.3 PyPI version JSON
download
home_page
SummaryEasily check the current costs of OpenAI's GPT and ChatGPT models.
upload_time2023-06-30 01:43:46
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords openai chat gpt pricing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
-----------

```shell
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:

```shell
+--------------+-------------------+
| 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.
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "openai-pricing",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Pedro Dupim <pedrodupim@icloud.com>",
    "keywords": "openai,chat gpt,pricing",
    "author": "",
    "author_email": "Pedro Dupim <pedrodupim@icloud.com>",
    "download_url": "https://files.pythonhosted.org/packages/19/ba/f14a2359a61c21bedf5cddfe651f437eea724c34e164e036ca707faa5fd3/openai-pricing-1.1.3.tar.gz",
    "platform": null,
    "description": "# openai-pricing\r\n================\r\n\r\nThis 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.\r\n\r\n##  Library usage\r\n-----------------\r\n\r\nThe 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).\r\n\r\nCurrently, it supports the following models:\r\n\r\n- GPT-4 32k\r\n- GPT-4\r\n- GPT-3.5 16k\r\n- GPT-3.5\r\n- Davinci\r\n- Curie\r\n- Babbage\r\n- Ada\r\n\r\nThis list can be obtained by calling `OpenAIPricing.list_available_models()`.\r\n\r\n### Example\r\n-----------\r\n\r\n```shell\r\nfrom openai_pricing import OpenAIPricing\r\n\r\np = OpenAIPricing()\r\n\r\np.list_available_models()\r\n\r\n\r\nmodel = 'gpt-4-32k'\r\ntokens = 1000 # default value for tokens is 1000 \r\n\r\n\r\nmodel_name = p.model_name(model) # get model name\r\n\r\nmax_tokens = p.get_max_tokens(model) # get the max tokens for a model \r\n\r\nprice_prompt = p.get_price(model, type='prompt', tokens=1000) # get the current price per 1,000 tokens in prompt \r\n\r\nprice_completion = p.get_price(model, type='completion', tokens=1000) # get the current price per 1,000 tokens in completion  \r\n\r\n\r\nprint('The model', model_name)\r\n\r\nprint('accepts up to', max_tokens,'tokens.')\r\n\r\nprint('It costs $', price_prompt,'per 1,000 prompt tokens')\r\n\r\nprint('and $', price_completion, 'per 1,000 completion tokens.')\r\n\r\n# 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.\r\nprint('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.')\r\n```\r\n\r\nOutput:\r\n\r\n```shell\r\n+--------------+-------------------+\r\n| Model name   | Technical name    |\r\n|--------------+-------------------|\r\n| GPT-4 32k    | gpt-4-32k         |\r\n| GPT-4        | gpt-4             |\r\n| GPT-3.5 16k  | gpt-3.5-turbo-16k |\r\n| GPT-3.5      | gpt-3.5-turbo     |\r\n| Davinci      | text-davinci-003  |\r\n| Curie        | text-curie-001    |\r\n| Babbage      | text-babbage-001  |\r\n| Ada          | text-ada-001      |\r\n+--------------+-------------------+\r\nThe model GPT-4 32k\r\naccepts up to 32768 tokens.\r\nIt costs $ 0.06 per 1,000 prompt tokens\r\nand $ 0.12 per 1,000 completion tokens.\r\nThe average value for request is 0.09 per 1,000 tokens (500 tokens in prompt and 500 pormpt in completion.\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Easily check the current costs of OpenAI's GPT and ChatGPT models.",
    "version": "1.1.3",
    "project_urls": {
        "Documentation": "https://github.com/Alo-mundo/openai-pricing/blob/main/README.md",
        "Homepage": "https://github.com/Alo-mundo/openai-pricing",
        "Repository": "https://github.com/Alo-mundo/openai-pricing.git"
    },
    "split_keywords": [
        "openai",
        "chat gpt",
        "pricing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "493d15fcd46b0d33d72b2d3e5297c054002639934673b84d6a01ec58e6055622",
                "md5": "a8f789ebc11c2abd34377cd1123691d9",
                "sha256": "cd250898a3edd82e26c13095bb478269b77c3fa20a9f292a8ba52cad0c40582e"
            },
            "downloads": -1,
            "filename": "openai_pricing-1.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a8f789ebc11c2abd34377cd1123691d9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 3063,
            "upload_time": "2023-06-30T01:43:44",
            "upload_time_iso_8601": "2023-06-30T01:43:44.391588Z",
            "url": "https://files.pythonhosted.org/packages/49/3d/15fcd46b0d33d72b2d3e5297c054002639934673b84d6a01ec58e6055622/openai_pricing-1.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19baf14a2359a61c21bedf5cddfe651f437eea724c34e164e036ca707faa5fd3",
                "md5": "190f2098788da1f28bc269c15f29f753",
                "sha256": "f2625ccd94068d2179cc21b538660788f61b5191002410622ac94393c97677f0"
            },
            "downloads": -1,
            "filename": "openai-pricing-1.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "190f2098788da1f28bc269c15f29f753",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3635,
            "upload_time": "2023-06-30T01:43:46",
            "upload_time_iso_8601": "2023-06-30T01:43:46.156008Z",
            "url": "https://files.pythonhosted.org/packages/19/ba/f14a2359a61c21bedf5cddfe651f437eea724c34e164e036ca707faa5fd3/openai-pricing-1.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-30 01:43:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Alo-mundo",
    "github_project": "openai-pricing",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "openai-pricing"
}
        
Elapsed time: 0.08852s