apikeylogger


Nameapikeylogger JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/federicoromeo/apikeylogger
SummaryThis library allows you to log the OpenAI api usage *by key* without having to change your code
upload_time2024-03-03 17:14:29
maintainer
docs_urlNone
authorFederico Romeo
requires_python>=3.6
licenseMIT
keywords openai apikey api logger tracker
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # apikeylogger

Track your *OpenAI* api usage **by key**, without any code change.

#### Installation

```bash
pip install apikeylogger
```

#### Setup
Create a *.env* file with your OpenAI *api key* and *organization id* ([find yours here](https://platform.openai.com/account/organization)), like this:
```bash
OPENAI_API_KEY = ""
OPENAI_ORG_ID = ""
```


#### Usage
```python
# This call will transparently log your API usage by key in a local json file *apikeylogs.json*
from apikeylogger import track_openai
track_openai()

# Your normal code that uses openai
from openai import OpenAI
from dotenv import load_dotenv

load_dotenv()
client = OpenAI()

response = client.chat.completions.create(
    messages = [
        {
            "role": "user",
            "content": "What is the meaning of life?",
        }
    ],
    model = "gpt-3.5-turbo-0125" # any openai model
)

print(response.choices[0].message.content)
```

#### Test

Run tests with:
```bash
pytest
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/federicoromeo/apikeylogger",
    "name": "apikeylogger",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "openai,apikey,api,logger,tracker",
    "author": "Federico Romeo",
    "author_email": "federico.romeo.98@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/83/9e/d2215ce99e282c5b5383027b1afb83841d717c9a155858562b009ece84d5/apikeylogger-1.1.1.tar.gz",
    "platform": null,
    "description": "# apikeylogger\n\nTrack your *OpenAI* api usage **by key**, without any code change.\n\n#### Installation\n\n```bash\npip install apikeylogger\n```\n\n#### Setup\nCreate a *.env* file with your OpenAI *api key* and *organization id* ([find yours here](https://platform.openai.com/account/organization)), like this:\n```bash\nOPENAI_API_KEY = \"\"\nOPENAI_ORG_ID = \"\"\n```\n\n\n#### Usage\n```python\n# This call will transparently log your API usage by key in a local json file *apikeylogs.json*\nfrom apikeylogger import track_openai\ntrack_openai()\n\n# Your normal code that uses openai\nfrom openai import OpenAI\nfrom dotenv import load_dotenv\n\nload_dotenv()\nclient = OpenAI()\n\nresponse = client.chat.completions.create(\n    messages = [\n        {\n            \"role\": \"user\",\n            \"content\": \"What is the meaning of life?\",\n        }\n    ],\n    model = \"gpt-3.5-turbo-0125\" # any openai model\n)\n\nprint(response.choices[0].message.content)\n```\n\n#### Test\n\nRun tests with:\n```bash\npytest\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "This library allows you to log the OpenAI api usage *by key* without having to change your code",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/federicoromeo/apikeylogger",
        "Source": "https://github.com/federicoromeo/apikeylogger"
    },
    "split_keywords": [
        "openai",
        "apikey",
        "api",
        "logger",
        "tracker"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f17f4c413e72412eeeaaaace510fd8414c307d5c1c2ae3d088bcf508b508546d",
                "md5": "9d528808c208cc869a307664ae2e5f7e",
                "sha256": "4ab09b3bc6104635a6d11b41c1d68011011cd4741513eff4b78f1a232fbcc3e0"
            },
            "downloads": -1,
            "filename": "apikeylogger-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9d528808c208cc869a307664ae2e5f7e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8661,
            "upload_time": "2024-03-03T17:14:27",
            "upload_time_iso_8601": "2024-03-03T17:14:27.591395Z",
            "url": "https://files.pythonhosted.org/packages/f1/7f/4c413e72412eeeaaaace510fd8414c307d5c1c2ae3d088bcf508b508546d/apikeylogger-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "839ed2215ce99e282c5b5383027b1afb83841d717c9a155858562b009ece84d5",
                "md5": "03abbf585b40e2c8dedae5a88be1be41",
                "sha256": "d3a4d94d0b552201bf82fbedc203316f94620d1bcf7549f7c8023345c022d1f9"
            },
            "downloads": -1,
            "filename": "apikeylogger-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "03abbf585b40e2c8dedae5a88be1be41",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7903,
            "upload_time": "2024-03-03T17:14:29",
            "upload_time_iso_8601": "2024-03-03T17:14:29.255634Z",
            "url": "https://files.pythonhosted.org/packages/83/9e/d2215ce99e282c5b5383027b1afb83841d717c9a155858562b009ece84d5/apikeylogger-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-03 17:14:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "federicoromeo",
    "github_project": "apikeylogger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "apikeylogger"
}
        
Elapsed time: 0.19186s